structure as argument

Hello,
I have a structure of kind
typedef struct {
short ,
short ,
struct NNP ,
struct NNP ,
short *} XYZ;

when i try to pass this structure as pointer , I find elements either have zero or wrong values but if i pass all elements as separate arguments everything works fine.
may i know the reason fro such abnormal behavior & also how to solve it ?

thanks in advance

Is this when you call a global function?

If you are trying to pass the pointer from host code to global function, then the pointer will have to be a pointer to device memory after you copy the data to the device. And don’t try to use pass by reference, &, either, since that is treated as a pointer when compiled.

i am using pointer to device memory .

still i m getting either wrong values or zero

Are you calling a global function from the host, or are you calling a device function from a device_ function.

If you are calling device from device, try not passing the pointer, but try passing by value.

If you can, make a small code example that has the same problem.

typedef struct {
short D,
short* E,
short* F} NNP;
typedef struct {
short A,
short B,
NNP* R ,
NNP* S,
short } XYZ;
void Test(XYZ * Arg)
{
XYZ * d_Arg;
CUDA_SAFE_CALL( cudaMalloc( (void
*) &d_Arg, sizeof(XYZ)));
d_Arg->A=Arg->A;
d_Arg->B=Arg->B;
CUDA_SAFE_CALL( cudaMalloc( (void**) &d_Arg->R, sizeof(NNP)));
CUDA_SAFE_CALL( cudaMemcpy(d_Arg->R, Arg->R, sizeof(NNP),cudaMemcpyHostToDevice) );

CUDA_SAFE_CALL( cudaMalloc( (void**) &d_Arg->S, sizeof(NNP)));
CUDA_SAFE_CALL( cudaMemcpy( d_Arg->S, Arg->S, sizeof(NNP),cudaMemcpyHostToDevice) );

CUDA_SAFE_CALL( cudaMalloc( (void**) &d_Arg->R->E, 240sizeof(short)));
CUDA_SAFE_CALL( cudaMemcpy(d_Arg->R->E, Arg->R->E, 240
sizeof(short),cudaMemcpyHostToDevice) );

CUDA_SAFE_CALL( cudaMalloc( (void**) &d_Arg->R->F, 240sizeof(short)));
CUDA_SAFE_CALL( cudaMemcpy(d_Arg->R->F, Arg->R->F, 240
sizeof(short),cudaMemcpyHostToDevice) );

TestKernel<<< grid, threads, 0 >>>(d_Arg,d_Arg->A);

}

global TestKernel(XYZ * d_Arg,short Val)
{

here whne i access d_Arg->A,d_Arg->B i get zero or wrong value but Val has correct value of d_Arg->A.

}

You can’t directly access device memory from the host like that–you have to explicitly do cudaMemcpys.