0

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)

Gigo
  • 3,188
  • 3
  • 29
  • 40

1 Answers1

0

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..

Gigo
  • 3,188
  • 3
  • 29
  • 40
  • JavaCL behaves in a similiar way. If the last line does not end with a line feed, the compilation aborts. – Christian Apr 11 '15 at 15:50