CUarray allocation for surfaces

Hi all, Marco,

We implemented our whole application based on the driver API. Now I was trying to allocate an array to which a surface can be bound using cuArrayCreate3D with the CUDA_ARRAY3D_DESCRIPTOR.flags set to CUDA_ARRAY3D_SURFACE_LDST. However this does not seem to be working (in contrary to the 4.2 reference manual, the JCuda-docu also says leave .flags @ 0)
So I wanted to mix some runtime api in there, to check if using JCuda.cudaMalloc3DArray(cudaArray, desc, extent, CUDA_ARRAY3D_SURFACE_LDST) might do the trick.

But how do I get my CUarray pointer to be a cudaArray?
From the reference guide:

The types CUarray and struct cudaArray represent the same data type and may be used interchangeably by casting
the two types between each other.
In order to use a CUarray in a CUDA Runtime API function which takes a struct cudaArray , it is necessary to
explicitly cast the CUarray to a struct cudaArray .
In order to use a struct cudaArray in a CUDA Driver API function which takes a CUarray, it is necessary to explicitly
cast the struct cudaArray to a CUarray .

So a constructor like CUarray(cudaArray a) might do the trick. However, it would be even better if the initial problem would be solved and we could have surface-bindable CUarray’s.

Thanks in advance Marco, as always: awesome work :slight_smile:

Hello,

I’ll try to investigate this in more detail in the next days. Can you post a code snippet showing how you tried to do the allocation initially?

bye
Marco

My bad,

Everything works as it should through the Driver API. The flags are passed correctly to the CUDA side. I was simply passing the wrong CUarray to my method :o. Maybe just update the Javadoc of the .flags field (now: “Intended for future use”).

To obtain equivalent Driver and Runtime API mixing as in C, a way to transform a CUarray into a cudaArray would still be needed though (see quote in first post). But that’s not an important feature for me (sticking to the Driver API :)).

Cheers,
Keeth

Hi

Good to hear that, and thanks for this hint: I have updated the Documentation of the main classes (JCuda and JCudaDriver), but missed that flag in CUDA_ARRAY3D_DESCRIPTOR.

However, I’ll also consider the " CUarray(cudaArray a)" that you mentioned, although it is not necessary in this specific case, but since it should at least be possible according to the documentation.

bye
Marco