Hello,
I am using following code snippet:
++++++++++++++++++++++++++++++++++
struct obj_struct
{
double North[NuObj];
double East[NuObj];
double Dist[NuObj][NuObj];
double Area;
double* C2C;
double* Length;
};
struct obj_struct* d_Object;
cutilSafeCall(cudaMalloc((void**)&d_Object, sizeof(struct obj_struct)));
cutilSafeCall(cudaMalloc((void**)&(d_Object->C2C), NuObjNuSectsizeof(double)));
+++++++++++++++++++++++++++++++++++++++
I get Segmentation Fault at the second “cudaMalloc” call. I understand that the second CudaMalloc call is “INVALID” as per CUDA programming specifications. I wanted to understand the internal details from CUDA architecture point of view that why it is so ?
I am using:
CUDA toolkit Release 4.0
GPU M2070
CentOS 5.6, 64 bit
Your trying to access a device side pointer “d_Object” from the host which will give you an invalid pointer. Rule of thumb: never try to operate on a device side pointer from the host for other than passing it to functions that can make use of it ( ex my_kernel<<<< , >>>( device_ptr), cudaMalloc((void**)&my_ptr, size) , etc).
What you could do in above example is to first have a host side struct that gets its pointer set to device side buffer via cudaMalloc, in the next step you cudamemcpy your host side struct into “d_Object”.