Pointer of a 3D matrix to a kernel

Hi,

The purpose of this question to learn a simpler way to do matrix transformation in JCuda.

Can anyone explain to me, which a short snippet of code, in how I can pass a pointer of a 3D matrix to a kernel?

I will accept being referred to any post related to this topic.

Thank you.

Hello

When you are talking about a “3D array”, you likely have something like a float array[][][];, is this right?

In general, such an array can not be copied to the device directly. For a “3D-array” like a float ***array;, this is not even possible in C/CUDA, and also not in Java/JCuda. I wrote a few words about this in this stackoverflow answer (although this one only refers to 2D, the same applies for 3D as well).

In general, you’d “flatten” your array to be 1D, and then access it accordingly.

So instead of using

float array[][][] = new float[sizeX][sizeY][sizeZ];
array[x][y][z] = 123.0f;

you would write

float array[] = new float[sizeX * sizeY * sizeZ];
array[x + y * sizeX + z * sizeX * sizeY] = 123.0f;

Depending on how this is going to be used, you might want to add some utility methods (or “wrap” the whole array into some utility class) that do the index computations for you.

bye
Marco

Thanks for the reply.

But ran into a problem, I keep getting this error message: cudaErrorIntializationError.

Is it because I am running JCuda 0.6.5 and compiling with NVCC 7.5.

I don’t think it is even possible to get earlier versions of nvcc right?

So, how can run my jcuda program in 64 bit, when the visual studio compiler cl.exe is only 32bit version.

Thanks.

now I am getting error: INVALID cudaError: 201

The error code 201 only seems to appear as a CUresult code, standing for CUDA_ERROR_INVALID_CONTEXT. It is not a valid cudaError code.

The information about the error codes and versions is a bit confusing. If you encounter an error, try to describe clearly on which system the error appears. My guesses from now:

  • A 64 bit system
  • Visual Studio Version Number? (The cl.exe is always 32 bit, as far as I know)
  • CUDA 7.5
  • JCuda 6.5 (64 bit!?)

And also try to describe clearly under which conditions the error appears. In this case: Where do the error codes appear? (In the best case, provide a (minimal!) example where the error can be reproduced)