OpenCL:内核中的预期标识符

时间:2014-07-26 12:33:51

标签: opencl

我在Windows 7,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);
    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];
     }
}

它总是说:

Compilation started
:38:2: error: expected identifier or '('
Compilation failed

这是最后一行,我放的地方}。这有什么不对?

更新

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

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

1 个答案:

答案 0 :(得分:2)

我认为这是Windows处理使用fopen()打开的文本文件的方式的问题。如果您查看MSDN page for fopen(),则表示如果您打开仅使用"r"作为模式字符串的文件,则会在行结尾方面进行一些翻译。这意味着您查询的文件大小可能与fread()读取的数据量不匹配。

要解决此问题,只需更改模式字符串即表示您希望将文件读取为二进制数据(即没有任何讨厌的翻译):

FILE* file = fopen(files[i], "rb");