summaryrefslogtreecommitdiffstats
path: root/test/com/jogamp/opencl/util
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2011-09-20 02:42:59 +0200
committerMichael Bien <[email protected]>2011-09-20 02:42:59 +0200
commit18ae1f1e3c0ec5037e2790bcc517a564d30807d3 (patch)
tree925d0dc94cdb55a4fd164d8163b78295b385f616 /test/com/jogamp/opencl/util
parent953c64c02c61ec6fe2756105cd1a06967cb3d765 (diff)
first version of parallel ForEach primitive.
minor refactoring to make it DRY.
Diffstat (limited to 'test/com/jogamp/opencl/util')
-rw-r--r--test/com/jogamp/opencl/util/pp/ForEachTest.java71
-rw-r--r--test/com/jogamp/opencl/util/pp/ReductionTest.java20
2 files changed, 81 insertions, 10 deletions
diff --git a/test/com/jogamp/opencl/util/pp/ForEachTest.java b/test/com/jogamp/opencl/util/pp/ForEachTest.java
new file mode 100644
index 00000000..cd2b1bab
--- /dev/null
+++ b/test/com/jogamp/opencl/util/pp/ForEachTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011, Michael Bien
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Created on Tuesday, September 20 2011 01:26
+ */
+package com.jogamp.opencl.util.pp;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opencl.CLCommandQueue;
+import com.jogamp.opencl.CLContext;
+import java.nio.IntBuffer;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+/**
+ *
+ * @author mbien
+ */
+public class ForEachTest {
+
+
+ @Test
+ public void testForEach() {
+ CLContext context = CLContext.create();
+ try{
+ CLCommandQueue queue = context.getMaxFlopsDevice().createCommandQueue();
+
+ IntBuffer input = Buffers.newDirectIntBuffer(new int[]{ 1, 2, 3, 4, 5, 6, 7, 8});
+ IntBuffer output = Buffers.newDirectIntBuffer(input.capacity());
+
+ String op = "b[globalID] = a[globalID]+1;";
+ ForEach<IntBuffer> foreach = ForEach.create(context, op, IntBuffer.class);
+ foreach.foreach(queue, input, output);
+
+ while(output.hasRemaining()) {
+ assertEquals(input.get()+1, output.get());
+ }
+
+ foreach.release();
+ }finally{
+ context.release();
+ }
+ }
+
+
+}
diff --git a/test/com/jogamp/opencl/util/pp/ReductionTest.java b/test/com/jogamp/opencl/util/pp/ReductionTest.java
index 2894702f..94d1f53b 100644
--- a/test/com/jogamp/opencl/util/pp/ReductionTest.java
+++ b/test/com/jogamp/opencl/util/pp/ReductionTest.java
@@ -29,12 +29,12 @@
*/
package com.jogamp.opencl.util.pp;
+import com.jogamp.opencl.util.pp.Reduction.Op;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opencl.CLCommandQueue;
import com.jogamp.opencl.CLContext;
import com.jogamp.opencl.CLDevice;
import com.jogamp.opencl.CLPlatform;
-import com.jogamp.opencl.util.pp.Reduction.OP;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@@ -79,7 +79,7 @@ public class ReductionTest {
IntBuffer output = Buffers.newDirectIntBuffer(1);
- Reduction<IntBuffer> max = Reduction.create(context, OP.MAX, IntBuffer.class);
+ Reduction<IntBuffer> max = Reduction.create(context, Op.MAX, IntBuffer.class);
max.reduce(queue, input, output);
output.rewind();
@@ -88,7 +88,7 @@ public class ReductionTest {
assertEquals(expected_max, output.get(0));
- Reduction<IntBuffer> min = Reduction.create(context, OP.MIN, IntBuffer.class);
+ Reduction<IntBuffer> min = Reduction.create(context, Op.MIN, IntBuffer.class);
min.reduce(queue, input, output);
output.rewind();
@@ -97,7 +97,7 @@ public class ReductionTest {
assertEquals(expected_min, output.get(0));
- Reduction<IntBuffer> sum = Reduction.create(context, OP.ADD, IntBuffer.class);
+ Reduction<IntBuffer> sum = Reduction.create(context, Op.ADD, IntBuffer.class);
sum.reduce(queue, input, output);
output.rewind();
@@ -136,7 +136,7 @@ public class ReductionTest {
FloatBuffer output = Buffers.newDirectFloatBuffer(1);
- Reduction<FloatBuffer> max = Reduction.create(context, OP.MAX, FloatBuffer.class);
+ Reduction<FloatBuffer> max = Reduction.create(context, Op.MAX, FloatBuffer.class);
max.reduce(queue, input, output);
output.rewind();
@@ -145,7 +145,7 @@ public class ReductionTest {
assertEquals(expected_max, output.get(0), EPSILON);
- Reduction<FloatBuffer> min = Reduction.create(context, OP.MIN, FloatBuffer.class);
+ Reduction<FloatBuffer> min = Reduction.create(context, Op.MIN, FloatBuffer.class);
min.reduce(queue, input, output);
output.rewind();
@@ -154,7 +154,7 @@ public class ReductionTest {
assertEquals(expected_min, output.get(0), EPSILON);
- Reduction<FloatBuffer> sum = Reduction.create(context, OP.ADD, FloatBuffer.class);
+ Reduction<FloatBuffer> sum = Reduction.create(context, Op.ADD, FloatBuffer.class);
sum.reduce(queue, input, output);
output.rewind();
@@ -193,7 +193,7 @@ public class ReductionTest {
DoubleBuffer output = Buffers.newDirectDoubleBuffer(1);
- Reduction<DoubleBuffer> max = Reduction.create(context, OP.MAX, DoubleBuffer.class);
+ Reduction<DoubleBuffer> max = Reduction.create(context, Op.MAX, DoubleBuffer.class);
max.reduce(queue, input, output);
output.rewind();
@@ -202,7 +202,7 @@ public class ReductionTest {
assertEquals(expected_max, output.get(0), EPSILON);
- Reduction<DoubleBuffer> min = Reduction.create(context, OP.MIN, DoubleBuffer.class);
+ Reduction<DoubleBuffer> min = Reduction.create(context, Op.MIN, DoubleBuffer.class);
min.reduce(queue, input, output);
output.rewind();
@@ -211,7 +211,7 @@ public class ReductionTest {
assertEquals(expected_min, output.get(0), EPSILON);
- Reduction<DoubleBuffer> sum = Reduction.create(context, OP.ADD, DoubleBuffer.class);
+ Reduction<DoubleBuffer> sum = Reduction.create(context, Op.ADD, DoubleBuffer.class);
sum.reduce(queue, input, output);
output.rewind();