Is there a CUDA equivalent for std :: numeric_limits?

I would like to determine the maximum int value in the CUDA core. Unfortunately, I cannot find anything like std::numeric_limits for CUDA. Attempting to use the ::std function results in an error:

error : calling a __host__ function("std::numeric_limits<int> ::max") from a __global__ function("xyz_kernel") is not allowed C:\cuda.cu(153) (col. 10)

Is there a way to determine the desired value using the kernel or just pass it as a parameter?

+6
source share
2 answers

It exists, but it is not as general as std::numeric_limits . See this page for a list.

For example, you can have NPP_MAX_32U , but this only applies to 32-bit unsigned , not to the int type, the width of which depends on the system.

+3
source

I wrote something like this:

CUDA-compatible version of <limits> (named limits.cuh )

Essentially, this means adding __host__ __device__ to the collection of functions and putting all the structures in a namespace other than std .

Notes:

  • Licensing. It is based on g ++ <limits>
  • This has done some, but not extensive testing, with device-side code (only).
  • There may be some macro states with the actual <limits> (I'm not sure).
0
source

Source: https://habr.com/ru/post/971566/


All Articles