# passing information between kernels ?

**URL:** <https://forums.developer.nvidia.com/t/passing-information-between-kernels/10938>\
**Category:** CUDA Programming and Performance\
**Created:** [July 16, 2009, 10:27pm UTC](https://forums.developer.nvidia.com/t/passing-information-between-kernels/10938 "2009-07-16T22:27:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![randal](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@randal](https://forums.developer.nvidia.com/u/randal)\
**Post date:** [July 16, 2009, 10:27pm UTC](https://forums.developer.nvidia.com/t/passing-information-between-kernels/10938/1 "2009-07-16T22:27:33Z")

</div>

Hi ,

Is it possible to use the results of 1 kernel ,stored on the device memory, by another kernel?? or should we do the tedious method of copying the result to the host and transfering that back to the new kernel?

Thanks,  
randal

---

<div class="post-metadata">

**Author:** ![eyalhir74](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@eyalhir74](https://forums.developer.nvidia.com/u/eyalhir74)\
**Post date:** [July 17, 2009, 5:29am UTC](https://forums.developer.nvidia.com/t/passing-information-between-kernels/10938/2 "2009-07-17T05:29:18Z")

</div>

> [@](#):
>
> Is it possible to use the results of 1 kernel ,stored on the device memory, by another kernel?? or should we do the tedious method of copying the result to the host and transfering that back to the new kernel?

Of course you can. Just allocate a device output pointer and pass it to both kernels,

something like this:

```auto
__global__ void KernelA( float *pIn, float *pOut )

{

  ....

  pOut[threadIdx.x] = <someValue>; // or pOut[0] = <SomeValue>

}

__global__ void KernelB( float *pAnotherIn, float *pKernelAResult, float *pKernelBResult )

{

  ....

  pKernelBResult[threadIdx.x] = <SomeValue> * pKernelAResult[threadIdx.x]; // or any other formula...

}

```

Then copy the pKernelBResult values to host using regular cudaMemcpy

eyal
