I have a simple code (given below) which calls cudaMalloc and then immediately prints the GPU memory info.
int main(){
int *ptr;
cudaError_t rc = cudaMalloc(&ptr, sizeof(int) * 10000);
if (rc != cudaSuccess)
printf("Could not allocate memory: %d", rc);
cudaDeviceSynchronize();
size_t free_byte ;
size_t total_byte ;
cudaMemGetInfo( &free_byte, &total_byte ) ;
cudaDeviceSynchronize();
double free_db = (double)free_byte ;
double total_db = (double)total_byte ;
double used_db = total_db - free_db ;
printf("GPU memory usage: used = %f, free = %f MB, total = %f MB\n",
used_db/1024.0/1024.0, free_db/1024.0/1024.0, total_db/1024.0/1024.0);
return 0;
}
This code prints the same value of used memory regardless of how much memory I allocate in the cudaMalloc statement. What am I doing wrong here?