Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic Reference Reorganization, main branch (2024.08.08.) #291

Merged
merged 5 commits into from
Sep 3, 2024

Conversation

krasznaa
Copy link
Member

@krasznaa krasznaa commented Aug 8, 2024

This is a proposal for fixing the MSVC+CUDA compilation issue described in #288. As discussed already in #275, I wanted to split the implementation of vecmem::device_atomic_ref into multiple classes since a while. #288 was the trigger to make it happen.

This PR introduces the following new classes:

  • vecmem::dummy_device_atomic_ref: A fallback implementation, for host code that's not covered by something better. Does not actually do atomic operations.
  • vecmem::posix_device_atomic_ref: An implementation using GCC / Clang built-ins for atomic operation support in host code.
  • vecmem::cuda::device_atomic_ref: An implementation using the basic CUDA C atomic operations.
  • vecmem::hip::device_atomic_ref: The same as vecmem::cuda::device_atomic_ref (is a typedef of the latter), with an additional include statement needed by HIP.
  • vecmem::sycl::builtin_device_atomic_ref: A typedef using cl::sycl::atomic_ref.
  • vecmem::sycl::custom_device_atomic_ref: A full implementation of an atomic reference, using "low level" SYCL atomic operations.

The vecmem/memory/device_atomic_ref.hpp file now just chooses between these different implementations, based on various criteria, and sets up vecmem::device_atomic_ref as a typedef to one of the above types, or to std::atomic_ref with host code when using C++20.

As we discussed with @stephenswat, in the end the VECMEM_SUPPORT_POSIX_ATOMIC_REF test, which currently runs only during the build, will need to become something that vecmem-config.cmake would re-run for the host compiler in the context of the client project's build. But since some other flags will need to be moved to behave like that as well, I decided to do that in a future PR. And in this one I just figure out whether the host compiler supports vecmem::posix_device_atomic_ref, during the build of vecmem itself.

I am still working on the code, but wanted to expose it to @stephenswat at this point.

@krasznaa krasznaa added the refactor Rewrite the code to improve it label Aug 8, 2024
@krasznaa krasznaa force-pushed the AtomicRefReorg-main-20240805 branch 2 times, most recently from 1636292 to 076a570 Compare August 9, 2024 13:03
Copy link
Member Author

@krasznaa krasznaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to point out a few things for you Stephen, since I'm aware of a few weaknesses myself... 🤔

core/CMakeLists.txt Show resolved Hide resolved
core/CMakeLists.txt Show resolved Hide resolved
Each new class is meant to be used on just one "platform",
and vecmem::device_atomic_ref is a typedef to the one that
is appropriate in any given situation.

The selection procedure is not correct yet, the "POSIX" version
of the code never gets selected at the moment.
It is the same as vecmem::cuda::device_atomic_reference, with an additional
include needed by HIP.
Not in a way yet which would allow the re-evaluation of the
C++ compiler in client projects.
The SYCL implementation never needs __host__ or __device__.

The "POSIX" implementation will only ever work in host code.

The CUDA and HIP implementations are now included more generally
using the __CUDACC__ and __HIPCC__ macros. At which point the
vecmem::cuda::device_atomic_ref implementation had to be tweaked
to only use __threadfence() when building device code.
@krasznaa krasznaa force-pushed the AtomicRefReorg-main-20240805 branch from 076a570 to 4e05698 Compare August 31, 2024 11:25
Copy link
Member

@stephenswat stephenswat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comments and questions.

Since the main declaration of vecmem::device_atomic_ref
needs that enumeration as well.
@krasznaa krasznaa merged commit 7fbfa83 into acts-project:main Sep 3, 2024
55 checks passed
@krasznaa krasznaa deleted the AtomicRefReorg-main-20240805 branch September 3, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Rewrite the code to improve it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants