I’m trying to compile a code written using CUDA 3.2 on RHEL 5.6. The relevant portions are
extern "C"{
#include <stdio.h>
#include <inttypes.h>
static uint64_t size = 0;
...
size = 5000 * 1024 * 1024;
printf("sizeof(size) = %d size = %lu\n", sizeof(size), size);
}
The code is in a .cu file, and compiled using nvcc. I get the compilation warning that for the line “size = 5000 * 1024 * 1024”, the “integer operation result is out of range”. The output I got is
sizeof(size) = 8 size = 947912704
I don’t understand why the variable “size” can’t represent the value 5242880000 if it’s 8-bytes large.
Thank you.
As @Damien commented, the multiplication is being done on int. The next code gives the expected result:
This is not related with CUDA or the nvcc compiler which calls to a general purpose C compiler during ‘non-CUDA’ phases. See The CUDA Compiler Driver NVCC doc for more details.