CUDA Addressing a matrix
===

This is probably a basic question but I couldn't find the answer.
I'm trying to do a 2D convolution so I have sth like this in my kernel:

    A[X-i+(Y-j)*W]

where

    unsigned int X = blockIdx.x * blockDim.x + threadIdx.x;
    unsigned int Y = blockIdx.y * blockDim.y + threadIdx.y;

and W and H are width and height of the image. The problem is whenever I have sth like the above it ignores any CUDA code I have but if I unroll my loops and write it like:

    A[X+Y*W-720]
or any other constant number I need (I calculated i+j*W and put it in the code) it works fine. Can you tell me what I should do?
