Hi,
What is the wrong with the belowcode in CUDA in Debug mode( NOT in EmuDebug )?
struct MyStr
{
int* iPtr;
float* fPtr;
}
MyStr* str;
CUDA_SAFE_CALL( cudaMalloc( (void**)&str, sizeof(MyStr) ); // This is working fine, no crash here, but the members of str is showing “Red” symbol ( i.e., not valid ) while debugging
CUDA_SAFE_CALL( cudaMalloc( (void**)&str->iPtr, sizeof(int)*20 ); // Here I got the crash, cuda stop working and running mode automatically stopped.
Now, please answer the questions…
-
Why the first statement is showing its members as not valid?
[ ok, we can say that, if we allocating the memory only to str not for str members. ok, fine :) ] -
But why the second statement is giving crash?
-
If I write something like the following…
CUDA_SAFE_CALL( cudaMalloc( (void**)&str, sizeof(str) );
int* intPtr = NULL;
CUDA_SAFE_CALL( cudaMalloc( (void**)intPtr, sizeof(int)*20 );
CUDA_SAFE_CALL( cudaMemcpy( &str->iPtr, intPtr, sizeof(int)*20, cudaMemcpyHostToDevice ) );then its working fine. why?
So, do we have a copy in Host whenever we allocate memory in GPU? ( but I dont think so )
please answer above questions.