Java Alternative Algorithm does not work for arbitrary NDRanges #142
Aparapi "falls back" to a "Java Alternative Algorithm" (JAA) in cases where the Java byte code cannot be translated to OpenCL code. The JAA, however, only works if the local size of the NDRange is explicitly specified, even in those cases, where the derived value for the local size is the same as the explicitly specified value. The following example illustrates the problem:
public class JAATest {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5, 6, 7};
Range r = Range.create(7);
System.out.println(r); // prints "global:7 local:(derived)7"
new Kernel() {
@Override public void run() {
int i = getGlobalId();
System.out.println(); // induces fallback
a[i] = a[i] * 2;
}
}.execute(r);
System.out.println(java.util.Arrays.toString(a));
}
}
Execution yields the following incorrect output:
[1, 2, 3, 4, 5, 6, 7]
The version with an explicitly specified local size
public class JAATest {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 5, 6, 7};
Range r = Range.create(7, 7);
System.out.println(r); // prints "global:7 local:7"
new Kernel() {
@Override public void run() {
int i = getGlobalId();
System.out.println(); // induces fallback
a[i] = a[i] * 2;
}
}.execute(r);
System.out.println(java.util.Arrays.toString(a));
}
}
delivers the correct result:
[2, 4, 6, 8, 10, 12, 14]