Pass cuda texture variable as an argument

830 views Asked by At

I have setup the cudaArray, and have bound it to a texture:

    texture<float, 2, cudaReadModeElementType> tex;
    cudaChannelFormatDesc channelDesc =
        cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
    cudaArray *cuArray;
    checkCudaErrors(cudaMallocArray(&cuArray,
                                    &channelDesc,
                                    width,
                                    height));
    checkCudaErrors(cudaMemcpyToArray(cuArray,
                                      0,
                                      0,
                                      hData,
                                      size,
                                      cudaMemcpyHostToDevice));

Now I am wondering, if the content within the cuArray and tex remains the same all the time during the calculation, can I pass tex and/or cuArray to another function so that I don't have to do the binding every time?

Something like this:

DoJobUsingTex(float* output, float* input, int size, texture tex)
{
   \\  do something here
}
1

There are 1 answers

1
talonmies On BEST ANSWER

CUDA introduced texture objects when CUDA 5 and Kepler hardware were released. These are so called "bindless" textures which can be passed by value to kernels, so there isn't a need to rebind memory every time you want to run a kernel on different texture data.

You can read more about their use here.