Hi,
struct MyStr
{
int a;
int* iPtr;
long l;
float* fPtr
}
void HostFun( MyStr* str )
{
cudaMalloc( (void**)&str->iPtr, str->a );
cudaMalloc( (void**)&str->fPtr, str->l );
}
global void GloFun( int* iPtr, float* fPtr )
{
// I’m doing something here…
}
main()
{
MyStr str;
str.a = 10;
str.l = 10;
HostFun( &str );
GloFun<<<1,1>>>( str.iPtr, str.fPtr )
cudaFree( str.iPtr);
cudaFree( str.fPtr);
}
see the above code. and please answer
- I’m declaring a structure variable (str) in main(). so str is in host memory. Is it Right or not?
- I’m allocating the device memory for the members of str in host function HostFun(). but str is in host memory. Is this fine or not?
- I’m passing the pointers in global function as arguments. when I’m accessing or doing something using those pointers will do anything? or it just works fine?
- I’m freeing the memory in main() [ host ] function. Is this fine?