0

I have malloc 12G gpu memory like this, but when I use nvidia-smi to check the gpu memory usage, it is only 4G. I couldn't understand.

    size_t size = 6U * 1024 * 1024 * 1024 / 4;
    int *devSrc;
    int *devDest;
    cudaMalloc((void**)&devSrc, sizeof(int) * size);
    cudaMalloc((void**)&devDest, sizeof(int) * size);
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A   2520767      C   ...Test/cmake-build/cudaTest     4347MiB |
+-----------------------------------------------------------------------------+

when I change the variable size to 5U * 1024 * 1024 * 1024 / 4, the nvidia-smi indicated the gpu memory usage deduced to 2G:

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A   2521144      C   ...Test/cmake-build/cudaTest     2299MiB |
+-----------------------------------------------------------------------------+
  • 4
    You're seeing (unsigned) integer overflow because the RHS of your assignment (initialisation of `size`) is being performed in terms of plain `unsigned int` arithmetic. Changing the first term from `6U` to `6ULL` will (or *should*) fix this. See the linked duplicate for more details. – Adrian Mole Dec 05 '22 at 12:41

0 Answers0