I see in the CUDA Math API documentation that there are functions for single and double precision min/max operations (e.g. fminf()
). I assume these are highly optimized, etc. There don't seem to be functions like these for integers. Is this true? Is there a reason for that?
Asked
Active
Viewed 2.2k times
15

Phonon
- 12,549
- 13
- 64
- 114
1 Answers
17
There are min/max device functions for integers, but they are all called with an overloaded max()
. Look in device_functions.hpp:
__DEVICE_FUNCTIONS_STATIC_DECL__ int max(int x, int y)
{
return __nv_max(x, y);
}
__DEVICE_FUNCTIONS_STATIC_DECL__ unsigned int umax(unsigned int x, unsigned int y)
{
return __nv_umax(x, y);
}
__DEVICE_FUNCTIONS_STATIC_DECL__ long long llmax(long long x, long long y)
{
return __nv_llmax(x, y);
}
__DEVICE_FUNCTIONS_STATIC_DECL__ unsigned long long ullmax(unsigned long long x,
unsigned long long y)
{
return __nv_ullmax(x, y);
}
They're not listed in the Integer Intinsics section because in math_functions.hpp the max
function is overloaded to call these functions for you. The __nv*
functions are documented in device_function_decls.hpp.

chappjc
- 30,359
- 6
- 75
- 132
-
3For what it is worth these intrinsics map straight to hardware instructions. If you disassemble your binary with `cuobjdump --dump-sass`, you will find instructions like `IMNMX` = "integer minimum or maximum" (a predicate selects whether this performs `min()` or `max()`) – njuffa May 01 '15 at 00:26
-
For me the code with `__nv_min` doesn't compile. Which compute capability does it require? – Serge Rogatch Sep 28 '16 at 21:31
-
@SergeRogatch You just use `max` and overload resolution will handle it. Either you are not compiling the file with nvcc, or you forgot to include cuda_runtime.h. Be sure you have no macros for max though. I think math_functions.hpp has the overloads – chappjc Sep 28 '16 at 21:53
-
@chappjc, with just `min` it compiles, it is definitely `nvcc`, as there is a lot of other CUDA code in the file. `cuda_runtime.h` is included. But `__nv_min` doesn't compile (it says that the function is undefined). – Serge Rogatch Sep 28 '16 at 22:05
-
@SergeRogatch It's working then. Direct use is not intended. – chappjc Sep 28 '16 at 22:06