# can we pass structure pointer to kernel

**URL:** <https://forums.developer.nvidia.com/t/can-we-pass-structure-pointer-to-kernel/14251>\
**Category:** CUDA Programming and Performance\
**Created:** [January 11, 2010, 1:10am UTC](https://forums.developer.nvidia.com/t/can-we-pass-structure-pointer-to-kernel/14251 "2010-01-11T01:10:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amoljaikar](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@amoljaikar](https://forums.developer.nvidia.com/u/amoljaikar)\
**Post date:** [January 11, 2010, 1:10am UTC](https://forums.developer.nvidia.com/t/can-we-pass-structure-pointer-to-kernel/14251/1 "2010-01-11T01:10:59Z")

</div>

Respected all,

I am doing some code in cuda. I am new in cuda so i do not know much things related to that.

I want to ask that “Can we pass structure pointer to kernel ?”

waiting for response

---

<div class="post-metadata">

**Author:** ![SPWorley](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@SPWorley](https://forums.developer.nvidia.com/u/SPWorley)\
**Post date:** [January 11, 2010, 2:49am UTC](https://forums.developer.nvidia.com/t/can-we-pass-structure-pointer-to-kernel/14251/2 "2010-01-11T02:49:23Z")

</div>

Yes, if the structure lives on the device. You can’t pass a pointer to a HOST structure without first copying over the structure to the device.

[There’s a fancy exception to the need to copy the structure using zero-copy memory, but even in that case the pointer you pass in a device pointer.]

---

<div class="post-metadata">

**Author:** ![amoljaikar](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@amoljaikar](https://forums.developer.nvidia.com/u/amoljaikar)\
**Post date:** [January 11, 2010, 4:28am UTC](https://forums.developer.nvidia.com/t/can-we-pass-structure-pointer-to-kernel/14251/3 "2010-01-11T04:28:18Z")

</div>

> [@](#):
>
> Yes, if the structure lives on the device. You can’t pass a pointer to a HOST structure without first copying over the structure to the device.
> 
> [There’s a fancy exception to the need to copy the structure using zero-copy memory, but even in that case the pointer you pass in a device pointer.]

can i do like this?

Pixel is the structure having 4 bytes

Pixel \*p;

cudaMalloc((PIXEL \*\*)p,size);

//i thing above line will create the buffer on GPU of sizeof(PIXEL)\*size

//is it correct? then can i do like this

kernel\<\<\<dimGrid,dimBlock\>\>\>(p,…);

//passing pointer to the kernel
