docs(plans): record next-directions roadmap for the 2026-Q3 atomics push Persists the candidate directions that came up during this session but were not picked up, so a future session can pick from the menu without re-deriving them. A. Atomics and parallel primitives (directly related to this session’s main thread): A1. axe_openmp_parallel_reduce: atomic vs reduction tree comparison via env-var-driven backend variant. A2. ScatterView / atomic histogram primitive. A3. HIP backend atomics in device kernels (needs DCU). B. Backend skeletons (resources not yet available): B1. Sunway (SWACC) backend. B2. MTDSP (Tianhe Maichuang DSP) backend. C. CI and engineering improvements: C1. Perf regression trend tracking across CI runs. C2. HIP benchmark in CI (needs DCU runner). C3. CodeQL / static analysis. D. Documentation and DX: D1. atomics-best-practices.md (DONE in 6df2772). D2. README per example. D3. CHANGELOG.md. D4. CONTRIBUTING.md. E. Further perf: E1. Hillis-Steele / Blelloch parallel prefix (analyzed and DEFERRED, see commit 57484dd’s parent discussion). E2. SIMD vectorized chunk-internal scan. E3. Multi-backend coexistence test. F. Hardware-gated work: F1. TeamPolicy device-side team semantics. F2. ARM weak-memory-order atomic correctness validation. The plan also includes a recap table of the 15 commits this session landed and the final state (13 commits ahead of origin/master, 234 tests passing under -Werror + ASan/UBSan, 6 CI jobs, 5 examples, 4 baseline JSONs, 3 perf gate scripts). AGENTS.md gets a new entry pointing at the plan for visibility.
docs(plans): record next-directions roadmap for the 2026-Q3 atomics push
Persists the candidate directions that came up during this session but were not picked up, so a future session can pick from the menu without re-deriving them.
A. Atomics and parallel primitives (directly related to this session’s main thread): A1. axe_openmp_parallel_reduce: atomic vs reduction tree comparison via env-var-driven backend variant. A2. ScatterView / atomic histogram primitive. A3. HIP backend atomics in device kernels (needs DCU). B. Backend skeletons (resources not yet available): B1. Sunway (SWACC) backend. B2. MTDSP (Tianhe Maichuang DSP) backend. C. CI and engineering improvements: C1. Perf regression trend tracking across CI runs. C2. HIP benchmark in CI (needs DCU runner). C3. CodeQL / static analysis. D. Documentation and DX: D1. atomics-best-practices.md (DONE in 6df2772). D2. README per example. D3. CHANGELOG.md. D4. CONTRIBUTING.md. E. Further perf: E1. Hillis-Steele / Blelloch parallel prefix (analyzed and DEFERRED, see commit 57484dd’s parent discussion). E2. SIMD vectorized chunk-internal scan. E3. Multi-backend coexistence test. F. Hardware-gated work: F1. TeamPolicy device-side team semantics. F2. ARM weak-memory-order atomic correctness validation.
The plan also includes a recap table of the 15 commits this session landed and the final state (13 commits ahead of origin/master, 234 tests passing under -Werror + ASan/UBSan, 6 CI jobs, 5 examples, 4 baseline JSONs, 3 perf gate scripts).
AGENTS.md gets a new entry pointing at the plan for visibility.
面向国产新一代超算系统的 Kokkos 兼容性能可移植加速库。
参考 Kokkos 设计,采用异构后端、统一前端架构:
extern "C"
void*
用户代码 (Kokkos API 兼容) │ ┌────┴──────────────────────────────────┐ │ axelib 前端 (C++17 Header) │ │ View / parallel_for / RangePolicy … │ │ 类型擦除: lambda → fn ptr + void* │ └────┬──────────────────────────────────┘ │ extern "C" ABI (12 函数/后端) ┌────┼────┬──────────┐ ▼ ▼ ▼ ▼ HIP Sunway MTDSP Serial/OpenMP/EMU (加速器后端) (CPU后端, 已实现)
# 开发机 — 3 个 CPU 后端 cmake -DAXE_ENABLE_SERIAL=ON -DAXE_ENABLE_OPENMP=ON -DAXE_ENABLE_EMU=ON \ -DAXE_BUILD_TESTS=ON .. make -j4 && ctest # 曙光 DCU 后端(需在目标平台使用 hipcc) module load compiler/dtk/25.04 CXX=hipcc cmake -DAXE_ENABLE_SERIAL=ON -DAXE_ENABLE_OPENMP=ON -DAXE_ENABLE_HIP=ON \ -DAXE_BUILD_TESTS=ON .. make -j4 && ctest
AXE_ENABLE_SERIAL
AXE_ENABLE_OPENMP
AXE_ENABLE_EMU
AXE_ENABLE_HIP
AXE_ENABLE_SUNWAY
AXE_ENABLE_MTDSP
AXE_BUILD_TESTS
#include <Kokkos/Kokkos_Core.hpp> int main() { Kokkos::initialize(); const int N = 1000; Kokkos::View<double*> a("a", N); Kokkos::View<double*> b("b", N); Kokkos::parallel_for(Kokkos::RangePolicy<>(0, N), KOKKOS_LAMBDA(int i) { a(i) = i; b(i) = a(i) * 2.0; }); Kokkos::Sum<double> sum; Kokkos::parallel_reduce(Kokkos::RangePolicy<>(0, N), [&](int i, double& partial) { partial += a(i); }, sum); printf("sum = %f\n", sum.reference()); Kokkos::finalize(); }
编译:
# 注意:libaxelib_core.a 依赖静态初始化注册后端,必须使用 --whole-archive g++ -std=c++17 -DAXE_ENABLE_SERIAL -I include app.cpp \ -Wl,--whole-archive build/libaxelib_core.a -Wl,--no-whole-archive \ -o app
可以显式指定后端:
Kokkos::parallel_for(Kokkos::RangePolicy<Kokkos::OpenMP>(0, N), functor); Kokkos::parallel_for(Kokkos::RangePolicy<Kokkos::HIP>(0, N), functor);
Kokkos::initialize
Kokkos::finalize
Kokkos::View<T*>
Kokkos::View<T**>
View<T***>
Kokkos::MemoryUnmanaged
Kokkos::create_mirror_view
Kokkos::parallel_for
Kokkos::parallel_reduce
Kokkos::parallel_scan
Kokkos::atomic_add
atomic_sub
atomic_mul
atomic_div
atomic_inc
atomic_dec
atomic_min
atomic_max
atomic_load
atomic_store
atomic_exchange
atomic_compare_exchange
atomic_compare_exchange_strong
atomic_and
atomic_or
atomic_xor
atomic_fetch_*
__atomic
atomicAdd
atomicSub
atomicMul
atomicAnd
atomicExch
MemoryOrder
Kokkos::TeamPolicy
TeamThreadRange
team_barrier
parallel_for/reduce/scan
Kokkos::LayoutLeft
LayoutRight
LayoutStride
axelib/ ├── include/Kokkos/ # C++17 前端 (Header-Only) │ ├── Kokkos_Core.hpp # 入口头文件 │ ├── Kokkos_Core_fwd.hpp # 前向声明 + KOKKOS_LAMBDA 宏 │ ├── Core/ # View, Parallel, Policy, Layout, MemorySpace │ ├── Impl/ # BackendBridge, SpaceRegistry, ViewMapping │ └── Setup/ # 平台检测 + BackendId 枚举 + 执行空间 ├── src/ # 运行时核心 │ ├── Kokkos_Core.cpp # initialize / finalize / register_backend │ └── Kokkos_Impl.cpp # 内存追踪 / 泄漏检测 ├── backends/ # 后端实现 (12 C ABI 函数/后端) │ ├── serial/ # Serial 后端 (for 循环) │ ├── openmp/ # OpenMP 后端 (#pragma omp) │ ├── emu/ # EMU 后端 (std::thread) │ ├── hip/ # HIP 后端(曙光 DCU) │ ├── sunway/ # Sunway 后端(占位) │ └── mtdsp/ # MTDSP 后端(占位) ├── tests/ │ ├── unit/ # 前端单元测试 │ └── integration/ # 集成测试 (E2E, 多后端共存) ├── examples/ │ └── 01_hello_world/ # Hello World ├── scripts/ │ └── sugon_hip_test.slurm # 曙光超算 HIP 测试作业脚本 ├── cmake/ # FindHIP / FindSunway / FindMTDSP ├── docs/superpowers/ # 设计规格 + 实现计划 ├── .github/workflows/ci.yml # GitHub Actions CI ├── AGENTS.md # 代理/开发者协作指南 ├── CMakeLists.txt └── README.md
HIP.MultiDevice*
scripts/sugon_hip_multidevice_test.slurm
覆盖范围包括 View 操作(1D/2D/3D、subview 1D/2D/3D、LayoutStride)、并行执行、归约、扫描(含前缀输出与 2D MDRangePolicy 扫描)、初始化/终结、多后端共存、显式执行空间分发,以及 HIP 后端在 DCU 上的 alloc/free、H↔D 拷贝、parallel_for / parallel_reduce / parallel_scan、MDRangePolicy、多设备切换、自定义 stream、多设备独立工作/跨设备拷贝。
ctest --output-on-failure # CPU: 100% tests passed, 0 tests failed out of 234 # HIP: 100% tests passed, 0 tests failed out of 62 (单 DCU 时 2 项跳过)
已在曙光新一代超算(Sugon OS 8.9 + Hygon DCU)上完成验证,详见 docs/superpowers/reports/2026-06-22-sugon-test.md。
docs/superpowers/reports/2026-06-22-sugon-test.md
GitHub Actions 自动运行:
-Wall -Wextra -Werror
perf-atomic-reduce-scan
atomic_reduce_scan
scripts/check_atomic_reduce_scan.sh
parallel_reduce
parallel_scan
docs/superpowers/baselines/atomic_reduce_scan.json
perf-team-scan-benchmark
team_scan_benchmark
scripts/check_team_scan_benchmark.sh
docs/superpowers/baselines/team_scan_benchmark.json
team-scan-distribution-artifact
examples/04_team_scan_distribution
见 LICENSE
斧库
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
axelib
面向国产新一代超算系统的 Kokkos 兼容性能可移植加速库。
设计思路
参考 Kokkos 设计,采用异构后端、统一前端架构:
extern "C"函数指针桥接void*,零运行时多态开销目标平台
构建
AXE_ENABLE_SERIALAXE_ENABLE_OPENMPAXE_ENABLE_EMUAXE_ENABLE_HIPAXE_ENABLE_SUNWAYAXE_ENABLE_MTDSPAXE_BUILD_TESTS使用
编译:
显式执行空间
可以显式指定后端:
已实现 API
Kokkos::initialize/Kokkos::finalizeKokkos::View<T*>— 1D 分配、浅拷贝、subview、deep_copyKokkos::View<T**>/View<T***>— 2D/3DKokkos::MemoryUnmanaged— 裸指针包装Kokkos::create_mirror_viewKokkos::parallel_for— RangePolicy / MDRangePolicy(2D,3D)Kokkos::parallel_reduce— Sum / Prod / Min / MaxKokkos::parallel_scan— Sum / Max / Min / Prod(最终累加值 + 前缀输出)Kokkos::atomic_add/atomic_sub/atomic_mul/atomic_div/atomic_inc/atomic_dec/atomic_min/atomic_max/atomic_load/atomic_store/atomic_exchange/atomic_compare_exchange/atomic_compare_exchange_strong/atomic_and/atomic_or/atomic_xor及其atomic_fetch_*变种 — 整型/浮点(Host:__atomic;HIP:atomicAdd/atomicSub/atomicMul/atomicAnd/atomicExch;可选MemoryOrder:relaxed/acquire/release/acq_rel/seq_cst)Kokkos::TeamPolicy/TeamThreadRange— OpenMP 多线程 team(team_barrier、并发 innerparallel_for/reduce/scan);Serial/Emu 单线程 teamKokkos::LayoutLeft/LayoutRight/LayoutStride目录结构
测试
HIP.MultiDevice*两项会跳过,需通过scripts/sugon_hip_multidevice_test.slurm在 2 DCU 下验证(2/2 通过)。覆盖范围包括 View 操作(1D/2D/3D、subview 1D/2D/3D、LayoutStride)、并行执行、归约、扫描(含前缀输出与 2D MDRangePolicy 扫描)、初始化/终结、多后端共存、显式执行空间分发,以及 HIP 后端在 DCU 上的 alloc/free、H↔D 拷贝、parallel_for / parallel_reduce / parallel_scan、MDRangePolicy、多设备切换、自定义 stream、多设备独立工作/跨设备拷贝。
已在曙光新一代超算(Sugon OS 8.9 + Hygon DCU)上完成验证,详见
docs/superpowers/reports/2026-06-22-sugon-test.md。持续集成
GitHub Actions 自动运行:
-Wall -Wextra -Werror)perf-atomic-reduce-scan:buildatomic_reduce_scanbenchmark 并跑scripts/check_atomic_reduce_scan.sh,验证 correctness + 用户级 atomic 至少在一个 op(reduce / scan)上不慢于 nativeparallel_reduce/parallel_scan。该 gate 是 qualitative 的(不比较 CI 与 dev box 的绝对时间),dev box 基线见docs/superpowers/baselines/atomic_reduce_scan.json。perf-team-scan-benchmark:buildteam_scan_benchmark并跑scripts/check_team_scan_benchmark.sh,验证 correctness + ts=16 至少 3x 快于 ts=1(3-pass team scan 的基本缩放不变量)。dev box 基线见docs/superpowers/baselines/team_scan_benchmark.json。team-scan-distribution-artifact:跑examples/04_team_scan_distribution并把 ASCII 直方图上传为 CI artifact,便于在 CI 页面查看并行分布。许可
见 LICENSE