Here are the examples of the java api com.aparapi.Range taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
97 Examples
18
Source : Main.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
public static void main(String[] _args) throws ClreplacedNotFoundException, InstantiationException, IllegalAccessException {
int size = Integer.getInteger("size", 1024);
Range range = Range.create(size);
int iterations = Integer.getInteger("iterations", 10000);
System.out.println("size =" + size);
System.out.println("iterations =" + iterations);
BlackScholesKernel kernel = new BlackScholesKernel(size);
for (int i = 0; i < iterations; i++) {
kernel.execute(size).getExecutionTime();
}
kernel.execute(range, iterations);
System.out.println("Average execution time " + kernel.getAcreplacedulatedExecutionTime() / iterations);
kernel.showResults(10);
kernel.dispose();
}
18
Source : KernelCompileOnlyTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testCompileFollowedByExecuteFollowedByCompileOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
try {
myKernel.compile(openCLDevice);
} catch (CompileFailedException e) {
fail("This shouldn't happen");
}
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
try {
myKernel.compile(openCLDevice);
} catch (CompileFailedException e) {
fail("This shouldn't happen");
}
myKernel.execute(r);
int[] resultsB = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, resultsB[i]);
}
}
18
Source : KernelCompileOnlyTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testCompileFollowedByExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
try {
myKernel.compile(openCLDevice);
} catch (CompileFailedException e) {
fail("This shouldn't happen");
}
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
18
Source : KernelCompileOnlyTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testCompileCompileFollowedByExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
try {
myKernel.compile(openCLDevice);
} catch (CompileFailedException e) {
fail("This shouldn't happen");
}
try {
myKernel.compile(openCLDevice);
} catch (CompileFailedException e) {
fail("This shouldn't happen");
}
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
}
18
Source : KernelAndDeviceItemSizeLimitsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testKernelCompileWorkGroupSizeAndExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
int[] maxWorkItemSize = null;
try {
maxWorkItemSize = myKernel.getKernelCompileWorkGroupSize(openCLDevice);
} catch (QueryFailedException e) {
fail("This shouldn't happen");
}
replacedertTrue("Kernel Compile Work Group Size should not be null", maxWorkItemSize != null);
replacedertTrue("Kernel Compile Work Group Size should have a dimension greater than 0", maxWorkItemSize.length > 0);
for (int i = 0; i < maxWorkItemSize.length; i++) {
replacedertTrue("Kernel Compile Work Group Size should be greater or equal than zero at index=" + i, maxWorkItemSize[i] >= 0);
}
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
18
Source : KernelAndDeviceItemSizeLimitsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testKernelMaxWorkGroupSizeAndExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
int maxWorkGroupSize = -10;
try {
maxWorkGroupSize = myKernel.getKernelMaxWorkGroupSize(openCLDevice);
} catch (QueryFailedException e) {
fail("This shouldn't happen");
}
replacedertTrue("Max Kernel Workgroup Size should be greater than 0", maxWorkGroupSize > 0);
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
18
Source : KernelAndDeviceItemSizeLimitsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testPreferredKernelWorkGroupSizeMultipleAndExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
int preferredWorkGroupSizeMultiple = -10;
try {
preferredWorkGroupSizeMultiple = myKernel.getKernelPreferredWorkGroupSizeMultiple(openCLDevice);
} catch (QueryFailedException e) {
fail("This shouldn't happen");
}
replacedertTrue("Preferred Kernel Workgroup Size Multiple should be greater than 0", preferredWorkGroupSizeMultiple > 0);
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
18
Source : KernelAndDeviceItemSizeLimitsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testKernelMinimumPrivateMemSizeInUsePerWorkItemAndExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
long maxPrivateMemSize = -10;
try {
maxPrivateMemSize = myKernel.getKernelMinimumPrivateMemSizeInUsePerWorkItem(openCLDevice);
} catch (QueryFailedException e) {
fail("This shouldn't happen");
}
replacedertTrue("Max Private Mem Size should be greater than 0", maxPrivateMemSize >= 0);
Range r = Range.create(openCLDevice, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
18
Source : KernelAndDeviceItemSizeLimitsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testKernelLocalMemSizeInUseAndExecuteOnOpenCL() {
SimpleKernel myKernel = new SimpleKernel();
long maxLocalMemSize = -10;
try {
maxLocalMemSize = myKernel.getKernelLocalMemSizeInUse(openCLDevice);
} catch (QueryFailedException e) {
fail("This shouldn't happen");
}
replacedertTrue("Max Local Mem Size should be greater or equal to 0", maxLocalMemSize >= 0);
Range r = Range.create(openCLDevice, SIZE, SIZE);
myKernel.execute(r);
int[] results = myKernel.getResults();
for (int i = 0; i < SIZE; i++) {
replacedertEquals("There is an error in the computed kernel result at index=" + i, i, results[i]);
}
replacedertTrue("Aparapi should have taken some time to compile and execute the kernel", myKernel.getAcreplacedulatedExecutionTimeCurrentThread(openCLDevice) > 0);
}
17
Source : JavaMandelBrotMultiThread.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Override
public MandelBrot createMandleBrot(final Range range, final float scale, final float offsetx, final float offsety, final int[] rgb) {
final int width = range.getGlobalSize(0);
final int height = range.getGlobalSize(1);
final int threadCount = 8;
final Thread[] threads = new Thread[threadCount];
final CyclicBarrier barrier = new CyclicBarrier(threadCount + 1);
for (int thread = 0; thread < threadCount; thread++) {
final int threadId = thread;
final int groupHeight = height / threadCount;
(threads[threadId] = new Thread(new Runnable() {
@Override
public void run() {
for (int gridy = threadId * groupHeight; gridy < ((threadId + 1) * groupHeight); gridy++) {
for (int gridx = 0; gridx < width; gridx++) {
final float x = ((((gridx) * scale) - ((scale / 2.0f) * width)) / width) + offsetx;
final float y = ((((gridy) * scale) - ((scale / 2.0f) * height)) / height) + offsety;
int count = 0;
float zx = x;
float zy = y;
float new_zx = 0.0f;
for (; (count < MAX_ITERATIONS) && (((zx * zx) + (zy * zy)) < 8.0f); count++) {
new_zx = ((zx * zx) - (zy * zy)) + x;
zy = ((2.0f * zx) * zy) + y;
zx = new_zx;
}
rgb[gridx + (gridy * width)] = pallette[count];
}
}
try {
barrier.await();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
})).start();
}
try {
barrier.await();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (this);
}
17
Source : RangeSizeTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void test384x384() {
Range range = Range.create2D(384, 384);
replacedertTrue("Range > max work size", range.getLocalSize(0) * range.getLocalSize(1) <= range.getWorkGroupSize());
}
17
Source : RangeSizeTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void test384x320() {
Range range = Range.create2D(384, 320);
replacedertTrue("Range > max work size", range.getLocalSize(0) * range.getLocalSize(1) <= range.getWorkGroupSize());
}
17
Source : LocalAtomicVariableArrayTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void simpleVarIndexOpenCLTest() {
SimpleVarIndexLocalVarKernel myKernel = new SimpleVarIndexLocalVarKernel();
Range range = openCLDevice.createRange(SIZE, SIZE);
try {
myKernel.execute(range);
replacedertEquals("Atomic increment doesn't match", SIZE, myKernel.atomics[4].get());
} finally {
myKernel.dispose();
}
}
17
Source : LocalAtomicVariableArrayTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void simpleConstIndexOpenCLTest() {
SimpleConstIndexLocalVarKernel myKernel = new SimpleConstIndexLocalVarKernel();
Range range = openCLDevice.createRange(SIZE, SIZE);
try {
myKernel.execute(range);
replacedertEquals("Atomic increment doesn't match, index 1", SIZE, myKernel.atomics[1].get());
replacedertEquals("Atomic increment doesn't match, index 2", SIZE, myKernel.atomics[2].get());
replacedertEquals("Atomic increment doesn't match, index 3", SIZE, myKernel.atomics[3].get());
} finally {
myKernel.dispose();
}
}
17
Source : LocalArrayArgsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testExplicit() {
final LocalArrayArgsKernel kernel = new LocalArrayArgsKernel();
try {
final Range range = openCLDevice.createRange(SIZE, SIZE);
targetArray = new int[SIZE];
kernel.setExplicit(true);
kernel.setArray(targetArray);
kernel.put(targetArray);
kernel.execute(range);
kernel.get(targetArray);
replacedertTrue(validate());
} finally {
kernel.dispose();
}
}
17
Source : LocalArrayArgsTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void test() {
final LocalArrayArgsKernel kernel = new LocalArrayArgsKernel();
try {
final Range range = openCLDevice.createRange(SIZE, SIZE);
targetArray = new int[SIZE];
kernel.setExplicit(false);
kernel.setArray(targetArray);
kernel.execute(range);
replacedertTrue(validate());
} finally {
kernel.dispose();
}
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicCmpXchg1OpenCLExplicit() {
final int[] in = new int[3];
final int[] out = new int[2];
in[0] = 50;
in[1] = 50;
in[2] = 100;
final AtomicCmpXchg kernel = new AtomicCmpXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[2], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicXchgOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicXchg kernel = new AtomicXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMin1OpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 49;
final AtomicMin kernel = new AtomicMin(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicOrOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0x80;
in[1] = 0x02;
final AtomicOr kernel = new AtomicOr(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x82, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicCmpXchg2OpenCLExplicit() {
final int[] in = new int[3];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
in[2] = 100;
final AtomicCmpXchg kernel = new AtomicCmpXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicDecOpenCL() {
final int[] in = new int[1];
final int[] out = new int[2];
in[0] = 50;
final AtomicDec kernel = new AtomicDec(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] - 1, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicCmpXchg1OpenCL() {
final int[] in = new int[3];
final int[] out = new int[2];
in[0] = 50;
in[1] = 50;
in[2] = 100;
final AtomicCmpXchg kernel = new AtomicCmpXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[2], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicOrOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0x80;
in[1] = 0x02;
final AtomicOr kernel = new AtomicOr(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x82, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicAndOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0xf1;
in[1] = 0x8f;
final AtomicAnd kernel = new AtomicAnd(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x81, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMin1OpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 49;
final AtomicMin kernel = new AtomicMin(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicAndOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0xf1;
in[1] = 0x8f;
final AtomicAnd kernel = new AtomicAnd(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x81, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicAddOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicAdd kernel = new AtomicAdd(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] + in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMax2OpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 49;
final AtomicMax kernel = new AtomicMax(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMin2OpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
final AtomicMin kernel = new AtomicMin(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMax2OpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 49;
final AtomicMax kernel = new AtomicMax(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicIncOpenCLExplicit() {
final int[] in = new int[1];
final int[] out = new int[2];
in[0] = 50;
final AtomicInc kernel = new AtomicInc(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] + 1, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMax1OpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
final AtomicMax kernel = new AtomicMax(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMax1OpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
final AtomicMax kernel = new AtomicMax(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicIncOpenCL() {
final int[] in = new int[1];
final int[] out = new int[2];
in[0] = 50;
final AtomicInc kernel = new AtomicInc(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] + 1, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicSubOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicSub kernel = new AtomicSub(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] - in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicXorOpenCLExplicit() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0xf1;
in[1] = 0x8f;
final AtomicXor kernel = new AtomicXor(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x7e, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicXchgOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicXchg kernel = new AtomicXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicCmpXchg2OpenCL() {
final int[] in = new int[3];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
in[2] = 100;
final AtomicCmpXchg kernel = new AtomicCmpXchg(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicMin2OpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 50;
in[1] = 51;
final AtomicMin kernel = new AtomicMin(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicAddOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicAdd kernel = new AtomicAdd(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] + in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicSubOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 10;
in[1] = 20;
final AtomicSub kernel = new AtomicSub(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] - in[1], out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicXorOpenCL() {
final int[] in = new int[2];
final int[] out = new int[2];
in[0] = 0xf1;
in[1] = 0x8f;
final AtomicXor kernel = new AtomicXor(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", 0x7e, out[1]);
}
17
Source : AtomicsSupportTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testAtomicDecOpenCLExplicit() {
final int[] in = new int[1];
final int[] out = new int[2];
in[0] = 50;
final AtomicDec kernel = new AtomicDec(in, out);
try {
final Range range = openCLDevice.createRange(1, 1);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Old value doesn't match", in[0], out[0]);
replacedertEquals("Final value doesn't match", in[0] - 1, out[1]);
}
17
Source : AtomicsSupportAdvTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testOpenCL() {
final int[] in = new int[SIZE];
final int[] out = new int[3];
for (int i = 0; i < SIZE / 2; i++) {
in[i] = i;
in[i + SIZE / 2] = SIZE - i;
}
in[10] = SIZE;
final AtomicKernel kernel = new AtomicKernel(in, out);
try {
final Range range = openCLDevice.createRange(SIZE / 2, SIZE / 2);
kernel.execute(range);
} finally {
kernel.dispose();
}
replacedertEquals("Max value doesn't match", 100, out[0]);
replacedertTrue("Left max found at unexpected position: " + out[MAX_POS_LEFT_IDX], out[MAX_POS_LEFT_IDX] == 10 || out[MAX_POS_LEFT_IDX] == 50);
replacedertTrue("Right max found at unexpected position: " + out[MAX_POS_RIGHT_IDX], out[MAX_POS_RIGHT_IDX] == 100 - 10 || out[MAX_POS_RIGHT_IDX] == 100 - 50);
}
17
Source : AtomicsSupportAdvTest.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
@Test
public void testOpenCLExplicit() {
final int[] in = new int[SIZE];
final int[] out = new int[3];
for (int i = 0; i < SIZE / 2; i++) {
in[i] = i;
in[i + SIZE / 2] = SIZE - i;
}
in[10] = SIZE;
final AtomicKernel kernel = new AtomicKernel(in, out);
try {
final Range range = openCLDevice.createRange(SIZE / 2, SIZE / 2);
kernel.setExplicit(true);
kernel.put(in);
kernel.execute(range);
kernel.get(out);
} finally {
kernel.dispose();
}
replacedertEquals("Max value doesn't match", 100, out[0]);
replacedertTrue("Left max found at unexpected position: " + out[MAX_POS_LEFT_IDX], out[MAX_POS_LEFT_IDX] == 10 || out[MAX_POS_LEFT_IDX] == 50);
replacedertTrue("Right max found at unexpected position: " + out[MAX_POS_RIGHT_IDX], out[MAX_POS_RIGHT_IDX] == 100 - 10 || out[MAX_POS_RIGHT_IDX] == 100 - 50);
}
17
Source : LongAparapiMatrixStrategy.java
with GNU Lesser General Public License v2.1
from mtommila
with GNU Lesser General Public License v2.1
from mtommila
@Override
public void permuteToHalfWidth(ArrayAccess arrayAccess, int n1, int n2) throws ApfloatRuntimeException {
if (n1 != (n1 & -n1) || n2 != (n2 & -n2) || n1 <= 0 || n2 <= 0) {
throw new ApfloatInternalException("Matrix size must be a power of two, not " + n1 + " x " + n2);
}
// Permute the rows of matrix to correct order, to make the n1 x n2 matrix half as wide (2*n1 x n2/2)
if (n1 < 2) {
return;
}
int twicen1 = 2 * n1;
boolean[] isRowDone = new boolean[twicen1];
// Overly big but twicen1 just isn't enough
int[] index = new int[twicen1 * 2];
int j = 1, p = 0;
do {
int m = j;
index[p++] = m;
isRowDone[m] = true;
m = (m < n1 ? 2 * m : 2 * (m - n1) + 1);
while (m != j) {
isRowDone[m] = true;
index[p++] = m;
m = (m < n1 ? 2 * m : 2 * (m - n1) + 1);
}
index[p++] = 0;
while (isRowDone[j]) {
j++;
}
} while (j < twicen1 - 1);
LongKernel kernel = LongKernel.getInstance();
kernel.setOp(LongKernel.PERMUTE);
kernel.setArrayAccess(arrayAccess);
kernel.setN2(n2 / 2);
kernel.setIndex(index);
kernel.setIndexCount(p);
kernel.put(index);
Range range = Range.create(n2 / 2);
kernel.execute(range);
}
17
Source : LongAparapiMatrixStrategy.java
with GNU Lesser General Public License v2.1
from mtommila
with GNU Lesser General Public License v2.1
from mtommila
@Override
public void permuteToDoubleWidth(ArrayAccess arrayAccess, int n1, int n2) throws ApfloatRuntimeException {
if (n1 != (n1 & -n1) || n2 != (n2 & -n2) || n1 <= 0 || n2 <= 0) {
throw new ApfloatInternalException("Matrix size must be a power of two, not " + n1 + " x " + n2);
}
if (n1 < 2) {
throw new ApfloatInternalException("Matrix height must be at least 2.");
}
// Permute the rows of matrix to correct order, to make the n1 x n2 matrix twice as wide (n1/2 x 2*n2)
if (n1 < 4) {
return;
}
int halfn1 = n1 / 2;
boolean[] isRowDone = new boolean[n1];
// Overly big but n1 just isn't enough
int[] index = new int[n1 * 2];
int j = 1, p = 0;
do {
int m = j;
index[p++] = m;
isRowDone[m] = true;
m = ((m & 1) != 0 ? m / 2 + halfn1 : m / 2);
while (m != j) {
isRowDone[m] = true;
index[p++] = m;
m = ((m & 1) != 0 ? m / 2 + halfn1 : m / 2);
}
index[p++] = 0;
while (isRowDone[j]) {
j++;
}
} while (j < n1 - 1);
LongKernel kernel = LongKernel.getInstance();
kernel.setOp(LongKernel.PERMUTE);
kernel.setArrayAccess(arrayAccess);
kernel.setN2(n2);
kernel.setIndex(index);
kernel.setIndexCount(p);
kernel.put(index);
Range range = Range.create(n2);
kernel.execute(range);
}
16
Source : SwapExample.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
public static void main(String[] args) {
final int size = 32;
final float[] lhs = new float[size];
for (int i = 0; i < size; i++) {
lhs[i] = i;
}
final float[] rhs = new float[size];
final Range range = Range.create(size);
final Device device = KernelManager.instance().bestDevice();
if (device instanceof OpenCLDevice) {
final OpenCLDevice openclDevice = (OpenCLDevice) device;
final Swapper swapper = openclDevice.bind(Swapper.clreplaced);
for (int i = 0; i < size; i++) {
System.out.println(lhs[i] + " " + rhs[i]);
}
swapper.swap(range, lhs, rhs);
for (int i = 0; i < size; i++) {
System.out.println(lhs[i] + " " + rhs[i]);
}
swapper.swap(range, lhs, rhs);
for (int i = 0; i < size; i++) {
System.out.println(lhs[i] + " " + rhs[i]);
}
swapper.swap(range, rhs, lhs);
for (int i = 0; i < size; i++) {
System.out.println(lhs[i] + " " + rhs[i]);
}
}
}
16
Source : Pow4Example.java
with Apache License 2.0
from Syncleus
with Apache License 2.0
from Syncleus
public static void main(String[] args) {
final int size = 32;
final float[] in = new float[size];
for (int i = 0; i < size; i++) {
in[i] = i;
}
final float[] squares = new float[size];
final Range range = Range.create(size);
final Device device = KernelManager.instance().bestDevice();
if (device instanceof OpenCLDevice) {
final OpenCLDevice openclDevice = (OpenCLDevice) device;
final Squarer squarer = openclDevice.bind(Squarer.clreplaced);
squarer.square(range, in, squares);
for (int i = 0; i < size; i++) {
System.out.println(in[i] + " " + squares[i]);
}
squarer.square(range, squares, in);
for (int i = 0; i < size; i++) {
System.out.println(i + " " + squares[i] + " " + in[i]);
}
}
}
See More Examples