aboutsummaryrefslogtreecommitdiffstats
path: root/test/com
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2011-07-07 23:32:28 +0200
committerMichael Bien <[email protected]>2011-07-07 23:32:28 +0200
commit4fe7110357d2631960e23861a3221489d313c467 (patch)
tree40f1ff4ddef2cd151e22b7d1c496ce3f6b4d9e76 /test/com
parent25b19e390a0a6a3cae8d129a579f16ffd5d4e2e5 (diff)
CLKernel utility methods for setting vector arguments with up to 4 elements + test.
Diffstat (limited to 'test/com')
-rw-r--r--test/com/jogamp/opencl/CLProgramTest.java74
-rw-r--r--test/com/jogamp/opencl/TestUtils.java21
2 files changed, 91 insertions, 4 deletions
diff --git a/test/com/jogamp/opencl/CLProgramTest.java b/test/com/jogamp/opencl/CLProgramTest.java
index d083c770..3c8ef8ba 100644
--- a/test/com/jogamp/opencl/CLProgramTest.java
+++ b/test/com/jogamp/opencl/CLProgramTest.java
@@ -28,6 +28,7 @@
package com.jogamp.opencl;
+import com.jogamp.common.nio.Buffers;
import com.jogamp.opencl.util.CLBuildConfiguration;
import com.jogamp.opencl.util.CLProgramConfiguration;
import com.jogamp.opencl.CLProgram.Status;
@@ -39,7 +40,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.nio.FloatBuffer;
import java.util.Map;
+import java.util.Random;
import java.util.concurrent.CountDownLatch;
import org.junit.Rule;
import org.junit.Test;
@@ -313,7 +316,76 @@ public class CLProgramTest {
context.release();
}
- }
+ }
+
+ @Test
+ public void kernelVectorArgsTest() {
+
+ String source =
+ "kernel void vector(global float * out,\n"
+ + " const float v1,\n"
+ + " const float2 v2,\n"
+ + "// const float3 v3,\n" // nv does not support float3
+ + " const float4 v4,\n"
+ + " const float8 v8) {\n"
+ + " out[0] = v1;\n"
+
+ + " out[1] = v2.x;\n"
+ + " out[2] = v2.y;\n"
+
+ + " out[3] = v4.x;\n"
+ + " out[4] = v4.y;\n"
+ + " out[5] = v4.z;\n"
+ + " out[6] = v4.w;\n"
+
+ + " out[ 7] = v8.s0;\n"
+ + " out[ 8] = v8.s1;\n"
+ + " out[ 9] = v8.s2;\n"
+ + " out[10] = v8.s3;\n"
+ + " out[11] = v8.s4;\n"
+ + " out[12] = v8.s5;\n"
+ + " out[13] = v8.s6;\n"
+ + " out[14] = v8.s7;\n"
+ + "}\n";
+
+ CLContext context = CLContext.create();
+
+ try{
+ CLProgram program = context.createProgram(source).build();
+ CLKernel kernel = program.createCLKernel("vector");
+
+ CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(15, CLBuffer.Mem.WRITE_ONLY);
+
+ final int seed = 7;
+ Random rnd = new Random(seed);
+
+ kernel.putArg(buffer);
+ kernel.putArg(rnd.nextFloat());
+ kernel.putArg(rnd.nextFloat(), rnd.nextFloat());
+// kernel.putArg(rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat()); // nv does not support float3
+ kernel.putArg(rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat());
+ kernel.putArg(TestUtils.fillBuffer(Buffers.newDirectFloatBuffer(8), seed));
+
+ CLCommandQueue queue = context.getMaxFlopsDevice().createCommandQueue();
+ queue.putTask(kernel).putReadBuffer(buffer, true);
+
+ FloatBuffer out = buffer.getBuffer();
+
+ rnd = new Random(seed);
+ for(int i = 0; i < 7; i++) {
+ assertEquals(rnd.nextFloat(), out.get(), 0.01f);
+ }
+
+ rnd = new Random(seed);
+ for(int i = 0; i < 8; i++) {
+ assertEquals(rnd.nextFloat(), out.get(), 0.01f);
+ }
+
+ }finally{
+ context.release();
+ }
+
+ }
@Test
public void createAllKernelsTest() {
diff --git a/test/com/jogamp/opencl/TestUtils.java b/test/com/jogamp/opencl/TestUtils.java
index bf1fd153..efe6855e 100644
--- a/test/com/jogamp/opencl/TestUtils.java
+++ b/test/com/jogamp/opencl/TestUtils.java
@@ -29,6 +29,7 @@
package com.jogamp.opencl;
import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
import java.util.Random;
import static java.lang.System.*;
@@ -44,7 +45,7 @@ public class TestUtils {
final static int NUM_ELEMENTS = 10000000;
- public static final void fillBuffer(ByteBuffer buffer, int seed) {
+ public static ByteBuffer fillBuffer(ByteBuffer buffer, int seed) {
Random rnd = new Random(seed);
@@ -52,9 +53,23 @@ public class TestUtils {
buffer.putInt(rnd.nextInt());
buffer.rewind();
+
+ return buffer;
}
- public static final int roundUp(int groupSize, int globalSize) {
+ public static FloatBuffer fillBuffer(FloatBuffer buffer, int seed) {
+
+ Random rnd = new Random(seed);
+
+ while(buffer.remaining() != 0)
+ buffer.put(rnd.nextFloat());
+
+ buffer.rewind();
+
+ return buffer;
+ }
+
+ public static int roundUp(int groupSize, int globalSize) {
int r = globalSize % groupSize;
if (r == 0) {
return globalSize;
@@ -63,7 +78,7 @@ public class TestUtils {
}
}
- public static final void checkIfEqual(ByteBuffer a, ByteBuffer b, int elements) {
+ public static void checkIfEqual(ByteBuffer a, ByteBuffer b, int elements) {
for(int i = 0; i < elements; i++) {
int aVal = a.getInt();
int bVal = b.getInt();