0

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
}
einpoklum
  • 118,144
  • 57
  • 340
  • 684
Nick X Tsui
  • 2,737
  • 6
  • 39
  • 73
  • 1
    https://devblogs.nvidia.com/parallelforall/cuda-pro-tip-kepler-texture-objects-improve-performance-and-flexibility/ – talonmies Jan 24 '17 at 18:20
  • @talonmies I have not tried it out, but it looks like exactly what I need. Can you please post it as an answer so I can accept it? Thanks a lot. – Nick X Tsui Jan 24 '17 at 19:33

1 Answers1

2

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.

tera
  • 7,080
  • 1
  • 21
  • 32
talonmies
  • 70,661
  • 34
  • 192
  • 269