# invalid device function error: cudaErrorInvalidDeviceFunction

**URL:** <https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064>\
**Category:** CUDA Programming and Performance\
**Created:** [October 24, 2008, 4:24pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064 "2008-10-24T16:24:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raphael](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Raphael](https://forums.developer.nvidia.com/u/Raphael)\
**Post date:** [October 24, 2008, 4:24pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/1 "2008-10-24T16:24:44Z")

</div>

Hi Cuda Experts,

when calling kernel ‘asdf’ i get the cudaErrorInvalidDeviceFunction error.

after hours of experimenting with that problem, does anybody have a suggestion what the problem may be?

```auto
extern "C" void scatter_display(GLuint pbo, float *d_dataX, float *d_dataY, int noPoints, float viewMinValX, float viewMaxValX, float viewMinValY, float viewMaxValY, uint dimX, uint dimY, uint dimZ)

{

	dim3 blockSize0(dimX,1,1);

	dim3 gridSize0(dimY,dimZ,1);

	

	asdf<<<gridSize0, blockSize0>>>(d_dataX); 

	cudaError_t ce = cudaGetLastError();

	if(ce != cudaSuccess)

  return;

}

__global__ void asdf(float *d_dataX)

{

	uint idx = threadIdx.x +blockIdx.x*blockDim.x + blockIdx.y*blockDim.x*gridDim.x;

	d_dataX[idx] = d_dataX[idx]+1;

}

```

thanks,

raphael

---

<div class="post-metadata">

**Author:** ![yamsha](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@yamsha](https://forums.developer.nvidia.com/u/yamsha)\
**Post date:** [October 24, 2008, 7:07pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/2 "2008-10-24T19:07:39Z")

</div>

> [@](#):
>
> Hi Cuda Experts,
> 
> when calling kernel ‘asdf’ i get the cudaErrorInvalidDeviceFunction error.
> 
> after hours of experimenting with that problem, does anybody have a suggestion what the problem may be?
> 
> ```auto
> extern "C" void scatter_display(GLuint pbo, float *d_dataX, float *d_dataY, int noPoints, float viewMinValX, float viewMaxValX, float viewMinValY, float viewMaxValY, uint dimX, uint dimY, uint dimZ)
> 
> {
> 
> dim3 blockSize0(dimX,1,1);
> 
> dim3 gridSize0(dimY,dimZ,1);
> 
> 	
> 
> asdf<<<gridSize0, blockSize0>>>(d_dataX); 
> 
> cudaError_t ce = cudaGetLastError();
> 
> if(ce != cudaSuccess)
> 
> Â return;
> 
> }
> 
> __global__ void asdf(float *d_dataX)
> 
> {
> 
> uint idx = threadIdx.x +blockIdx.x*blockDim.x + blockIdx.y*blockDim.x*gridDim.x;
> 
> d_dataX[idx] = d_dataX[idx]+1;
> 
> }
> 
> ```
> 
> thanks,
> 
> raphael
> 
> [snapback]456075[/snapback]

Is the kernel in the same file with the function that calls it? Because if it’s not, you might need to “include” it or declare the kernel as extern.

---

<div class="post-metadata">

**Author:** ![tmurray](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tmurray](https://forums.developer.nvidia.com/u/tmurray)\
**Post date:** [October 24, 2008, 8:21pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/3 "2008-10-24T20:21:56Z")

</div>

uh, do you have a declaration for the kernel before the invocation?

---

<div class="post-metadata">

**Author:** ![Raphael](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Raphael](https://forums.developer.nvidia.com/u/Raphael)\
**Post date:** [October 24, 2008, 9:17pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/4 "2008-10-24T21:17:22Z")

</div>

thanks tmurray & yamsha

> [@](#):
>
> uh, do you have a declaration for the kernel before the invocation?
> 
> [snapback]456174[/snapback]

yes, the kernel is declared at the beginning of the file.

> [@](#):
>
> Is the kernel in the same file with the function that calls it?

yes, there is one single cu file…

basically, if added some #includes (cutil, runtime,…) and the declaration of the kernel, you’ve got the whole file already …

---

<div class="post-metadata">

**Author:** ![Raphael](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Raphael](https://forums.developer.nvidia.com/u/Raphael)\
**Post date:** [October 27, 2008, 9:41am UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/5 "2008-10-27T09:41:04Z")

</div>

Hello again,

i’m still unable to figure out this problem… :wacko: I’ve made a simpler version that reproduces the error - any ideas???

thx,

raphael

> [@](#):
>
> #include \<cutil.h\>
> 
> typedef unsigned int uint;
> 
> typedef unsigned char uchar;
> 
> **global** void asdf(float \*d\_dataX);
> 
> extern “C” bool test\_display(uint dimX, uint dimY, uint dimZ)
> 
> {
> 
> ```
> float *data_d = NULL;
> 
> cudaMalloc((void**)&data_d, dimX*dimY*dimZ*sizeof(float));
> 
> float *data = new float[dimX*dimY*dimZ];
> 
> for(int i=0;i<dimX;i++)
> 
> ```
> 
> for(int j=0;j\<dimY;j++)
> 
> for(int k=0;k\<dimZ;k++)
> 
> data[i+j\*dimX+k\*dimX\*dimY]=i+j_dimX+k_dimX\*dimY;
> 
> ```
> cudaMemcpy(data, data_d, dimX*dimY*dimZ*sizeof(float), cudaMemcpyDeviceToHost);
> 
> cudaError_t ce1 = cudaGetLastError();
> 
> if(ce1 != cudaSuccess)
> 
> ```
> 
> return false;
> 
> ```
> dim3 blockSize0(dimX,1,1);
> 
> dim3 gridSize0(dimY,dimZ,1);
> 
> asdf<<<gridSize0, blockSize0>>>(data_d);
> 
> cudaError_t ce2 = cudaGetLastError();
> 
> if(ce2 != cudaSuccess)
> 
> ```
> 
> return false;
> 
> ```
> return true;
> 
> ```
> 
> }
> 
> **global** void asdf(float \*d\_dataX)
> 
> {
> 
> ```
> uint idx = threadIdx.x +blockIdx.x*blockDim.x + blockIdx.y*blockDim.x*gridDim.x;
> 
> d_dataX[idx] = d_dataX[idx]+1;
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![Raphael](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Raphael](https://forums.developer.nvidia.com/u/Raphael)\
**Post date:** [October 27, 2008, 10:33am UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/6 "2008-10-27T10:33:33Z")

</div>

Solved. There was another cuda call initializing a pbo which was wrong and somehow killed cuda. The code up there now works fine.

> [@](#):
>
> Hello again,
> 
> i’m still unable to figure out this problem… :wacko:&nbsp; I’ve made a simpler version that reproduces the error - any ideas???
> 
> thx,
> 
> raphael
> 
> [snapback]457072[/snapback]

---

<div class="post-metadata">

**Author:** ![Xiang\_Song](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Xiang\_Song](https://forums.developer.nvidia.com/u/Xiang_Song)\
**Post date:** [March 12, 2010, 12:06pm UTC](https://forums.developer.nvidia.com/t/invalid-device-function-error-cudaerrorinvaliddevicefunction/6064/7 "2010-03-12T12:06:33Z")

</div>

> [@](#):
>
> Solved. There was another cuda call initializing a pbo which was wrong and somehow killed cuda. The code up there now works fine.

How to solve this? How do you identify what is from cuda and how do you clear them up?

Thanks,

Xiang
