stucture poiter for kernal (not solved Problem)

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

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

can i create a pointer for each structure?

like i want to access the each structure’s element into 1 thread.

like P[i].xyz = c[i];

p is structure array and c is character array.

can i do that?

Sorry, that I do not answer directly to your question. I’m not so familiar with pointers.

In my program I use such construction:

typedef struct {

	int rgb[3];

} c_m;

extern "C" void cu_img_up(bmp img_in, bmp img_out)

{

...

	c_m * ca;

	c_m * cc;

	cudaMalloc ((void**)&ca, numBytes);

	cudaMalloc ((void**)&cc, numBytes);

	cudaMemcpy	  (ca, a, numBytes, cudaMemcpyHostToDevice);

	cudaMemcpy	  (cc, c, numBytes, cudaMemcpyHostToDevice);

		dim3 threads = dim3(3, 1);

	dim3 blocks = dim3(height, width);

	img_upKernel<<<blocks, threads>>>(ca, cc, height, width);

	

	cudaMemcpy	  (c, cc, numBytes, cudaMemcpyDeviceToHost);

...

	cudaFree		 (ca   );

	cudaFree		 (cc   );

}

__global__ void img_upKernel (c_m* ca, c_m* cc, int h, int w)

{ 

	int tx = threadIdx.x;

	int idx = blockIdx.x * gridDim.y + blockIdx.y;

	

	cc[idx].rgb[tx] = ca[idx].rgb[tx] + 40;

	if (cc[idx].rgb[tx] > 255)

		cc[idx].rgb[tx] = 255;

	

}