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

Topic refactor cuda hip atomics #1768

Merged

Conversation

psychocoderHPC
Copy link
Member

@psychocoderHPC psychocoderHPC commented Jul 27, 2022

In #1767 I already enabled the usage of building atomicAdd for double precision.
Nevertheless, we are emulating in alpaka often atomics because it is a nightmare to maintain the list of supported atomic functions for HIP and CUDA. The list of supported types for different atomics differs between both models.

This PR introduces a "simple" way to let the compiler decide if a built-in function is available and use these. If not we will emulate the required atomics by using atomicCas.

  • enable atomicCas for floating point data types
  • emulate atomics if no builtin is available
  • alpaka::AtomicCas add floating point support
  • refactor atomic unit tests (remove many exceptions for CUDA/HIP)
  • use builtin atomics for hierarchy::Threads -> mapped to atomicXXX_block()

@psychocoderHPC psychocoderHPC force-pushed the topic-refactoreCudaHipAtomics branch from 90f6ed4 to 6ed752b Compare July 27, 2022 14:02
@sbastrakov sbastrakov changed the title Topic refactore cuda hip atomics Topic refactor cuda hip atomics Jul 27, 2022
//
// Atomics can be used in the hierarchy level grids, blocks and threads.
// Atomics are not guaranteed to be save between devices.
class AtomicUniformCudaHipBuiltIn
Copy link
Member

Choose a reason for hiding this comment

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

Does it also works, if the CUDA and the HIP are enabled at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

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

As I know. You can not enable CUDA and HIP at the same time.

Copy link
Member

Choose a reason for hiding this comment

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

Really, I thought Andrea implemented it? Or is it permitted by the CMake?

Copy link
Member Author

Choose a reason for hiding this comment

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

As I know he is compiling a library for CUDA and a library for HIP and linking both together.
Both libs will use a different compiler.

@fwyzard Could you check if this PR is working for you. I do not exactly know your workflows.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I remember that we introduced the device API struct to avoid naming conflicts. Nevertheless, these changes are fully on the device side and should not create symbols on the host side which can conflict.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I have been doing night shifts this week, and had little time for the rest :-/

I'll try to have a look ASAP.

@psychocoderHPC psychocoderHPC force-pushed the topic-refactoreCudaHipAtomics branch from 6ed752b to d7e586b Compare July 27, 2022 14:18
@psychocoderHPC psychocoderHPC force-pushed the topic-refactoreCudaHipAtomics branch 8 times, most recently from bb5870b to da30e6c Compare July 28, 2022 11:13
sbastrakov
sbastrakov previously approved these changes Jul 28, 2022
@psychocoderHPC psychocoderHPC force-pushed the topic-refactoreCudaHipAtomics branch 6 times, most recently from 92eba90 to c400aca Compare July 28, 2022 15:11
- check for builtin atomics and use these if available
- emulate atomics which are not provided as builtin via atomicCas
- emulate atomicCas for floating point data
Unify CPU and HIP/CUDA atomic tests.
For CUDA run tests only for 32bit and 64bit data types.
```
alpaka/atomic/AtomicOaccExtended.hpp:209:36: error: comparing floating-point with '==' or '!=' is unsafe [-Werror=float-equal]
```
For architectures where __hip_atomic_compare_exchange_strong is false
HIP is emulating atomics with `atomicCAS` but with a broken
implementation.
@psychocoderHPC psychocoderHPC force-pushed the topic-refactoreCudaHipAtomics branch from c400aca to eb579fd Compare July 29, 2022 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants