HIP icon indicating copy to clipboard operation
HIP copied to clipboard

Problems with hip implementing atomic on AMD GPU

Open xianwujie opened this issue 2 years ago • 2 comments

Hello,everyone. I have some questions about atomic while using HIP.When I want to use atomic.load() in a device function based on the hip:rocm-4.0.0 version, error like : ../bucket.cuh:48:44: error: no matching member function for call to 'load' lane_pair_ = ptr_[tile_.thread_rank()].load(order);

/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/atomic:246:7: note: candidate function not viable: call to host function from device function load(memory_order __m = memory_order_seq_cst) const noexcept ^ /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/atomic:255:7: note: candidate function not viable: call to host function from device function load(memory_order __m = memory_order_seq_cst) const volatile noexcept

So I have the below questions:

  1. Have you ever encountered such a problem and how to solve it?
  2. Can I override device struct atomic{...} in HIP like cuda/atomic?

xianwujie avatar Jun 14 '22 08:06 xianwujie

std::atomic does not work in GPU device code. You should use the atomicAdd, atomicAnd, atomicCAS, etc. device intrinsics instead. See https://docs.amd.com/bundle/HIP_Supported_CUDA_API_Reference_Guide/page/CUDA_Device_API_supported_by_HIP.html

frobnitzem avatar Jun 21 '22 14:06 frobnitzem

Hi @frobnitzem , Thanks for your reply, I got it..

xianwujie avatar Jun 23 '22 06:06 xianwujie