I've looked all around this site and others, and nothing has worked. I'm resorting to posting a question for my specific case.
I have a bunch of matrices, and the goal is to use a kernel to let the GPU to do the same operation on all of them. I'm pretty sure I can get the kernel to work, but I can't get cudaMalloc / cudaMemcpy to work.
I have a pointer to a Matrix structure, which has a member called elements that points to some floats. I can do all the non-cuda mallocs just fine.
Thanks for any/all help.
Code:
typedef struct {
int width;
int height;
float* elements;
} Matrix;
int main void() {
int rows, cols, numMat = 2; // These are actually determined at run-time
Matrix* data = (Matrix*)malloc(numMat * sizeof(Matrix));
// ... Successfully read from file into "data" ...
Matrix* d_data;
cudaMalloc(&d_data, numMat*sizeof(Matrix));
for (int i=0; i<numMat; i++){
// The next line doesn't work
cudaMalloc(&(d_data[i].elements), rows*cols*sizeof(float));
// Don't know if this works
cudaMemcpy(d_data[i].elements, data[i].elements, rows*cols*sizeof(float)), cudaMemcpyHostToDevice);
}
// ... Do other things ...
}
Thanks!