Hi guys,
I'm trying to copy my struct called Parameters from host to device. And the code looks like this.
#include
#include
#include <cuda_runtime.h>
#include
#include
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
typedef float dType;
using std::cout; using std::cin; using std::endl;
struct Parameters{
/* Map Dimensions */
unsigned int map_height;
unsigned int map_width;
unsigned int map_nCells;
/* Block types */
dType AIR ;
dType WALL;
dType WATER ;
/* Water properties */
// Max and min cell liquid values
dType MaxValue; //The normal, un-pressurized mass of a full water cell
dType MinValue; //Ignore cells that are almost dry
// Extra liquid a cell can store than the cell above it
dType MaxCompression;
// Lowest and highest amount of liquids allowed to flow per iteration
dType MinFlow;
dType MaxFlow;
// Adjusts flow speed (0.0 - 1.0)
dType FlowSpeed; //units of water moved out of one block to another, per timestep
};
global void printParameters(Parameters* parameters){
printf(“Device Parameters : \n”);
printf(“%f, %f, %f\n”, parameters->map_height, parameters->map_width, parameters->map_nCells);
}
void checkError(cudaError_t err){
if (err != cudaSuccess){
std::cout << cudaGetErrorString(err) << std::endl;
exit(-1);
}
}
int main(){
/* intializing Parameters on host and device */
Parameters *h_parameters = (Parameters *)malloc(sizeof(Parameters));
h_parameters->map_height = 10;
h_parameters->map_width = 10;
h_parameters->map_nCells = h_parameters->map_height * h_parameters->map_width;
h_parameters->AIR = 0.0;
h_parameters->WALL = 1.0;
h_parameters->WATER = 2.0;
h_parameters->MinValue = 0.005;
h_parameters->MaxCompression = 0.25;
h_parameters->MinFlow = 0.005;
h_parameters->MaxFlow = 4;
h_parameters->FlowSpeed = 1;
cout << "Host Parameters :\n";
cout << h_parameters->map_height << ", " << h_parameters->map_width << ", " << h_parameters->map_nCells << std::endl;
Parameters* d_parameters;
cudaMalloc((void**)&d_parameters, sizeof(Parameters));
checkError( cudaMemcpy(d_parameters, h_parameters, sizeof(Parameters), cudaMemcpyHostToDevice) );
printParameters<<<1,1>>>(d_parameters);
checkError(cudaPeekAtLastError());
checkError(cudaDeviceSynchronize());
return;
}
When I run my program. I get the following output.
nvcc -arch=sm_61 -std=c++11 main.cu -run
Host Parameters :
10, 10, 100
Device Parameters :
0.000000, 0.000000, 0.000000
As observed Parameters are not copied into device.
Can somebody tell me what the issue is ?