Predefined variables for checking image size?


I’m doing a lot of image processing on either 2D- or 3D- image data.

My problem is that that grid and block size if not always direct multiple of my image matrix size.

Therefore I always have to check if I’m inside my image.

const int x = (blockDim.x * blockIdx.x) + threadIdx.x;

const int y = (blockDim.y * blockIdx.y) + threadIdx.y;

// If we are outside the bounds of the image we exit directly.

if(x >= Width)  return;

if(y >= Height) return;

I have to do this all the time for my kernels. What I would like

is to have some built-in variables like we already have for gridDim, blockDim, and so on.

How do you solve such things?