Skip to content

Commit eab2fac

Browse files
committed
JavaCL Generator: add support for 3-components vectors (issue #497)
1 parent 7ad54c4 commit eab2fac

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

Generator/src/main/java/com/nativelibs4java/opencl/generator/JavaCLGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static class Conversion {
305305
"float", Float.TYPE, float[].class, Float.class,
306306
"bool", Boolean.TYPE, boolean[].class, Boolean.class
307307
};
308-
for (int arity : new int[] { 1, 2, 4, 8, 16 }) {
308+
for (int arity : new int[] { 1, 2, 3, 4, 8, 16 }) {
309309
String suffix = arity == 1 ? "" : arity +"";
310310
for (int i = 0; i < data.length; i += 4) {
311311
String rawType = (String)data[i];

JavaCL/src/test/java/com/nativelibs4java/opencl/generator/GeneratorTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@
1010
import org.bridj.Pointer;
1111
import org.junit.Test;
1212
import static org.junit.Assert.*;
13+
import org.junit.Before;
1314

1415
public class GeneratorTest {
15-
16+
CLContext context;
17+
CLQueue queue;
18+
Structs structs;
19+
20+
@Before
21+
public void setup() throws IOException {
22+
context = JavaCL.createBestContext();
23+
queue = context.createDefaultQueue();
24+
structs = new Structs(context);
25+
}
26+
1627
@Test
1728
public void testStructs() throws IOException {
18-
CLContext context = JavaCL.createBestContext();
19-
CLQueue queue = context.createDefaultQueue();
20-
21-
Structs structs = new Structs(context);
2229
Structs.S s = new Structs.S();
2330
Pointer<Structs.S> pS = Pointer.getPointer(s);
2431
CLBuffer<Structs.S> b = context.createBuffer(CLMem.Usage.InputOutput, pS);
@@ -36,4 +43,13 @@ public void testStructs() throws IOException {
3643
assertEquals(120, s.b());
3744

3845
}
46+
47+
@Test
48+
public void testFloat3() {
49+
float[] input = new float[] { 1, 2, 3 };
50+
CLBuffer<Float> outputBuffer = context.createFloatBuffer(CLMem.Usage.Output, 3);
51+
CLEvent e = structs.g(queue, input, outputBuffer, new int[] { 1 }, null);
52+
float[] output = outputBuffer.read(queue, e).getFloats();
53+
assertArrayEquals(input, output, 0.0f);
54+
}
3955
}

JavaCL/src/test/opencl/com/nativelibs4java/opencl/generator/Structs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ kernel void f(__global S *pS) {
66
pS->a = pS->a * 2 + 10;
77
pS->b = pS->b * 10 + 100;
88
}
9+
10+
kernel void g(float3 floats, __global float *out) {
11+
out[0] = floats.x;
12+
out[1] = floats.y;
13+
out[2] = floats.z;
14+
}

0 commit comments

Comments
 (0)