I am trying to do the following:
typedef struct {
float *d;
int size;
} data;
data mydata;
mydata.size=1000;
CUDA_SAFE_CALL(cudaMalloc((void **) mydata.d, sizeof(float)*mydata.size));
CUDA_SAFE_CALL(cudaFree(mydata.d));
but on cudafree I get the invalid device pointer. can anyone help me with this please???
Tigga
November 6, 2009, 2:30pm
2
CUDA_SAFE_CALL(cudaMalloc((void **) mydata.d, sizeof(float)*mydata.size));
should be
CUDA_SAFE_CALL(cudaMalloc((void **)&mydata.d, sizeof(float)*mydata.size));
mandana
November 12, 2009, 2:47pm
3
CUDA_SAFE_CALL(cudaMalloc((void **) mydata.d, sizeof(float)*mydata.size));
should be
CUDA_SAFE_CALL(cudaMalloc((void **)&mydata.d, sizeof(float)*mydata.size));
Thanks for your answere, what if I wanna do the following, define the struct as a pointer:
typedef struct {
float *d;
int size;
} data;
data *mydata;
mydata->size=1000;
CUDA_SAFE_CALL(cudaMalloc((void **) mydata->d, sizeof(float)*mydata.size));
CUDA_SAFE_CALL(cudaFree(mydata.d));
I get the error: expression must have class type error on cudaMalloc.
How can I solve this???
LSChien
November 12, 2009, 3:03pm
4
data *mydata;
mydata->size=1000;
CUDA_SAFE_CALL(cudaMalloc((void **) &(mydata->d), sizeof(float)*mydata->size));
CUDA_SAFE_CALL(cudaFree(mydata->d));
Tigga
November 12, 2009, 3:06pm
5
This is a C problem not a CUDA problem.
‘mydata.size’ is incorrect. It should be ‘mydata->size’.
You’ve also got exactly the same bug as last time - (void **) mydata->d is incorrect and should be (void **)&mydata->d.
It might be an idea to learn a bit more C before diving into CUDA.
mandana
November 12, 2009, 3:13pm
6
This is a C problem not a CUDA problem.
‘mydata.size’ is incorrect. It should be ‘mydata->size’.
You’ve also got exactly the same bug as last time - (void **) mydata->d is incorrect and should be (void **)&mydata->d.
It might be an idea to learn a bit more C before diving into CUDA.
oooops, I made a mistake writing the code here. I have actually put the addess sign for the malloc. my mistake was accessing the size. forgot to replace it with “->”. thanks.