Hi,
I’m currentyly trying to pass a 2d array to cuda with CudaMalloc pitch and CudaMemcpy2D.The only value i get is pointer and i don’t understand why?
This is an exemple of my code:
double** busdata;
double** linedata;
int i_bus=4;
int j_bus=10;
int i_line=4;
int j_line=6;
// We initializa the Host matrice
try{
busdata=new(double*[i_bus]);
for(int i=0; i<i_bus;i++){
busdata[i]=new(double[j_bus]);
}
linedata=new(double*[i_line]);
for(int i=0;i<i_line;i++){
linedata[i]=new(double[j_line]);
}
}catch(std::bad_alloc& ba){
std::cerr << "bad_alloc caught: " << ba.what() << '\n';
}
size_t bus_pitch;
size_t line_pitch;
double* device_busdata;
double* device_linedata;
//Here I allocate the device matrice
cudaStatus =cudaMallocPitch(&device_linedata,&line_pitch,j_line*sizeof(double),i_line);
if(cudaStatus!=cudaSuccess){
fprintf(stderr,"cudaMalloc failed.");
goto Error;
}
cudaStatus =cudaMallocPitch(&device_busdata,&bus_pitch,j_bus*sizeof(double),i_bus);
if(cudaStatus!=cudaSuccess){
fprintf(stderr,"cudaMalloc failed.");
goto Error;
}
//Copy of the data from the CPU to the GPU
cudaStatus=cudaMemcpy2D(device_busdata,bus_pitch,busdata,j_bus*sizeof(double),j_bus*sizeof(double),i_bus,cudaMemcpyHostToDevice);
if(cudaStatus!=cudaSuccess){
fprintf(stderr,"cudaMemcpy failed.");
goto Error;
}
cudaStatus=cudaMemcpy2D(device_linedata,line_pitch,linedata,j_line*sizeof(double),j_line*sizeof(double),i_line,cudaMemcpyHostToDevice);
if(cudaStatus!=cudaSuccess){
fprintf(stderr,"cudaMemcpy failed.");
goto Error;
}
That’s how i allocate and send the data in the GPU. But when i try to use it with this code:
__global__ void ComputeN(double* busdata, int buspitch,int* npq, double* Pq ){
int tid= blockDim.x*blockIdx.x+threadIdx.x;
double* row= (double*) ((char*) busdata+tid*buspitch);
double type=roundf(row[1]);
if(type==3){
atomicAdd(npq,1);
Pq[*npq]=type;
}
}
I always get bad results like 3.83797400846176e-270. I supposed it’s a memory address and not the data i’ve copied.
I know there is a lot of subject on this theme like this one :https://devtalk.nvidia.com/default/topic/521887/cudamallocpitch-cudamemcpy2d-want-to-check-if-the-copy-of-2d-data-between-host-and-dev-is-work/
But I don’t even know why my value don’t go to the GPU…
I’m using a GTX 860 M whith Cuda 7.0
Thank you in advance