owensgroup / BGHT

BGHT: High-performance static GPU hash tables.

Home Page:https://owensgroup.github.io/BGHT/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can atomic be replaced?

xianwujie opened this issue · comments

commented

hello,I'm refactoring BGHT on AMD and I'm running into a problem about atomic.
I change cuda::atomic ---->std::atomic()
// using atomic_pair_type = cuda::atomic<value_type, Scope>;
using atomic_pair_type = atomic<value_type>;

and have below error, the cause of the error is canot call host fun from device.
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bucket.cuh:48:44: error: no matching member function for call to 'load'
lane_pair_ = ptr_[tile_.thread_rank()].load(order);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bcht_impl.cuh:191:16: note: in instantiation of member function 'bght::detail::bucket<std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>, bght::padded_pair<unsigned int, unsigned int, false>, cooperative_groups::thread_group>::load' requested here
cur_bucket.load(std::memory_order_relaxed);
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/kernels.cuh:60:34: note: in instantiation of function template specialization 'bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>::insert<cooperative_groups::thread_group>' requested here
bool insertion_success = map.insert(cur_pair, tile);
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bcht_impl.cuh:143:39: note: in instantiation of function template specialization 'bght::detail::kernels::tiled_insert_kernel<bght::padded_pair<unsigned int, unsigned int, false> *, bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>>' requested here
hipLaunchKernelGGL(detail::kernels::tiled_insert_kernel,num_blocks,block_size,0, stream,first, last, *this);
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/test/test_bcht.cpp:85:33: note: in instantiation of function template specialization 'bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>::insert<bght::padded_pair<unsigned int, unsigned int, false> *>' requested here
auto insertion_success = test.insert(input_start, input_last, stream);
^
/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

There is no cuda/atomic implementation in HIP, so I would like to ask if atomic can be replaced with other device functions?
Waiting for your reply.

Hi @xianwujie, All loads use the cuda::memory_order_relaxed memory order, so you can try to replace the atomic load with a regular load after casting the pointer to volatile. We also use compare_exchange_strong and exchange which you can replace with atomicCAS and atomicExch, respectively. You can ignore the compare_exchange_weak function.

I'd recommend writing your own struct that encapsulate these operations (e.g. , custom_atomic and using atomic_pair_type = custom_atomic<value_type>)

commented

Hi @maawad ,Thanks for your reply, I got your means, and I will try to write custom_atomic.

But there is another problem of atomicCAS input parameter type mismatch.
e.g: auto old = ptr_[location].exchange(pair, order); ----> auto old = atomicExch(ptr_[location], pair);
the type of pair is const pair_type& pair,
Do you have any other suggestions?

more details :
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bucket.cuh:104:16: error: no matching function for call to 'atomicExch'
auto old = atomicExch(ptr_[location],pair);
^~~~~~~~~~
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bcht_impl.cuh:217:36: note: in instantiation of member function 'bght::detail::bucket<std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>, bght::padded_pair<unsigned int, unsigned int, false>, cooperative_groups::thread_group>::exch_at_location' requested here
auto old_pair = cur_bucket.exch_at_location(
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/kernels.cuh:60:34: note: in instantiation of function template specialization 'bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>::insert<cooperative_groups::thread_group>' requested here
bool insertion_success = map.insert(cur_pair, tile);
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/include/detail/bcht_impl.cuh:143:39: note: in instantiation of function template specialization 'bght::detail::kernels::tiled_insert_kernel<bght::padded_pair<unsigned int, unsigned int, false> *, bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>>' requested here
hipLaunchKernelGGL(detail::kernels::tiled_insert_kernel,num_blocks,block_size,0, stream,first, last, *this);
^
/home/user/pim-workspace/wujie/GPPIM/BGHT/test/test_bcht.cpp:85:33: note: in instantiation of function template specialization 'bght::bcht<unsigned int, unsigned int, bght::universal_hash, bght::equal_to, bght::hip_allocator, 16>::insert<bght::padded_pair<unsigned int, unsigned int, false> *>' requested here
auto insertion_success = test.insert(input_start, input_last, stream);
^
/opt/rocm-4.0.0/hip/include/hip/hcc_detail/hip_atomic.h:121:5: note: candidate function not viable: no known conversion from 'std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>' to 'int ' for 1st argument
int atomicExch(int address, int val)

^
/opt/rocm-4.0.0/hip/include/hip/hcc_detail/hip_atomic.h:127:14: note: candidate function not viable: no known conversion from 'std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>' to 'unsigned int ' for 1st argument
unsigned int atomicExch(unsigned int address, unsigned int val)

^
/opt/rocm-4.0.0/hip/include/hip/hcc_detail/hip_atomic.h:133:20: note: candidate function not viable: no known conversion from 'std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>' to 'unsigned long long ' for 1st argument
unsigned long long atomicExch(unsigned long long address, unsigned long long val)

^
/opt/rocm-4.0.0/hip/include/hip/hcc_detail/hip_atomic.h:139:7: note: candidate function not viable: no known conversion from 'std::atomic<bght::padded_pair<unsigned int, unsigned int, false>>' to 'float ' for 1st argument
float atomicExch(float address, float val)