我有一个CUDA内核,我正在将其编译为cubin文件,没有任何特殊的标志:
nvcc text.cu -cubin
编译成功,但是出现以下信息:
警告: 无法确定指针指向,假定为全局内存空间
并且引用了某个临时cpp文件中的一行代码。我可以通过注释掉一些对我来说毫无意义的看似随意的代码来使其正常工作。
以下是内核代码:
__global__ void string_search(char** texts, int* lengths, char* symbol, int* matches, int symbolLength)
{
int localMatches = 0;
int blockId = blockIdx.x + blockIdx.y * gridDim.x;
int threadId = threadIdx.x + threadIdx.y * blockDim.x;
int blockThreads = blockDim.x * blockDim.y;
__shared__ int localMatchCounts[32];
bool breaking = false;
for(int i = 0; i < (lengths[blockId] - (symbolLength - 1)); i += blockThreads)
{
if(texts[blockId][i] == symbol[0])
{
for(int j = 1; j < symbolLength; j++)
{
if(texts[blockId][i + j] != symbol[j])
{
breaking = true;
break;
}
}
if (breaking) continue;
localMatches++;
}
}
localMatchCounts[threadId] = localMatches;
__syncthreads();
if(threadId == 0)
{
int sum = 0;
for(int i = 0; i < 32; i++)
{
sum += localMatchCounts[i];
}
matches[blockId] = sum;
}
}
如果我替换这行代码
localMatchCounts[threadId] = localMatches;
在第一个for循环中加入这行代码后:
localMatchCounts[threadId] = 5;
代码编译没有任何提示。通过在上面的循环中注释掉看似随机的部分也可以实现这一点。我还尝试将本地内存数组替换为普通数组,但没有效果。有人能告诉我问题出在哪里吗?
系统是Vista 64位,如果有用的话。
编辑:我修复了代码,使其实际工作,虽然它仍然会产生编译器提示。至少在正确性方面(可能会影响性能),警告似乎不是问题。