I did search for an answer to this on the forums but didn’t find one, here goes:
When I try to use cudaMemcpy everything compiles fine, but in debug mode I notice that it isnt actually copying from the host to device, here is the relevant section of code:
const int max_particles = 1000;
int main(){
int a = 256;
struct element{
float x[max_particles];
float p_x[max_particles];
} particle; //The struct object for the elements of particles is called particle
/*
Here be a section of code which reads values into particle.x and particle.p_x
*/
size_t size = a * sizeof(float); //Determine amount of memory required for each variable
//Create memory on the Host and assign pointers for each variable
float* host_particle_x = (float*)malloc(size);
float* host_particle_p_x = (float*)malloc(size);
cout << "Allocating host memory and initialising...\n" << endl;
//Initialise Host pointers with the determined variables
host_particle_x = particle.x;
host_particle_p_x = particle.p_x;
//Create variables for the device
float* device_particle_x;
float* device_particle_p_x;
cout << "Allocating Device memory..." << endl;
//Allocate memory for the device variables
cutilSafeCall(cudaMalloc((void**)&device_particle_x, size));
cutilSafeCall(cudaMalloc((void**)&device_particle_p_x, size));
cout << "Copying Host memory to Device memory..." << endl;
//Copy the variables from the host memory to the device memory
cutilSafeCall(cudaMemcpy(device_particle_x, host_particle_x, size, cudaMemcpyHostToDevice));
cutilSafeCall(cudaMemcpy(device_particle_p_x, host_particle_p_x, size, cudaMemcpyHostToDevice));