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: Cleanup backend-specific internals of CUDA backend #152

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions src/stdgpu/cuda/atomic.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,6 @@ atomic_fetch_dec_mod(T* address,



/**
* \brief Atomically computes the difference of the two values
* \param[in] address A pointer to a value
* \param[in] value A value
* \return The old value at the given address
*/
STDGPU_DEVICE_ONLY unsigned long long int
atomicSub(unsigned long long int* address,
const unsigned long long int value);

/**
* \brief Atomically computes the difference of the two values
* \param[in] address A pointer to a value
* \param[in] value A value
* \return The old value at the given address
*/
STDGPU_DEVICE_ONLY float
atomicSub(float* address,
const float value);


/**
* \brief Atomically computes the minimum of the two values
* \param[in] address A pointer to a value
* \param[in] value A value
* \return The old value at the given address
*/
STDGPU_DEVICE_ONLY float
atomicMin(float* address,
const float value);


/**
* \brief Atomically computes the maximum of the two values
* \param[in] address A pointer to a value
* \param[in] value A value
* \return The old value at the given address
*/
STDGPU_DEVICE_ONLY float
atomicMax(float* address,
const float value);



#include <stdgpu/cuda/impl/atomic_detail.cuh>


Expand Down
112 changes: 56 additions & 56 deletions src/stdgpu/cuda/impl/atomic_detail.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,62 @@



inline STDGPU_DEVICE_ONLY unsigned long long int
atomicSub(unsigned long long int* address,
const unsigned long long int value)
{
return atomicAdd(address, stdgpu::numeric_limits<unsigned long long int>::max() - value + 1);
}


inline STDGPU_DEVICE_ONLY float
atomicSub(float* address,
const float value)
{
return atomicAdd(address, -value);
}


inline STDGPU_DEVICE_ONLY float
atomicMin(float* address,
const float value)
{
int* address_as_int = (int*)address;
int old = *address_as_int, assumed;

do
{
assumed = old;
old = atomicCAS(address_as_int, assumed, __float_as_int( fminf(__int_as_float(assumed), value) ));

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

return __int_as_float(old);
}


inline STDGPU_DEVICE_ONLY float
atomicMax(float* address,
const float value)
{
int* address_as_int = (int*)address;
int old = *address_as_int, assumed;

do
{
assumed = old;
old = atomicCAS(address_as_int, assumed, __float_as_int( fmaxf(__int_as_float(assumed), value) ));

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

return __int_as_float(old);
}


namespace stdgpu
{

Expand Down Expand Up @@ -132,61 +188,5 @@ atomic_fetch_dec_mod(T* address,
} // namespace stdgpu


inline STDGPU_DEVICE_ONLY unsigned long long int
atomicSub(unsigned long long int* address,
const unsigned long long int value)
{
return atomicAdd(address, stdgpu::numeric_limits<unsigned long long int>::max() - value + 1);
}


inline STDGPU_DEVICE_ONLY float
atomicSub(float* address,
const float value)
{
return atomicAdd(address, -value);
}


inline STDGPU_DEVICE_ONLY float
atomicMin(float* address,
const float value)
{
int* address_as_int = (int*)address;
int old = *address_as_int, assumed;

do
{
assumed = old;
old = atomicCAS(address_as_int, assumed, __float_as_int( fminf(__int_as_float(assumed), value) ));

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

return __int_as_float(old);
}


inline STDGPU_DEVICE_ONLY float
atomicMax(float* address,
const float value)
{
int* address_as_int = (int*)address;
int old = *address_as_int, assumed;

do
{
assumed = old;
old = atomicCAS(address_as_int, assumed, __float_as_int( fmaxf(__int_as_float(assumed), value) ));

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

return __int_as_float(old);
}



#endif // STDGPU_CUDA_ATOMIC_DETAIL_H
Loading