【发布时间】:2010-09-22 07:52:55
【问题描述】:
我有一个 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 位,物有所值。
编辑:我修复了代码,使其实际工作,尽管它仍然会产生编译器通知。警告似乎不是问题,至少在正确性方面(它可能会影响性能)。
【问题讨论】: