diff options
author | Michael Bien <[email protected]> | 2010-01-20 20:39:33 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-20 20:39:33 +0100 |
commit | c9e1605e183d7e83af16dc8fac057e58cfc2d29b (patch) | |
tree | 61322e181ac79d4e9d733de23b2784fb686ca902 /test | |
parent | 21f0d9231227a4d2c96cb70b5061c18145591fba (diff) |
seperated CLProgram specific tests into CLProgramTest.
implemented create-program-from-binaries functionality.
javadoc fixes.
Diffstat (limited to 'test')
-rw-r--r-- | test/com/mbien/opencl/CLProgramTest.java | 91 | ||||
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 45 |
2 files changed, 93 insertions, 43 deletions
diff --git a/test/com/mbien/opencl/CLProgramTest.java b/test/com/mbien/opencl/CLProgramTest.java new file mode 100644 index 00000000..0ca0fa9e --- /dev/null +++ b/test/com/mbien/opencl/CLProgramTest.java @@ -0,0 +1,91 @@ +package com.mbien.opencl; + +import java.io.IOException; +import java.util.Map; +import org.junit.Test; + +import static org.junit.Assert.*; +import static java.lang.System.*; +import static com.mbien.opencl.TestUtils.*; +import static com.sun.gluegen.runtime.BufferFactory.*; + +/** + * + * @author Michael Bien + */ +public class CLProgramTest { + + @Test + public void rebuildProgramTest() throws IOException { + + out.println(" - - - CLProgramTest; rebuild program test - - - "); + + CLContext context = CLContext.create(); + CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")); + + try{ + program.getCLKernels(); + fail("expected exception but got none :("); + }catch(CLException ex) { + out.println("got expected exception: "+ex.getCLErrorString()); + assertEquals(ex.errorcode, CL.CL_INVALID_PROGRAM_EXECUTABLE); + } + + program.build(); + assertTrue(program.isExecutable()); + out.println(program.getBuildStatus()); + + Map<String, CLKernel> kernels = program.getCLKernels(); + assertNotNull(kernels); + assertTrue("kernel map is empty", kernels.size() > 0); + + // rebuild + // 1. release kernels (internally) + // 2. build program + program.build(); + assertTrue(program.isExecutable()); + out.println(program.getBuildStatus()); + + // try again with rebuilt program + kernels = program.getCLKernels(); + assertNotNull(kernels); + assertTrue("kernel map is empty", kernels.size() > 0); + assertTrue(kernels.size() > 0); + + context.release(); + } + + @Test + public void programBinariesTest() throws IOException { + + out.println(" - - - CLProgramTest; down-/upload binaries test - - - "); + + CLContext context = CLContext.create(); + CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); + + // optain binaries + Map<CLDevice, byte[]> binaries = program.getBinaries(); + assertFalse(binaries.isEmpty()); + + CLDevice[] devices = program.getCLDevices(); + for (CLDevice device : devices) { + assertTrue(binaries.containsKey(device)); + } + + // 1. release program + // 2. re-create program with old binaries + program.release(); + + program = context.createProgram(binaries); + + out.println(program.getBuildStatus()); + + program.build(); + + assertTrue(program.isExecutable()); + + } + + + +} diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index d28dd042..171c972f 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -120,8 +120,8 @@ public class HighLevelBindingTest { assertFalse(source.trim().isEmpty()); // out.println("source:\n"+source); -// Map<CLDevice, byte[]> binaries = program.getBinaries(); -// assertFalse(binaries.isEmpty()); + Map<CLDevice, byte[]> binaries = program.getBinaries(); + assertFalse(binaries.isEmpty()); int elementCount = 11444777; // Length of float arrays to process (odd # for illustration) int localWorkSize = 256; // set and log Global and Local work size dimensions @@ -189,46 +189,5 @@ public class HighLevelBindingTest { context.release(); } - @Test - public void rebuildProgramTest() throws IOException { - - out.println(" - - - highLevelTest; rebuild program test - - - "); - - CLContext context = CLContext.create(); - CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")); - - try{ - program.getCLKernels(); - fail("expected exception but got none :("); - }catch(CLException ex) { - out.println("got expected exception:\n"+ex.getMessage()); - assertEquals(ex.errorcode, CL.CL_INVALID_PROGRAM_EXECUTABLE); - } - - program.build(); - assertTrue(program.isExecutable()); - out.println(program.getBuildStatus()); - - Map<String, CLKernel> kernels = program.getCLKernels(); - assertNotNull(kernels); - assertTrue("kernel map is empty", kernels.size() > 0); - - // rebuild - // 1. release kernels (internally) - // 2. build program - program.build(); - assertTrue(program.isExecutable()); - out.println(program.getBuildStatus()); - - // try again with rebuilt program - kernels = program.getCLKernels(); - assertNotNull(kernels); - assertTrue("kernel map is empty", kernels.size() > 0); - assertTrue(kernels.size() > 0); - - context.release(); - } - - } |