# invalid texture reference

**URL:** <https://forums.developer.nvidia.com/t/invalid-texture-reference/10127>\
**Category:** CUDA Programming and Performance\
**Created:** [June 13, 2009, 4:44pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127 "2009-06-13T16:44:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 13, 2009, 4:44pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/1 "2009-06-13T16:44:32Z")

</div>

I only have a single .cu file.

I have declared texture as global and static and outside main{} function as:-

static texture\<float,3,cudaReadModeElementType\> tex;

Now inside main i have loaded a 3D Binary Image in a 1D array(h\_image) in host memory and then copied it into the device memory using following code.

//To Load the Same Image in Device Memory in cudaArray.  
cudaArray\* d\_image;

// setup texture dimension  
cudaExtent extent;  
extent.width = width;  
extent.height = height;  
extent.depth = depth;

// texture channel descriptor  
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc();

// memory allocation for texture, on GPU, allocates GPU memory as 3D cuda memory  
cudaMalloc3DArray(&d\_image, &channelDesc, extent);

// copy from host memory to device memory  
cudaMemcpy3DParms copyParams = {0};  
copyParams.srcPtr = make\_cudaPitchedPtr((void\*)h\_image, height\*sizeof(float), height, depth);  
copyParams.dstArray = d\_image;  
copyParams.extent = extent;  
copyParams.kind = cudaMemcpyHostToDevice;

//copy from host memory to device memory  
safecall( cudaMemcpy3D(&copyParams), “cudaMemcpy3D” );

// set texture parameters  
tex.normalized = true;  
tex.filterMode = cudaFilterModeLinear;  
tex.addressMode[0] = cudaAddressModeWrap;  
tex.addressMode[1] = cudaAddressModeWrap;  
tex.addressMode[2] = cudaAddressModeWrap;

// bind cudaArray to the texture  
cudaBindTextureToArray(tex, d\_image,channelDesc);

cuda\_kernel\<\<\<64,64\*64\>\>\>();

NOW

The code compiles but when i run it it gives me error as “invalid texture reference.”

I dont know what am i doing wrong here.

I am loading 3D image into 1D array in host then copying it into device. Are my steps correct for this?

Also we can directly fetch values from cudaArray (i read it in this forum iteself), so we have to bind it to texture so i was trying to do the same and its the same thing giving error. What is wrong here?

Also after binding, i am confused about how do i write my kernel to loop through the values in the texture.?

Please help me, i am stuck here.

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 13, 2009, 9:45pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/2 "2009-06-13T21:45:52Z")

</div>

