diff options
author | Michael Bien <[email protected]> | 2010-01-12 22:47:32 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-12 22:47:32 +0100 |
commit | 4aebe5715b7d61591c8e0b677e452b3905e5ecd6 (patch) | |
tree | 8373e4472bced12403bb5620ca807593c71be85c /test/com | |
parent | 2c00ae70f73098653084e6852b4529f5e7c02f72 (diff) |
re-enabled create from host pointer CLBuffer options and added bufferWithHostPointerTest().
Diffstat (limited to 'test/com')
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index 5515cecc..da1080d1 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -3,6 +3,7 @@ package com.mbien.opencl; import com.mbien.opencl.CLBuffer.Mem; import com.mbien.opencl.CLCommandQueue.Mode; import com.mbien.opencl.CLDevice.SingleFPConfig; +import com.sun.opengl.util.BufferUtil; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; @@ -21,6 +22,9 @@ import static com.sun.gluegen.runtime.BufferFactory.*; */ public class HighLevelBindingTest { + //decrease this value on systems with few memory. + private final static int NUM_ELEMENTS = 10000000; + @BeforeClass public static void setUpClass() throws Exception { out.println("OS: " + System.getProperty("os.name")); @@ -187,7 +191,7 @@ public class HighLevelBindingTest { out.println(" - - - highLevelTest; copy buffer test - - - "); - final int elements = 10000000; //many.. + final int elements = NUM_ELEMENTS; CLContext context = CLContext.create(); @@ -208,24 +212,51 @@ public class HighLevelBindingTest { context.release(); - ByteBuffer a = clBufferA.buffer; - ByteBuffer b = clBufferB.buffer; - - // print first few elements of the resulting buffer to the console. out.println("validating computed results..."); - for(int i = 0; i < elements; i++) { - int aVal = a.getInt(); - int bVal = b.getInt(); - if(aVal != bVal) { - out.println("a: "+aVal); - out.println("b: "+bVal); - out.println("position: "+a.position()); - fail("a!=b"); - } + checkIfEqual(clBufferA.buffer, clBufferB.buffer, elements); + out.println("results are valid"); + + } + + @Test + public void bufferWithHostPointerTest() throws IOException { + + out.println(" - - - highLevelTest; host pointer test - - - "); + + final int elements = NUM_ELEMENTS; + + CLContext context = CLContext.create(); + + ByteBuffer buffer = BufferUtil.newByteBuffer(elements*SIZEOF_INT); + // fill only first read buffer -> we will copy the payload to the second later. + fillBuffer(buffer, 12345); + CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); + + Mem[] bufferConfig = new Mem[] {Mem.COPY_BUFFER, Mem.USE_BUFFER}; + + for(int i = 0; i < bufferConfig.length; i++) { + + out.println("testing with "+bufferConfig[i] + " config"); + + CLBuffer<ByteBuffer> clBufferA = context.createBuffer(buffer, Mem.READ_ONLY, bufferConfig[i]); + CLBuffer<ByteBuffer> clBufferB = context.createByteBuffer(elements*SIZEOF_INT, Mem.READ_ONLY); + + // asynchronous write of data to GPU device, blocking read later to get the computed results back. + queue.putCopyBuffer(clBufferA, clBufferB, clBufferA.buffer.capacity()) // copy A -> B + .putReadBuffer(clBufferB, true) // read B + .finish(); + + clBufferA.release(); + clBufferB.release(); + + // uploading worked when a==b. + out.println("validating computed results..."); + checkIfEqual(clBufferA.buffer, clBufferB.buffer, elements); + out.println("results are valid"); } - out.println("results are valid"); + context.release(); } @Test @@ -267,5 +298,21 @@ public class HighLevelBindingTest { context.release(); } + + + private final void checkIfEqual(ByteBuffer a, ByteBuffer b, int elements) { + for(int i = 0; i < elements; i++) { + int aVal = a.getInt(); + int bVal = b.getInt(); + if(aVal != bVal) { + out.println("a: "+aVal); + out.println("b: "+bVal); + out.println("position: "+a.position()); + fail("a!=b"); + } + } + a.rewind(); + b.rewind(); + } } |