Binding Textures and Passing Textures in a Structure

I am a bit confused with textures. I have too many parameters for a kernel that I am passing them in a structure. Those variables that are not textures do not give me any trouble. But I seem to be having some trouble with those that are bound to textures. The process I am using is as follows;

declare structures containing parameters on host and device

create structures

create structure parameters on device

assign parameters to host structure

cudaMemcopy host structure to device structure

(This works because I have done it with non-texture parameters)

Before calling the kernel in file a.cu I calculate the thread grid and bind parameter s from the structure to texture sTex via

cudaBindTexture(0, sTex, parameters->s,numBodies*sizeof(float));

I then pass the structure to the kernel, execute the kernel then unbind sTex.

The kernel and texture are defined in a separate file b.cu. In the kernel code I refer to the texture as follows

parameters->sorted_s[index] = FETCH(s, sortedData.y);

But in doing this I get a segmentation fault.

When I refer to the texture in the kernel as follows

parameters->new_s[index] = FETCH(parameters->s, sortedData.y);

I get the compile error that the parameters structure does not contain sTex.

So my question is, if the texture is defined in the same file as the kernel and the kernel call and texture binding are in a different file then do I have to pass the bound variable or the texture, and if using a structure then how should the texture be referenced and dereferenced?

I am a bit confused with textures. I have too many parameters for a kernel that I am passing them in a structure. Those variables that are not textures do not give me any trouble. But I seem to be having some trouble with those that are bound to textures. The process I am using is as follows;

declare structures containing parameters on host and device

create structures

create structure parameters on device

assign parameters to host structure

cudaMemcopy host structure to device structure

(This works because I have done it with non-texture parameters)

Before calling the kernel in file a.cu I calculate the thread grid and bind parameter s from the structure to texture sTex via

cudaBindTexture(0, sTex, parameters->s,numBodies*sizeof(float));

I then pass the structure to the kernel, execute the kernel then unbind sTex.

The kernel and texture are defined in a separate file b.cu. In the kernel code I refer to the texture as follows

parameters->sorted_s[index] = FETCH(s, sortedData.y);

But in doing this I get a segmentation fault.

When I refer to the texture in the kernel as follows

parameters->new_s[index] = FETCH(parameters->s, sortedData.y);

I get the compile error that the parameters structure does not contain sTex.

So my question is, if the texture is defined in the same file as the kernel and the kernel call and texture binding are in a different file then do I have to pass the bound variable or the texture, and if using a structure then how should the texture be referenced and dereferenced?

Hi!

  1. Does FETCH function fetch into the texture?? To access to the texture from the kernel you can access with tex2D(sTex,x,y) for example. In the main function, you have done the bind and then, you can access to the texture directly from the kernel. The texture is sTex, is not? In this code you never access to the texture (i think).
  2. Anyway, you must see the simpleTexture example of the SDK.

Regards!

Hi!

  1. Does FETCH function fetch into the texture?? To access to the texture from the kernel you can access with tex2D(sTex,x,y) for example. In the main function, you have done the bind and then, you can access to the texture directly from the kernel. The texture is sTex, is not? In this code you never access to the texture (i think).
  2. Anyway, you must see the simpleTexture example of the SDK.

Regards!

the FETCH does a tex1Dfetch.

I adapted one of the projects in the SDK for the project I’m working on, and it bound a variable to a texture, but still passed the bound variable to the kernel, so I have been using that believing I had to pass the bound variable. But I’ve just tried not passing the bound variable and that worked, so no you don’t have to pass the variable that has been bound to a texture because the kernel knows you are refering to a texture (if your texture definitions are correct).

But I still needed to bind a variable in a structure to a texture, and after some trial and error now think that you have to pass that variable as an individual variable even though it is a member of a structure. Then instead of binding to the reference in the structure you bind to the individual variable. This works. But I don’t know why.

the FETCH does a tex1Dfetch.

I adapted one of the projects in the SDK for the project I’m working on, and it bound a variable to a texture, but still passed the bound variable to the kernel, so I have been using that believing I had to pass the bound variable. But I’ve just tried not passing the bound variable and that worked, so no you don’t have to pass the variable that has been bound to a texture because the kernel knows you are refering to a texture (if your texture definitions are correct).

But I still needed to bind a variable in a structure to a texture, and after some trial and error now think that you have to pass that variable as an individual variable even though it is a member of a structure. Then instead of binding to the reference in the structure you bind to the individual variable. This works. But I don’t know why.