> [@](#):
>
> static texture\<float,3,cudaReadModeElementType\> tex;
> 
> //To Load the Same Image in Device Memory in cudaArray.
> 
> ```
> cudaArray* d_image;
> 
> ```
> 
> // setup texture dimension
> 
> ```
> cudaExtent extent;
> 
> extent.width = width;
> 
> extent.height = height;
> 
> extent.depth = depth;
> 
> ```
> 
> // texture channel descriptor
> 
> cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc();
> 
> // memory allocation for texture, on GPU, allocates GPU memory as 3D cuda memory
> 
> cudaMalloc3DArray(&d\_image, &channelDesc, extent);
> 
> // copy from host memory to device memory
> 
> cudaMemcpy3DParms copyParams = {0};
> 
> copyParams.srcPtr = make\_cudaPitchedPtr((void\*)h\_image, height\*sizeof(float), height, depth);
> 
> copyParams.dstArray = d\_image;
> 
> copyParams.extent = extent;
> 
> copyParams.kind = cudaMemcpyHostToDevice;
> 
> //copy from host memory to device memory
> 
> safecall( cudaMemcpy3D(&copyParams), “cudaMemcpy3D” );
> 
> // set texture parameters
> 
> tex.normalized = true;
> 
> tex.filterMode = cudaFilterModeLinear;
> 
> tex.addressMode[0] = cudaAddressModeWrap;
> 
> tex.addressMode[1] = cudaAddressModeWrap;
> 
> tex.addressMode[2] = cudaAddressModeWrap;
> 
> // bind cudaArray to the texture
> 
> cudaBindTextureToArray(tex, d\_image,channelDesc);
> 
> cuda\_kernel\<\<\<64,64\*64\>\>\>();

On giving a second thought… can i just directly use 3D cudaArray without binding it to any texture. I am confused… i think its not possible. IS IT ?

Also i am doing this to achieve 3D sobel filtering in the 3D image i load cudaArray.

Am i doing it correctly… am i following the right steps…

i cant find any appropriate document regarding handling 3D data and performing operation in [nvidia.com](http://nvidia.com) or any other place…

so any suggestion is highly appreciated…

thanks and help me out here… i m stuck… [External Media](http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/ermm.gif "Media hosted on another site. Click to open in a new tab.") :( :o [External Media](http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/argh.gif "Media hosted on another site. Click to open in a new tab.")

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 13, 2009, 10:55pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/3 "2009-06-13T22:55:46Z")

</div>

anyone??? :(

---

<div class="post-metadata">

**Author:** ![\_Big\_Mac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@\_Big\_Mac](https://forums.developer.nvidia.com/u/_Big_Mac)\
**Post date:** [June 14, 2009, 3:00pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/4 "2009-06-14T15:00:29Z")

</div>

I don’t remember having to put static in front of texture declaration. Have you tried without?

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 14, 2009, 5:05pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/5 "2009-06-14T17:05:00Z")

</div>

Hi there,

Thanks for the reply

> [@](#):
>
> I don’t remember having to put static in front of texture declaration. Have you tried without?

Yah i have tried it without static as well but it gives me the same error. Any other clues??

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 15, 2009, 4:59pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/6 "2009-06-15T16:59:00Z")

</div>

are there any chance of version problem for this error:

when i enter nvcc --version it gives me following output

nvcc: NVIDIA ® Cuda compiler driver  
Copyright © 2005-2009 NVIDIA Corporation  
Built on Thu\_Apr\_\_9\_05:05:52\_PDT\_2009  
Cuda compilation tools, release 2.2, V0.2.1221

Does this version support 3D texture.

If not… are there any references available which can give me an idea how to split 3D texture into series of 2D texture and work on it?

---

<div class="post-metadata">

**Author:** ![\_Big\_Mac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@\_Big\_Mac](https://forums.developer.nvidia.com/u/_Big_Mac)\
**Post date:** [June 15, 2009, 6:25pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/7 "2009-06-15T18:25:11Z")

</div>

It should, AFAIR 3D textures are in since 2.0. I’ve never used 3D textures so I can’t help. Have you tried going through the example in SDK step by step?

---

<div class="post-metadata">

**Author:** ![wanderine](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wanderine](https://forums.developer.nvidia.com/u/wanderine)\
**Post date:** [June 15, 2009, 9:11pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/8 "2009-06-15T21:11:03Z")

</div>

Don’t know if it matters, but have you declared the texture in the .cu file or in the …\_kernel.cu file?

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 15, 2009, 9:14pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/9 "2009-06-15T21:14:10Z")

</div>

> [@](#):
>
> Don’t know if it matters, but have you declared the texture in the .cu file or in the …\_kernel.cu file?

I only have one .cu file for now… just one file and i am coding everything inside the same cu file.

I am compiling it like nvcc test.cu

that’s all…

am i missing something??

my file compiles well but when i try to run a.out ( general case), it gives me this error.

any clues??

---

<div class="post-metadata">

**Author:** ![wanderine](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wanderine](https://forums.developer.nvidia.com/u/wanderine)\
**Post date:** [June 15, 2009, 9:17pm UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/10 "2009-06-15T21:17:47Z")

</div>

E-mail the code to [wanderine@hotmail.com](mailto:wanderine@hotmail.com) and I can try the code at work tomorrow.

---

<div class="post-metadata">

**Author:** ![miztaken](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@miztaken](https://forums.developer.nvidia.com/u/miztaken)\
**Post date:** [June 16, 2009, 5:13am UTC](https://forums.developer.nvidia.com/t/invalid-texture-reference/10127/11 "2009-06-16T05:13:51Z")

</div>

> [@](#):
>
> E-mail the code to [wanderine@hotmail.com](mailto:wanderine@hotmail.com) and I can try the code at work tomorrow.

sure … i will mail u soon…
