diff --git a/test/runtime/src/java/com/amd/aparapi/test/runtime/ExplicitBoolean.java b/test/runtime/src/java/com/amd/aparapi/test/runtime/ExplicitBoolean.java new file mode 100644 index 0000000000000000000000000000000000000000..2034ae2b10ba5a05e3a8badf850be09a983b2f35 --- /dev/null +++ b/test/runtime/src/java/com/amd/aparapi/test/runtime/ExplicitBoolean.java @@ -0,0 +1,82 @@ +package com.amd.aparapi.test.runtime; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.amd.aparapi.Kernel; + +public class ExplicitBoolean{ + + class ExplicitBooleanTestKernel extends Kernel{ + int size; // Number of work items. + + int iterations; // Number of times to execute kernel. + + public boolean[] input, output; + + public ExplicitBooleanTestKernel(int _size) { + size = _size; + input = new boolean[size]; + output = new boolean[size]; + setExplicit(true); + put(output); + } + + public void go() { + put(input); + execute(size); + get(output); + } + + @Override public void run() { + int id = getGlobalId(); + output[id] = input[id]; + } + } + + static boolean same(boolean[] lhs, boolean[] rhs) { + boolean same = lhs != null && rhs != null && lhs.length == rhs.length; + for (int i = 0; same && i < lhs.length; i++) { + same = lhs[i] == rhs[i]; + } + return (same); + } + + @Test public void test() { + int size = 16; + ExplicitBooleanTestKernel k1 = new ExplicitBooleanTestKernel(size); + ExplicitBooleanTestKernel k2 = new ExplicitBooleanTestKernel(size); + k2.input = k1.output; + + for (int i = 0; i < size; i++) { + k1.input[i] = Math.random() > 0.5; + } + + if (size <= 32) + printArray(k1.input); + + k1.go(); + + if (size <= 32) + printArray(k1.output); + + assertTrue("k1.input == k1.output ", same(k1.output, k1.output)); + + k2.go(); + + if (size <= 32) + printArray(k2.output); + + assertTrue("k1.input == k2.input", same(k1.output, k1.output)); + System.out.println(k1.getExecutionMode()); + } + + private static void printArray(boolean[] a) { + for (int i = 0; i < a.length; i++) { + System.out.print((a[i] ? 1 : 0) + "\t"); + } + System.out.println(); + } + +}