首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >64位原子操作能在AMD卡上的openCL中工作吗?

问64位原子操作能在AMD卡上的openCL中工作吗?
EN

Stack Overflow用户
提问于 2021-04-22 18:35:09
回答 1查看 131关注 0票数 1

遵循STREAM blog的openCL中模拟原子的实现很好地适用于32位的原子添加,在中央处理器以及NVIDIA和AMD GPU上。

基于cl_khr_int64_base_atomics扩展的64位等价物似乎可以在(口袋和英特尔) CPU和NVIDIA openCL驱动程序上正常运行。

我无法在AMDGPU卡上运行64位--无论是在amdgpu-pro和rocm (3.5.0)环境下,它们分别运行在Radeon VII和Radeon Instinct MI50上。

实现过程如下:

代码语言:javascript
复制
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 );
}

在不支持双精度类型的原子操作的情况下,我们的想法是利用强制转换,因为只需要存储值(不需要算术)。然后,应该能够使用khronos manual for int64 base atomics中定义的long atom_cmpxchg(__global long *p, long cmp, long val)。

我在两个AMD环境中收到的错误都指向回退到32位版本,尽管有#pragma,但编译器似乎无法识别64位版本

代码语言:javascript
复制
/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位使用相同的实现(整型和浮点型而不是长整型和双精度型)对我来说工作得很完美……

谢谢你的任何提示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-22 19:41:26

对于64位,该函数称为atom_cmpxchg,而不是atomic_cmpxchg。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67211566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档