OpenCL: Expected identifier in kernel


I am running the following kernel on windows 7, 64 bit, with Intel CPU and HD graphics.

I get very strange error reporting by clGetProgramBuildInfo for the following code:

#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]; } }

It always says:

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

this is for the last line, where I have put }. What is wrong here?


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

<strong>Definition of loadProgramSource</strong>

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


I believe this is an issue with the way the Windows deals with text files opened with fopen(). If you take a look at the <a href="http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx" rel="nofollow">MSDN page for fopen()</a>, it indicates that if you open a file with just "r" as the mode string, some translations will happen with regards to line-endings. This means that the size of the file you query may not match the amount of data read by fread().

To solve this, simply change the mode string to indicate that you wish to read the file as binary data (i.e. without any pesky translations):

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


  • Populating H2 database with Spring and jdbc DataSourceTransactionManager
  • psutil error on macos
  • numpy.ndarray objects not garbage collected
  • How to compile unsafe code in MonoDevelop 2.4
  • “Yesod devel” fails with fromJust in devel.hs
  • Can't use openlayers-3 with webpack
  • Python: how to split and return a list from a function to avoid memory error
  • Allocating a 2D contiguous array within a function
  • Refactoring advice: maps to POJOs
  • XNU incudes in Kext
  • SQL query to group by maximal sets of a column having inner consecutive distances below a threshold
  • Responsive left sidebar open close
  • can variables be set randomly when declaring them again?
  • Prevent page break in text block with iText, XMLWorker
  • C# - Most efficient way to iterate through multiple arrays/list
  • C++ friend class std::vector
  • Updating Dojo provide
  • SyntaxError: (irb):26: both block arg and actual block given
  • Defined variables not working in javascript files when I use getScript
  • How can I display the parent menu item's description using Wordpress walkers?
  • Is it possible to open regedit and navigate to straight to a specific key using process.start?
  • Assign variable to the value in HTML
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Azure Cloud Service Web Role web pages do not load
  • How to add date and time under each post in guestbook in google app engine
  • php design question - will a Helper help here?
  • SQL merge duplicate rows and join values that are different
  • AngularJs get employee from factory
  • coudnt use logback because of log4j
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal