openclcloo

OpenCL compiler white-space problems


I'm trying to get started with OpenCL but came across weird behavior of the OpenCL compiler with respect to white-space and can't seem to find any documentation about that.

C-style single-line comments (// foo) immediately cause a meaningless build error: At end of source: error: expected a "}". Multi-line comments (/* bar */) seem to work fine.

Line breaks seem to get stripped without adding whitespace which can cause errors. This example will not compile because of that:

__kernel
void TestKernel() {}

line 1: error: identifier "__kernelvoid" is undefined

This may totally depend on my machine and/or configuration but can somebody confirm that these things should not be this way?

I am using OpenCL via Cloo from .net/C#. The driver is from AMD OpenCL 2.0 AMD-APP (1642.5)


Solution

  • I think I figured it out. I was doing this:

    var program = new ComputeProgram(context, File.ReadAllLines(filename));
    

    File.ReadAllLines() returns an array of strings without the line-break characters which is the root of the errors I was getting.

    Using File.ReadAllTest() instead fixed all the problems:

    var program = new ComputeProgram(context, File.ReadAllText(filename));
    

    But in my opinion some of the blame goes to either Cloo or the OpenCL API for accepting a string array but just concatenating it together..