CUDA Thrust: multiple compiler warnings

Compiling the current (CUDA v10.1) Thrust libraries using Windows and Visual Studio results in the following warnings:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include\thrust\mr\allocator.h(96,48): warning C4003:  not enough arguments for function-like macro invocation 'max'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include\thrust/system/cuda/detail/sort.h(1218): warning C4244: 'initializing': conversion from 'Integer' to 'int', possible loss of data
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include\thrust/system/cuda/detail/reduce.h(939): warning C4244: 'argument': conversion from 'Size' to 'int', possible loss of data

These are not showstoppers. These warnings are generated for templated C++ code, so an annoying snowstorm of warning messages appears when a large CUDA Thrust project is built, but compiled applications nevertheless run without CUDA errors.

The question is whether the results are reliable, since the compiler’s default behavior in each case (replacing missing arguments with “empty” values, truncating larger to smaller data types) is correct for the logic in the Thrust code. Or are there corner cases where null arguments or data truncation would lead to incorrect results?

can you identify the actual CUDA 10.1 version you are using? Is it 10.1.243?

also, can you supply a simple example code that when compiled, produces these warnings?

I can confirm that it’s v10.1.243, although the problem has remained unchanged at least since the first iteration of v10.1.

My own code calls thrust::stable_sort(), but unfortunately the application comprises many thousands of lines of code and I don’t have a simple repro at hand.

I would imagine, however, that CUDA SDK sample code that relies on functionality defined in sort.h or reduce.h would suffice. Since the warnings stem from method calls internal to Thrust, it might be straightforward for someone who knows the code to look at the warnings and recognize the problem.

For example, in the code in sort.h, the warning is associated with an assignment statement:

int num_passes = thrust::detail::log2_ri(num_tiles);

The log2_ri method is defined like this:

template <typename Integer>
__host__ __device__ __thrust_forceinline__
Integer log2_ri(Integer x)
  Integer result = log2(x);

  // This is where we round up to the nearest log.
  if (!is_power_of_2(x))

  return result;

So the Integer template specialization cannot always be converted losslessly into a C++ int. This would be problematic in my own code, although perhaps in Thrust it doesn’t matter. In any case, surely whoever is responsible for this code at NVidia can take a look at it and create an appropriate fix.

I compiled the thrustRadixSort sample code from 10.1.243 on VS2019. It didn’t produce any of the warnings you have listed or described. The two warnings it does produce are related to the sample code itself (usage of thrust rng) not anything related to sort.

Some other things I can think of:

  1. you could file a bug using the instructions linked in the sticky post at the top of this forum. It’s likely that you would be asked for a repro code if you do that.

  2. You could file a thrust issue.

Thank you, Robert.

I guess this will go onto my “to do” list.

For what it’s worth, the warnings are only emitted by the Visual Studio 2019 compiler. In Linux, the same code compiles silently. I’ll try to contrive some repro code as soon as I get a chance.

I assume you are getting these warnings on MSVC because you are building with -W4.
Last I checked, there is no equivalent warning to C4244 on gcc, only a subset: -Wfloat-conversion.


For example:

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.21.27702\bin\HostX86\x64" -x cu  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include"     --keep-dir x64\Debug -maxrregcount=0 --ptxas-options=-v --machine 64 --compile -cudart static  -g   -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64\Debug\vc142.pdb /FS /Zi /RTC1 /MTd " -o x64\Debug\ "C:\Projects VS120\Arioc\AriocU\"

My bad. Checking Microsoft’s documentation, the extent of the checks associated with C4244 apparently differs between warning levels 2, 3, and 4. MSVC warning level -W3 is generally a sane (useful) warning level, so getting these warnings cleaned up seems like something worth pursuing (which means filing a bug report seems advisable).