hi.
I’m studying cuda first time.
I have some problem about cudaMemcpyToArray and texture declar…
after compiling this code…
I think “result_dz” is same value whit “dx”…but “dz” have still initial value ‘0’…
(dx->d_dx->cuArray->d_dz->dx)
do you know what’s the wrong???
tnank you for your help!!!
/////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define IE 40
#define JE 40
#define KE 40
#define nsteps 3 // num of iteration
texture<float,1>texRef;
int main(int argc, char* argv){
int i;
int numBlock=40; // define number of block
int numThread=5; // define number of thread
float *d_dx,*d_dz; // device variable
size_t memSize=(IE*JE*KE)*sizeof(float);
// host mem alloc
float *dx =(float*)malloc(sizeof(float)*(IE*JE*KE));
float *dz =(float*)malloc(sizeof(float)*(IE*JE*KE));
// device mem alloc
cudaMalloc((void**)&d_dx,memSize);
cudaMalloc((void**)&d_dz,memSize);
// initial the array
for (i=0;i< 20 ;i++){
dx[i]=(float)i;
dz[i]=0.0;
printf("dx[%d] : %5.2f ", i, dx[i]);
printf("dz[%d] : %5.2f \n", i, dz[i]);
}
//allocate array for using texture memory
cudaArray *cuArray=0;
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float>();
cudaMallocArray(&cuArray, &channelDesc, memSize, 0);
//block, thread dec
dim3 dimGrid(numBlock);
dim3 dimBlock(numThread);
cudaMemcpy(d_dx,dx,memSize,cudaMemcpyHostToDevice);
cudaMemcpyToArray(cuArray,0,0, d_dx, memSize, cudaMemcpyDeviceToDevice);
cudaMemcpyFromArray(d_dz,cuArray,0,0, memSize, cudaMemcpyDeviceToHost);
cudaMemcpy(dz,d_dz,memSize,cudaMemcpyDeviceToHost);
for (i=0;i< 20 ;i++){
printf("result_dz[%d] : %5.2f \n ", i, dz[i]);
}
// device mem free
cudaFree(d_dx);
cudaFree(d_dz);
cudaFreeArray(cuArray);
// host mem free
free(dx);
free(dz);
return 0;
}
//////////////////////////////////////
p.s) I wnat to use 1D texture array…
texture<float,1>texRef
is it right???
thanks again!!!