Hello,
I have an NVIDIA Quadro K2100M which has a 2GB memory and a CC 3.0.
I’m using Visual Studio 2013, x64 platform.
I’m using this test to learn how cudaMallocPitch is working:
#define CUDA_CHECK_ERROR(stmt, fname, line)
{
cudaError_t cudaStatus;
cudaStatus = cudaGetLastError();
if (cudaStatus != cudaSuccess)
{
printf(“File: %s\nLine: %i\nCUDA statement: \n%s\nCUDA error - %08d\n\n”, fname, line, stmt, cudaStatus);
printf(“CUDA error information: %s\n”, cudaGetErrorString(cudaStatus));
getchar();
}
else
{
printf(“File: %s\nLine: %i\nCUDA statement: \n%s\nCUDA error - %08d\n\n”, fname, line, stmt, cudaStatus);
printf(“CUDA No error!!!\n”);
}
};
#define CUDA(stmt) do {
stmt;
CUDA_CHECK_ERROR(#stmt, FILE, LINE);
}while(0)
unsigned int TestSize = 104857600;
unsigned int TestSizeWidth = 10485760;
unsigned int TestSizeHeight = 10485760;
unsigned int Index = 0;
int *dev_c = 0;
size_t free;
size_t total;
size_t pitch;
CUDA(cudaSetDevice(0));
CUDA(cudaDeviceReset());
CUDA(cudaMemGetInfo(&free, &total));
std::cout << " Begin - Available heap memory: " << (float)(free / 1048576.0f) << “MB” << std::endl;
while (1)
{
//CUDA(cudaMalloc((void**)&dev_c, TestSize));
CUDA(cudaMallocPitch((void**)&dev_c, &pitch, TestSizeWidth, TestSizeHeight));
CUDA(cudaMemGetInfo(&free, &total));
std::cout << " Available heap memory: " << (float)(free / 1048576.0f) << "MB" << std::endl;
CUDA(cudaFree(dev_c));
CUDA(cudaMemGetInfo(&free, &total));
std::cout << " After release - Available heap memory: " << (float)(free / 1048576.0f) << "MB";
TestSize += 104857600;
Index++;
std::cout << " Iteration index: " << Index << std::endl;
}
Every loop iteration the requested allocation size from the GPU memory is growing by a 100MB.
When I’m using the cudaMalloc API I’m getting that the loop was stucked during its iteration 20 because the last printed Index value was 19.
This is exactly what I was expected to get due to the fact that the total GPU memory is 2GB and I’m asking 100MB more each loop iteration starting from 100MB.
But when I’m using the same loop but with the cudaMallocPitch API which ask for 100MB also by sending a width of 10MB and height of 10MB the first call is failed and return an error number 2 which is the cudaErrorMemoryAllocation error of the CUDA driver.
Please advise.