Skip to content
Snippets Groups Projects
Commit b6a41c6e authored by Gary Frost's avatar Gary Frost
Browse files

No commit message

No commit message
parent a9f96b93
No related branches found
No related tags found
No related merge requests found
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment