use of textures in a kernel that is called many times

I’m a bit unclear on how things work with textures wrt multiple kernel invocations. My use case is that I have three arrays to process by the same kernel. I want to use a 2d texture for the arrays. My understanding (I am new so may be wrong) is that it’s not possible to pass texture reference as a parameter to the kernel so the kernel is hard coded to use a single texture. Also that kernel invocations are asynchronous. So will there be any problem calling the kernel that refer a single hard coded texture multiple times?

for i = 1 to n:

  allocate pitched device memory for array i

  copy array i host memory to device

for i = 1 to n:

  bind array i to texture

  call kernel

  unbind texture

for i = 1 to n:

  free array i device memory

Do I have to put a blocking synchronization call in 2nd the loop? What if I wanted to use cuda streams? Is there any problem to worry about?

You can bind more than one texture at a time, so you can use more than one texture in a single kernel.

You are correct that you cannot pass textures as arguments to the kernels. The last bind call made prior to the kernel launch is the bind that will be active when the kernel executes (I’ve never found a reason to un-bind). There is no problem in calling a kernel that refers to the same texture multiple times. Just call the bind texture before each launch as you indicate in your pseudocode.