Skip to content

Commit

Permalink
Restore the custom double atomic add.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Aug 28, 2021
1 parent 7a1d67f commit de8dc91
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/common/device_helpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@

#endif // defined(XGBOOST_USE_RMM) && XGBOOST_USE_RMM == 1

#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600 || defined(__clang__)

#else // In device code and CUDA < 600
__device__ __forceinline__ double atomicAdd(double* address, double val) { // NOLINT
unsigned long long int* address_as_ull =
(unsigned long long int*)address; // NOLINT
unsigned long long int old = *address_as_ull, assumed; // NOLINT

do {
assumed = old;
old = atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));

// Note: uses integer comparison to avoid hang in case of NaN (since NaN !=
// NaN)
} while (assumed != old);

return __longlong_as_double(old);
}
#endif

namespace dh {
namespace detail {
template <size_t size>
Expand Down

0 comments on commit de8dc91

Please sign in to comment.