aparapi
aparapi copied to clipboard
[BOUNTY $25] OpenCL keywords are not escaped during code generation
If the Java kernel contains a variable name that is legal in Java but happens to be an OpenCL keyword the code generation will fail. OpenCL keywords should be somehow escaped on mangled in the output code.
Consider the following test:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.aparapi.Kernel;
import com.aparapi.Range;
public class Issue54Test
{
@Test
public void passingTest()
{
final int SIZE = 16;
final float[] RESULT = new float[] {1};
Kernel kernel = new Kernel()
{
@Local final float[] localArray = new float[SIZE*SIZE];
@Override
public void run()
{
int row = getGlobalId(0);
int column = getGlobalId(1);
localArray[row + column*SIZE] = row + column;
localBarrier();
float value = 0;
for (int x = 0; x < SIZE; x++)
{
for (int y = 0; y < SIZE; y++)
{
value += localArray[x + y*SIZE];
}
}
RESULT[0] = value;
}
};
kernel.execute(Range.create2D(SIZE, SIZE, SIZE, SIZE));
assertEquals(3840, RESULT[0], 1E-6F);
}
@Test
public void failingTest()
{
final int SIZE = 16;
final float[] RESULT = new float[] {1};
Kernel kernel = new Kernel()
{
@Local final float[] local = new float[SIZE*SIZE];
@Override
public void run()
{
int row = getGlobalId(0);
int column = getGlobalId(1);
local[row + column*SIZE] = row + column;
localBarrier();
float value = 0;
for (int x = 0; x < SIZE; x++)
{
for (int y = 0; y < SIZE; y++)
{
value += local[x + y*SIZE];
}
}
RESULT[0] = value;
}
};
kernel.execute(Range.create2D(SIZE, SIZE, SIZE, SIZE));
assertEquals(3840, RESULT[0], 1E-6F);
}
}
Running this test will cause the following runtime error:
clBuildProgram failed
************************************************
<program source>:2:24: error: expected member name or ';' after declaration specifiers
__local float *local;
~~~~~~~~~~~~~ ^
<program source>:6:5: warning: no previous prototype for function 'get_pass_id'
int get_pass_id(This *this){
^
<program source>:10:24: error: parameter may not be qualified with an address space
__local float *local,
^
<program source>:10:24: error: parameter name omitted
<program source>:16:10: error: expected identifier
this->local = local;
^
<program source>:22:13: error: expected identifier
this->local[row + (column * 16)] = (float)(row + column);
^
<program source>:27:35: error: expected identifier
value = value + this->local[(x + (y * 16))];
^
************************************************
@raner Thanks so much, ill review this and see what I can do.
@raner Sorry there hasnt been much movement on this. I'm going to assign a bounty to it and try to get someone on it. If we can't find anyone I'll investigate this myself. Have you had any progress since it was reported?