OpenCL:内核中的预期标识符
我在Windows7上运行以下内核,64位,采用Intel CPU和HD图形 对于以下代码,我通过OpenCL:内核中的预期标识符,opencl,Opencl,我在Windows7上运行以下内核,64位,采用Intel CPU和HD图形 对于以下代码,我通过clGetProgramBuildInfo得到非常奇怪的错误报告: #define BLOCK_SIZE 256 __kernel void reduce4(__global uint* input, __global uint* output, __local uint* sdata) { unsigned int tid = get_local_id(0); unsigne
clGetProgramBuildInfo
得到非常奇怪的错误报告:
#define BLOCK_SIZE 256
__kernel void reduce4(__global uint* input, __global uint* output, __local uint* sdata)
{
unsigned int tid = get_local_id(0);
unsigned int bid = get_group_id(0);
unsigned int gid = get_global_id(0);
unsigned int blockSize = get_local_size(0);
unsigned int index = bid*(BLOCK_SIZE*2) + tid;
sdata[tid] = input[index] + input[index+BLOCK_SIZE];
barrier(CLK_LOCAL_MEM_FENCE);
for(unsigned int s = BLOCK_SIZE/2; s > 64 ; s >>= 1) {
// Unrolling the last wavefront and we cut 7 iterations of this
// for-loop while we practice wavefront-programming
if(tid < s)
{
sdata[tid] += sdata[tid + s];
}
barrier(CLK_LOCAL_MEM_FENCE);
}
if (tid < 64) {
if (blockSize >= 128) sdata[tid] += sdata[tid + 64];
if (blockSize >= 64) sdata[tid] += sdata[tid + 32];
if (blockSize >= 32) sdata[tid] += sdata[tid + 16];
if (blockSize >= 16) sdata[tid] += sdata[tid + 8];
if (blockSize >= 8) sdata[tid] += sdata[tid + 4];
if (blockSize >= 4) sdata[tid] += sdata[tid + 2];
if (blockSize >= 2) sdata[tid] += sdata[tid + 1];
}
// write result for this block to global mem
if(tid == 0)
{
output[bid] = sdata[0];
}
}
这是最后一行,我把}。这里怎么了
更新:
This is how I am reading the kernel file:
int offset = 0;
for(int i = 0; i < numOfDevices; ++i, ++offset ) {
/* Load the two source files into temporary datastores */
const char *file_names[] = {"SimpleOptimizations.cl"};
const int NUMBER_OF_FILES = 1;
char* buffer[NUMBER_OF_FILES];
size_t sizes[NUMBER_OF_FILES];
loadProgramSource(file_names, NUMBER_OF_FILES, buffer, sizes);
/* Create the OpenCL program object */
program = clCreateProgramWithSource(context, NUMBER_OF_FILES, (const char**)buffer, sizes, &error);
if(error != CL_SUCCESS) {
perror("Can't create the OpenCL program object");
exit(1);
}
这是我读取内核文件的方式:
整数偏移=0;
对于(int i=0;i
loadProgramSource的定义
void loadProgramSource(const char** files,
size_t length,
char** buffer,
size_t* sizes) {
/* Read each source file (*.cl) and store the contents into a temporary datastore */
for(size_t i=0; i < length; i++) {
FILE* file = fopen(files[i], "r");
if(file == NULL) {
perror("Couldn't read the program file");
exit(1);
}
fseek(file, 0, SEEK_END);
sizes[i] = ftell(file);
rewind(file); // reset the file pointer so that 'fread' reads from the front
buffer[i] = (char*)malloc(sizes[i]+1);
buffer[i][sizes[i]] = '\0';
fread(buffer[i], sizeof(char), sizes[i], file);
fclose(file);
}
}
void loadProgramSource(常量字符**文件,
大小和长度,
字符**缓冲区,
尺寸(t*尺寸){
/*读取每个源文件(*.cl)并将内容存储到临时数据存储中*/
对于(大小i=0;i
我认为这是Windows处理使用fopen()
打开的文本文件的方式的问题。如果您查看,它表明如果您仅使用“r”打开文件
作为模式字符串,行尾会发生一些转换。这意味着您查询的文件大小可能与fread()
读取的数据量不匹配
要解决此问题,只需更改模式字符串,以指示您希望将文件作为二进制数据读取(即,无任何烦人的翻译):
如果您正在从文件加载内核代码,并且没有正确地终止缓冲区,则经常会发生这种情况。您能告诉我们您是如何做到的吗?@jprice请查看我的updateOK,但是
loadProgramSource
?这是这些错误通常出现的地方。@jprice您能建议一种方法来检查其中的内容吗?我知道ght您可能已经编写了该函数。它从何而来-某个库或实用程序头?您是真正的MVP。我被这个问题困扰了一整天,并尝试了所有愚蠢的答案。多亏了您,问题才得以解决。是的,肯定是文件大小的问题。。。。。。。。。。。。。。
void loadProgramSource(const char** files,
size_t length,
char** buffer,
size_t* sizes) {
/* Read each source file (*.cl) and store the contents into a temporary datastore */
for(size_t i=0; i < length; i++) {
FILE* file = fopen(files[i], "r");
if(file == NULL) {
perror("Couldn't read the program file");
exit(1);
}
fseek(file, 0, SEEK_END);
sizes[i] = ftell(file);
rewind(file); // reset the file pointer so that 'fread' reads from the front
buffer[i] = (char*)malloc(sizes[i]+1);
buffer[i][sizes[i]] = '\0';
fread(buffer[i], sizeof(char), sizes[i], file);
fclose(file);
}
}
FILE* file = fopen(files[i], "rb");