2015-04-23 23 views
-1

我在主机上执行以下代码时遇到问题,不确定我要出错的位置。我的理解是我需要分配足够的内存来存储设备上的textLength大小的textData内容,我使用sizeof(char)* textLength malloc来给我足够的空间,然后使用cudaMemcpy将所有的从textData到设备上分配的空间的值。我的异常读取“访问冲突读取位置0x000000000501f80400”,这是我的cuTextArray在设备上的内存地址。cudaMalloc运行时错误

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结合纹理的代码片断阵列崩溃:

enter image description here

+3

其中3个操作('cudaMalloc','cudaMemcpy','cudaBindTextureToArray')实际上失败,异常

//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)); 

查找值?请提供[MCVE](http://stackoverflow.com/help/mcve)。 –

+0

行为真的没有什么帮助,我在cudaMalloc调用中设置了一个断点,运行程序时断点转移到了cudaMemcpy调用。按f10一次将我带到cuda_runtime.h到cudaMemcpyToSymbolAsync,再次按f10将导致异常 – Oliver

+2

请提供一个资源链接,其中说明使用'cudaArray'的限制为8kB。如果它也涉及'cudaMemcpyToArray',那么你应该清楚地说明它。另外,如果极限确实是_is_ 8kB并且您想要分配更多,那么您可能会滥用'cudaArray' ... –

回答

0

那么事实证明,我可以通过使用标准的字符指针与基准和不同的结合调用得到它的工作离整个阵列废话了。非常简单的东西,有点奇怪,它不容易回答。使用

tex1Dfetch(texTextRef,k+index)