Dealing with Structures

Hello again,

So I do a lot with data structures/classes (not so much classes on the device - basically have to dumb the data content from my class into a structure container) - what I do to allocate the device structure is something along the lines:

struct A{

    float * Values;

};

__global__ void AGreatFunction(A * DevS){

    DevS->Values+=1;

};

int main(){

struct * DevA, * HostA, * HostAData;

/*Assign data to HostAData->Values...*/

cudaMalloc(HostA->A...);

cudaMalloc(DevA);

// copy memory from host data source to device pointer

// Pointed to by HostA->A

cudaMemCpy(HostA->A,HostAData->a,...,HostToDevice);

// Copy the 'HostA->A device pointer' structure

// to the 'DevA' structure. i.e., now DevA will point

// To the correct regions of device memory where I have copied

// Data over, while maintaining its structure

cudaMemcpy(Deva,HostA..blah HostToDevice);

/*... Run some kernel er something*/

AGreatFunction<<<griddim,blockdim>>>(A * DevS)

So this all works fine, however- is there an easier way to do this? I have to define 3 structures to make 1 copy from host to device (no you cant do (cudaMemCpy(HostAData->A,HostAData->a,…,HostToDevice) - it segfaults, and for good reason). This is a roundabout way to maintain my data structure (I’m dealing with around 13 large (1024x1024 or greater) 2D arrays on 1D cuda memory, so in order to make accessing all the arrays easier I do structures instead of just straight float pointers (looks messy when you have 13+ arguments to a function).

So all in all I’m pissed I have to copy structures this way. If anyone else has a suggestion I would greatly appreciate it : ) Besides this when I compile my code I get about 300 (seriously, 300… I have a lot of references) “Warning: Cannot tell what pointer points to, assuming global memory space” Warnings. I’m guessing these are safe to ignore as long as I’m sure I did all the cudamallocs.

Well thanks for reading, and appreciate any help as usual.

Hello again,

So I do a lot with data structures/classes (not so much classes on the device - basically have to dumb the data content from my class into a structure container) - what I do to allocate the device structure is something along the lines:

struct A{

    float * Values;

};

__global__ void AGreatFunction(A * DevS){

    DevS->Values+=1;

};

int main(){

struct * DevA, * HostA, * HostAData;

/*Assign data to HostAData->Values...*/

cudaMalloc(HostA->A...);

cudaMalloc(DevA);

// copy memory from host data source to device pointer

// Pointed to by HostA->A

cudaMemCpy(HostA->A,HostAData->a,...,HostToDevice);

// Copy the 'HostA->A device pointer' structure

// to the 'DevA' structure. i.e., now DevA will point

// To the correct regions of device memory where I have copied

// Data over, while maintaining its structure

cudaMemcpy(Deva,HostA..blah HostToDevice);

/*... Run some kernel er something*/

AGreatFunction<<<griddim,blockdim>>>(A * DevS)

So this all works fine, however- is there an easier way to do this? I have to define 3 structures to make 1 copy from host to device (no you cant do (cudaMemCpy(HostAData->A,HostAData->a,…,HostToDevice) - it segfaults, and for good reason). This is a roundabout way to maintain my data structure (I’m dealing with around 13 large (1024x1024 or greater) 2D arrays on 1D cuda memory, so in order to make accessing all the arrays easier I do structures instead of just straight float pointers (looks messy when you have 13+ arguments to a function).

So all in all I’m pissed I have to copy structures this way. If anyone else has a suggestion I would greatly appreciate it : ) Besides this when I compile my code I get about 300 (seriously, 300… I have a lot of references) “Warning: Cannot tell what pointer points to, assuming global memory space” Warnings. I’m guessing these are safe to ignore as long as I’m sure I did all the cudamallocs.

Well thanks for reading, and appreciate any help as usual.