나는 cuda ....에서 tex2D로 배열을 나타내려고 노력 중이다. 디버깅을 한 후, 1 백만 개의 요소 중 19 개가 텍스처에 잘못 복사되었다는 것을 알았다. 배열, 나는 0 intstead 1 있어요. 난 당신의 코드에서 볼 수배열을 텍스처 표현으로 변환
void evolve_gpu(byte* h_in, byte* h_out)
{
//int SIZE = N * N * N * N * sizeof(float);
cudaEvent_t start, stop;
size_t d_in_pitch;
size_t d_out_pitch;
int len = 1002;
checkCudaErrors(cudaEventCreate(&start));
checkCudaErrors(cudaEventCreate(&stop));
// Allocate the device input image array
unsigned char *d_in = NULL;
unsigned char *d_out = NULL;
checkCudaErrors(cudaMallocPitch(&d_in, &d_in_pitch, sizeof(unsigned char)*len, len));
checkCudaErrors(cudaMallocPitch(&d_out, &d_out_pitch, sizeof(unsigned char)*len, len));
// Copy the host input image to the device memory
checkCudaErrors(cudaMemcpy2D(d_in, d_in_pitch, h_in, sizeof(unsigned char)*len
, sizeof(unsigned char)*len, len, cudaMemcpyHostToDevice));
/**************************** TEXTURE CONFIGURATION ******************************/
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypePitch2D;
resDesc.res.pitch2D.devPtr = d_in;
resDesc.res.pitch2D.pitchInBytes = d_in_pitch;
resDesc.res.pitch2D.width = len;
resDesc.res.pitch2D.height = len;
resDesc.res.pitch2D.desc = cudaCreateChannelDesc<unsigned char>();
cudaTextureDesc texDesc;
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
texDesc.normalizedCoords=false;
texDesc.addressMode[0]=cudaAddressModeBorder;
texDesc.addressMode[1]=cudaAddressModeBorder;
cudaTextureObject_t tex;
cudaCreateTextureObject(&tex, &resDesc, &texDesc, NULL);
/*********************************************************************************/
checkCudaErrors(cudaEventRecord(start, NULL));
// Launch the CUDA Kernel
dim3 block = dim3(THREADS_X, THREADS_Y);
dim3 grid = dim3((len+block.x-1)/block.x,(len+block.y-1)/block.y);//25*50
evolve_kernel<<<grid, block>>>(tex, d_out);
//******** kernel<<< number of blocks, number of threads, dynamic memory per block, associated stream >>> *******//
// Copy the device result to the host
checkCudaErrors(cudaMemcpy2D(h_out, d_out_pitch,
d_out, d_out_pitch,
sizeof(unsigned char)*len, len,
cudaMemcpyDeviceToHost));
for(int i=0;i<1002*1002;i++){
if(h_in[i] != h_out[i])
printf("i = %d\n",i);
}
checkCudaErrors(cudaGetLastError());
checkCudaErrors(cudaEventRecord(stop, NULL));
checkCudaErrors(cudaEventSynchronize(stop));
checkCudaErrors(cudaFree(d_in));
checkCudaErrors(cudaFree(d_out));
float msec = 0.f;
checkCudaErrors(cudaEventElapsedTime(&msec, start, stop));
printf("Basic version took: %f ms\n", msec);
}
SO [expects] //stackoverflow.com/help/mcve). 아무 것도 추가하거나 변경하지 않고 다른 사람이 복사, 붙여 넣기, 컴파일 및 실행할 수있는 완전한 코드를 제공하고 문제를 확인하는 것이 좋습니다. 데이터 세트를 작성하고 코드를 점검하여 보유하고있는 데이터 문제점을 설명하십시오. –