-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Various fixes for heterogeneous utilities #47605
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
*/ | ||
|
||
#include <cassert> | ||
#include <cstring> | ||
|
||
#include "FWCore/Reflection/interface/reflex.h" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef HeterogeneousCore_AlpakaInterface_interface_atomicInc_h | ||
#define HeterogeneousCore_AlpakaInterface_interface_atomicInc_h | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
// This function is similar to atomicInc, but deduces the limiting value from the type itself. | ||
|
||
ALPAKA_NO_HOST_ACC_WARNING | ||
template <typename TAcc, typename T, typename THierarchy = alpaka::hierarchy::Grids> | ||
ALPAKA_FN_HOST_ACC auto atomicInc(TAcc const& acc, T* address, THierarchy const& hierarchy = THierarchy()) -> T { | ||
T limit = std::numeric_limits<T>::max(); | ||
fwyzard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return alpaka::atomicInc(acc, address, limit, hierarchy); | ||
} | ||
|
||
#endif // HeterogeneousCore_AlpakaInterface_interface_atomicInc_h |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef HeterogeneousCore_AlpakaInterface_interface_atomicIncSaturate_h | ||
#define HeterogeneousCore_AlpakaInterface_interface_atomicIncSaturate_h | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
// This function is similar to atomicInc, but instead of wrapping around it saturates at the given value. | ||
|
||
ALPAKA_NO_HOST_ACC_WARNING | ||
template <typename TAcc, typename T, typename THierarchy = alpaka::hierarchy::Grids> | ||
ALPAKA_FN_HOST_ACC auto atomicIncSaturate(TAcc const& acc, | ||
T* address, | ||
T const& limit, | ||
THierarchy const& hierarchy = THierarchy()) -> T { | ||
T assumed; | ||
T old = *address; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On host parallel backends (that we don't use at the moment) this line is not thread safe (actually, strictly speaking with the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
|
||
do { | ||
assumed = old; | ||
if (assumed >= limit) { | ||
// Saturate at limit. | ||
break; | ||
} | ||
old = alpaka::atomicCas(acc, address, assumed, assumed + 1, hierarchy); | ||
} while (old != assumed); | ||
|
||
return old; | ||
} | ||
|
||
#endif // HeterogeneousCore_AlpakaInterface_interface_atomicIncSaturate_h |
Uh oh!
There was an error while loading. Please reload this page.