【发布时间】:2023-03-20 11:05:01
【问题描述】:
在STREAM blog 之后的 openCL 中模拟原子的实现非常适用于 CPU 以及 NVIDIA 和 AMD GPU 上的 32 位原子添加。
基于 cl_khr_int64_base_atomics 扩展的 64 位等效版本似乎可以在(pocl 和 intel)CPU 以及 NVIDIA openCL 驱动程序上正常运行。
但我无法在 AMD GPU 卡上运行 64 位 - 在 amdgpu-pro 和 rocm (3.5.0) 环境中,分别在 Radeon VII 和 Radeon Instinct MI50 上运行。
实现如下:
inline void atomicAdd(volatile __global double *addr, double val)
{
union {
long u64;
double f64;
} next, expected, current;
current.f64 = *addr;
do {
expected.f64 = current.f64;
next.f64 = expected.f64 + val;
current.u64 = atomic_cmpxchg(
(volatile __global long *)addr,
(long) expected.u64,
(long) next.u64);
} while( current.u64 != expected.u64 );
}
在不支持 double 类型的原子操作的情况下,我们的想法是利用转换为 long,只要值只需要存储(不需要算术)。然后应该能够使用khronos manual for int64 base atomics 中定义的long atom_cmpxchg(__global long *p, long cmp, long val)。
我收到的两种 AMD 环境的错误都指向回退到 32 位版本,编译器似乎无法识别 64 位版本,尽管#pragma:
/tmp/comgr-0bdbdc/input/CompileSource:21:17: error: call to 'atomic_cmpxchg' is ambiguous
current.u64 = atomic_cmpxchg(
^~~~~~~~~~~~~~
[...]/centos_pipeline_job_3.5/rocm-rel-3.5/rocm-3.5-30-20200528/7.5/out/centos-7/7/build/amd_comgr/<stdin>:13468:12: note: candidate function
int __ovld atomic_cmpxchg(volatile __global int *p, int cmp, int val);
^
[...]/centos_pipeline_job_3.5/rocm-rel-3.5/rocm-3.5-30-20200528/7.5/out/centos-7/7/build/amd_comgr/<stdin>:13469:21: note: candidate function
unsigned int __ovld atomic_cmpxchg(volatile __global unsigned int *p, unsigned int cmp, unsigned int val);
^
1 error generated.
Error: Failed to compile opencl source (from CL or HIP source to LLVM IR).
我确实在clinfo 扩展列表中找到了在两种环境中对cl_khr_int64_base_atomics 的支持。此外,cl_khr_int64_base 也存在于 opencl 驱动程序二进制文件中。
有人知道这里可能出了什么问题吗?对 32 位使用相同的实现(int 和 float 而不是 long 和 double)对我来说完美无缺...
感谢任何提示。
【问题讨论】:
标签: opencl atomic amd-gpu gpu-atomics