I need to use 3d and 2d matrices in my code. I have them in form of vectors. I don’t know if it’s possible to copy them as vector to GPU and use them?
or since they have different random sizes in different dimension , if I want to change them to arrays I need to keep the size of each dimension. for example the 3D matrix in two matrices of 2D and 1D.
what is the efficient way of storing a 3D matrix with of course sizes for each dimension?
You can get the pointer to the array using vector.front().
Type *dev_ptr;
vector<Type> matrix;
int size = matrix.size() * sizeof(Type);
cudaMalloc((void**)&dev_ptr, size);
cudaMemcpy(dev_ptr, matrix.front(), size, cudaMemcpyHostToDevice);
But seriously, you shouldn’t use vector to do this unless the size of a specific matrix could change during runtime, which I believe is not what you need.
Are you reading from text files? Better do it with binary files; that’s much easier and faster. Of course, if you want the data on your GPU to be stored linearly, there’s nothing you’ll need to do apart from the direct copying shown above. I believe this would be the case for you, if your calculations on those matrices aren’t exactly peculiar.
and about using vector, I thought that’s clean. if I want to use ***p for my matrix and then keep their sizes somewhere, and copying all to gpu. I thought it’s not a good idea.
and I’m reading from text, I dont know what is binary file. if it influences only the first loading time, It’s not really a big deal now.