Hi…
I am new to CUDA and trying to understand the cudaMallocPitch() functions here. I am not able to understand the concept and use of “pitch” as is used here in matrix functions.
Also do explain the meaning of the following line (in bold) in the code below.
// host code
float* devPtr;
int pitch;
cudaMallocPitch((void**)&devPtr, &pitch,
width * sizeof(float), height);
myKernel<<<100, 512>>>(devPtr, pitch);
// device code
global void myKernel(float* devPtr, int pitch)
{
for (int r = 0; r < height; ++r) {
float* row = (float*)((char*)devPtr + r * pitch);
for (int c = 0; c < width; ++c) {
float element = row[c];
}
}
}