Unrecognized Token during Kernel Compilation

Hi

I’m trying to compile a kernel that I’ve written myself from scratch. For the host program to invoke the compilation process, I used the source code from Matthew Scarpino’s book in chapter 2, “program_build.” While the original version compiles both original kernels fine, I get a whole series of “unrecognized token” errors on the same line until it gives up after 100 errors.

Any clues to what this could be?

I’m using C in Visual Studio 2008
I was using AMD Catalyst 12.4 and have updated to 12.8.
I was using the beta version of the SDK (I was running a 4850). However, I’ve just upgraded and updated to 2.7.923.1
The problem persists.

Last 2 lines of my code are:

}


The brace is line 279, the line below (line 280) exists but there’s nothing there, not even a space. It exists only because there’s a carriage return after the brace in line 279.

The errors I’m getting are:

C:\Users\user\Documents\Visual Studio 2008\Projects\myprog\x64\Debug>myprog.exe
"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------
  ^

"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error: expected a
          declaration
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------
  ^

"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------
   ^

"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------
    ^


<--------- SNIP --------->



"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------

                  ^

"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------

                   ^

"C:\Users\user\AppData\Local\Temp\OCLB12B.tmp.cl", line 280: error:
          unrecognized token
  ------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------

                    ^

Error limit reached.
100 errors detected in the compilation of "C:\Users\user\AppData\Local\Temp\OCLB
12B.tmp.cl".
Compilation terminated.

Internal error: clc compiler invocation failed.

Ok, problem solved.

As I was saying, I was using source code from Matthew Scarpino’s book in chapter 2, “program_build” that reads in a .cl file for compilation. There appears to be a bug in this source code in the line:

      program_handle = fopen(file_name[i], "r");

Further investigation says about ftell (which is used a few lines further) from http://www.cplusplus.com/reference/clibrary/cstdio/ftell/
Returns the current value of the position indicator of the stream.
For binary streams, the value returned corresponds to the number of bytes from the beginning of the file.
For text streams, the value is not guaranteed to be the exact number of bytes from the beginning of the file, but the value returned can still be used to restore the position indicator to this position using fseek.

Therefore, changing this line to:

      program_handle = fopen(file_name[i], "rb");

solves the problem.

So not an OpenCL problem after all, oh well. :oops: