我在主机上执行以下代码时遇到问题,我不知道哪里出错了。我的理解是我需要分配足够的内存来存储textData的内容,这是textLength的大小在设备上,我malloc的sizeof(char)* textLength应该给我足够的空间,然后我用cudaMemcpy来复制所有的从textData到设备上分配的空间的值。我的异常读取"访问冲突读取位置0x000000000501f80400"这是我的cuTextArray在设备上的内存地址。
texture<char, cudaTextureType1D, cudaReadModeElementType> textDataRef;
int textLength = 10000000
cudaArray *cuTextArray;
checkCudaErrors (cudaMalloc(&cuTextArray, sizeof(char)*textLength));
checkCudaErrors(cudaMemcpy(cuTextArray, textData, sizeof(char)*textLength, cudaMemcpyHostToDevice));
checkCudaErrors(cudaBindTextureToArray(textDataRef, cuTextArray, textDataRef.channelDesc));
我无法使用cudaMallocArray,因为我的数据对于缓冲区来说太大了 - 最多8192字节
此处似乎在将纹理绑定到cuda_runtime.h中的代码数组片段时崩溃:
答案 0 :(得分:0)
事实证明,通过使用带引用的标准字符指针和不同的绑定调用,我可以远离整个数组废话。非常简单的东西,奇怪的是它不容易回答。
//Allocate Memory
checkCudaErrors( cudaMalloc(&d_textData, sizeof(char) * textLength) );
//Copy Host To Device
checkCudaErrors( cudaMemcpy(d_textData, textData, sizeof(char)* textLength, cudaMemcpyHostToDevice));
//Bind reference to block of memory
checkCudaErrors ( cudaBindTexture(NULL,&texTextRef,d_textData,&texTextRef.channelDesc, sizeof(char) * textLength ) );
使用
查找值tex1Dfetch(texTextRef,k+index)