I am trying to use simple 3D array for Halton number generation. The algorithm is 100% correct coz I tried the same without CUDA
So in the statement row[j] = h, the h values generates random numbers
But when I check it in host memory there is no data and all it prints is 0.
So my Issue is how to access it. I don’t have much idea about cudaMemcpy3D , so if possible correct the code rather than suggesting I use cudaMemcpy3D External Image
Or if any other mistake lemme know
thanks
int width =50,height=3,depth=10;
global void random3dGen(cudaPitchedPtr devPitchedPtr);
int main()
{
//host code
cudaExtent extent = make_cudaExtent(width * sizeof(float), height, depth);
cudaPitchedPtr devPitchedPtr;
char* devPtr = (char*)devPitchedPtr2.ptr;
size_t pitch = devPitchedPtr2.pitch;
size_t slicePitch = pitch * 3;
char* slice = devPtr + 1 * slicePitch;
float* row =(float*)(slice + 2 * pitch);
printf("\n");
for(int i=0;i<10;i++)
printf(“%f\n”,row[i]);
return 0;
}
global void random3dGen(cudaPitchedPtr devPitchedPtr)
{
long n1,i;
float h,ib;
float n0;
//Simple Halton Number Generator
float N = 16.0;//seeder - Animesh
int components = 3;
int primearray = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229};
char* devPtr =(char*)devPitchedPtr.ptr;
size_t pitch = devPitchedPtr.pitch;
size_t slicePitch = pitch * 3;
int b;
char* slice = devPtr + (threadIdx.x % 10) * slicePitch;
for(int p=0;p<components;p++)
{
float* row =(float*)(slice + p * pitch);
n0 = N++;
for(int j=0;j<50;j++)
{
b = primearray[j];
n0 = N;
h = 0;
ib = (float)(1.0/b);
while(n0>0)
{
n1 = (int)(n0/b);
i = n0 - n1*b;
h = h + ib*i;
ib = ib/b;
n0 = n1;
}
row[j] = h;
// printf("%f",row[j]);
}
}
N = N + 2;
}