589
社区成员




texture <unsigned short, 3, cudaReadModeElementType> tex;
cudaArray *d_volumeArray = NULL;
//随便写个空的kernel
__global__ void kernel()
{
unsigned int tid = threadIdx.x;
}
void initTex(unsigned short *pPrj, cudaExtent extent)
{
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned short>();
cutilSafeCall( cudaMalloc3DArray(&d_volumeArray, &channelDesc, extent) );
// copy data to 3D array
cudaMemcpy3DParms copyParams = {0};
copyParams.srcPtr = make_cudaPitchedPtr((void*)pPrj, extent.width*sizeof(unsigned short), extent.width, extent.height);
copyParams.dstArray = d_volumeArray;
copyParams.extent = extent;
copyParams.kind = cudaMemcpyHostToDevice;
cutilSafeCall( cudaMemcpy3D(©Params) );
// set texture parameters
tex.normalized = false; // access with normalized texture coordinates
tex.filterMode = cudaFilterModeLinear; // linear interpolation
tex.addressMode[0] = cudaAddressModeClamp; // wrap texture coordinates
tex.addressMode[1] = cudaAddressModeClamp;
tex.addressMode[2] = cudaAddressModeClamp;
// bind array to 3D texture
cutilSafeCall(cudaBindTextureToArray(tex, d_volumeArray, channelDesc));
//随便执行一个空的kernel就在输出中看到cudaError内存错误
kernel<<<100, 256>>>();
}
//main中调用部分
int main()
{
//....
//载入数据
cudaExtent extent;
extent.width = 512;
extent.height = 512;
extent.depth = 4;
int volumeSize = extent.width * extent.height * extent.depth;
unsigned short *pPrj = (unsigned short*)malloc( sizeof(unsigned short) * volumeSize);
//从文件中读入数据岛pPrj中....
initTex(pPrj, extent);//使用cudaGetLastError或者是cudaThreadSynchronize都没能捕捉到错误
}