Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

cuda::atomic failures with underaligned types #160

Closed
jrhemstad opened this issue Apr 27, 2021 · 2 comments
Closed

cuda::atomic failures with underaligned types #160

jrhemstad opened this issue Apr 27, 2021 · 2 comments
Assignees
Labels
bug: functional Does not work as intended. helps: rapids Helps or needed by RAPIDS. P0: must have Absolutely must ship with the milestone.
Milestone

Comments

@jrhemstad
Copy link
Collaborator

The following code will fail if the default alignment (4) is used for key.

#if 1
struct key {
  int32_t a;
  int32_t b;
};
#else
struct alignas(8) key {
  int32_t a;
  int32_t b;
};
#endif
int main(){
    static_assert(alignof(key) == 4);
    cuda::atomic<key> k;
    auto r = k.load();
}

Error:

/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/__atomic(224): error: no suitable user-defined conversion from "cuda::std::__3::__cxx_atomic_alignment_wrapper_t<key>" to "key" exists
          detected during:
            instantiation of "_Tp cuda::std::__3::__cxx_atomic_load(const volatile cuda::std::__3::__cxx_atomic_base_impl_default<_Tp, _Sco> *, int) [with _Tp=key, _Sco=0]" 
/opt/compiler-explorer/libs/libcudacxx/trunk/include/cuda/std/detail/libcxx/include/atomic(1665): here
            instantiation of "_Tp cuda::std::__3::__atomic_base<_Tp, _Sco, <unnamed>>::load(cuda::std::__3::memory_order) const noexcept [with _Tp=key, _Sco=0, <unnamed>=false]" 

Specifying a larger alignment (8) resolves the issue.

https://godbolt.org/z/ETohMxqWb

@wmaxey wmaxey self-assigned this Apr 27, 2021
@wmaxey wmaxey added the bug: functional Does not work as intended. label Apr 27, 2021
@wmaxey wmaxey added this to the 2.0.0 milestone Apr 27, 2021
@brycelelbach brycelelbach added P0: must have Absolutely must ship with the milestone. helps: rapids Helps or needed by RAPIDS. labels May 18, 2021
@brycelelbach brycelelbach changed the title cuda::atomic failures with underaligned types cuda::atomic failures with underaligned types May 18, 2021
@wmaxey
Copy link
Member

wmaxey commented Jul 7, 2021

@wmaxey
Copy link
Member

wmaxey commented Sep 10, 2021

Closing with the caveat that this still fails for Pascal devices, but rather than a compile time error it fails at runtime with unsupported shared/global memory operation.

@wmaxey wmaxey closed this as completed Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: functional Does not work as intended. helps: rapids Helps or needed by RAPIDS. P0: must have Absolutely must ship with the milestone.
Projects
None yet
Development

No branches or pull requests

3 participants