My goal is to 'fill' a class that resides in device memory from the host. Since that class contains a pointer to data, my understanding is that, after allocating the class itself, I need to allocate the space for it seperately and then change the pointer of the device class to the now allocated pointer. I've tried to orient my solution according to this post which, in my eyes, seems to do exactly what I want, however I am doing something wrong and thus would like help.
I have the follwing setup of classes and relevant code:
class A {
public:
HostB host_B;
B *dev_B;
void moveBToGPU();
}
class HostB {
public:
vector<int> info;
}
class B {
public:
int *info;
}
void A::moveBToGPU() {
cudaMalloc(this->dev_B, sizeof(B));
int* dev_data;
cudaMalloc(&dev_data, sizeof(int) * host_B->info.size());
cudaMemcpy(&this->dev_B->info, &dev_data, sizeof(int *), cudaMemcpyHostToDevice); //Not sure if correct
//I would like to do the following, but that results in a segfault
cudaMemcpy(this->dev_B->info, host_B->info.data(), host_B->info.size(), cudaMemcpyHostToDevice);
//As expected, this works
cudaMemcpy(dev_data, host_B->info.data(), host_B->info.size(), cudaMemcpyHostToDevice;