This source file includes following definitions.
- atomicAdd
- atomicAdd
- atomicAdd
- atomicAdd
- atomicMin
- atomicMin
- atomicMin
- atomicMin
- atomicMax
- atomicMax
- atomicMax
- atomicMax
#pragma once
#ifndef __OPENCV_CUDEV_UTIL_ATOMIC_HPP__
#define __OPENCV_CUDEV_UTIL_ATOMIC_HPP__
#include "../common.hpp"
namespace cv { namespace cudev {
__device__ __forceinline__ int atomicAdd(int* address, int val)
{
return ::atomicAdd(address, val);
}
__device__ __forceinline__ uint atomicAdd(uint* address, uint val)
{
return ::atomicAdd(address, val);
}
__device__ __forceinline__ float atomicAdd(float* address, float val)
{
#if CV_CUDEV_ARCH >= 200
return ::atomicAdd(address, val);
#else
int* address_as_i = (int*) address;
int old = *address_as_i, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_i, assumed,
__float_as_int(val + __int_as_float(assumed)));
} while (assumed != old);
return __int_as_float(old);
#endif
}
__device__ static double atomicAdd(double* address, double val)
{
#if CV_CUDEV_ARCH >= 130
unsigned long long int* address_as_ull = (unsigned long long int*) address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_ull, assumed,
__double_as_longlong(val + __longlong_as_double(assumed)));
} while (assumed != old);
return __longlong_as_double(old);
#else
(void) address;
(void) val;
return 0.0;
#endif
}
__device__ __forceinline__ int atomicMin(int* address, int val)
{
return ::atomicMin(address, val);
}
__device__ __forceinline__ uint atomicMin(uint* address, uint val)
{
return ::atomicMin(address, val);
}
__device__ static float atomicMin(float* address, float val)
{
#if CV_CUDEV_ARCH >= 120
int* address_as_i = (int*) address;
int old = *address_as_i, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_i, assumed,
__float_as_int(::fminf(val, __int_as_float(assumed))));
} while (assumed != old);
return __int_as_float(old);
#else
(void) address;
(void) val;
return 0.0f;
#endif
}
__device__ static double atomicMin(double* address, double val)
{
#if CV_CUDEV_ARCH >= 130
unsigned long long int* address_as_ull = (unsigned long long int*) address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_ull, assumed,
__double_as_longlong(::fmin(val, __longlong_as_double(assumed))));
} while (assumed != old);
return __longlong_as_double(old);
#else
(void) address;
(void) val;
return 0.0;
#endif
}
__device__ __forceinline__ int atomicMax(int* address, int val)
{
return ::atomicMax(address, val);
}
__device__ __forceinline__ uint atomicMax(uint* address, uint val)
{
return ::atomicMax(address, val);
}
__device__ static float atomicMax(float* address, float val)
{
#if CV_CUDEV_ARCH >= 120
int* address_as_i = (int*) address;
int old = *address_as_i, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_i, assumed,
__float_as_int(::fmaxf(val, __int_as_float(assumed))));
} while (assumed != old);
return __int_as_float(old);
#else
(void) address;
(void) val;
return 0.0f;
#endif
}
__device__ static double atomicMax(double* address, double val)
{
#if CV_CUDEV_ARCH >= 130
unsigned long long int* address_as_ull = (unsigned long long int*) address;
unsigned long long int old = *address_as_ull, assumed;
do {
assumed = old;
old = ::atomicCAS(address_as_ull, assumed,
__double_as_longlong(::fmax(val, __longlong_as_double(assumed))));
} while (assumed != old);
return __longlong_as_double(old);
#else
(void) address;
(void) val;
return 0.0;
#endif
}
}}
#endif