diff options
author | Michael Bien <[email protected]> | 2010-02-19 22:16:40 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-02-19 22:16:40 +0100 |
commit | ed40efbf71daaee371d7eb334b0b7a00919548bc (patch) | |
tree | 986ae5fad1b2b82fd898f9da4aec9abd39bfbb09 | |
parent | a49b22397ae525e9b659a112aa11e4647c18c214 (diff) |
fixed CLBufferTest.mapBufferTest() for non CPU contexts.
-rw-r--r-- | src/com/mbien/opencl/CLPlatform.java | 6 | ||||
-rw-r--r-- | test/com/mbien/opencl/CLBufferTest.java | 21 |
2 files changed, 24 insertions, 3 deletions
diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java index 2f3cbf54..c3b1a1f2 100644 --- a/src/com/mbien/opencl/CLPlatform.java +++ b/src/com/mbien/opencl/CLPlatform.java @@ -98,6 +98,12 @@ public final class CLPlatform { //find all devices int ret = cl.clGetDeviceIDs(ID, type.TYPE, 0, null, ib); + + // return an empty array rather than throwing an exception + if(ret == CL.CL_DEVICE_NOT_FOUND) { + return new CLDevice[0]; + } + checkForError(ret, "error while enumerating devices"); PointerBuffer deviceIDs = PointerBuffer.allocateDirect(ib.get(0)); diff --git a/test/com/mbien/opencl/CLBufferTest.java b/test/com/mbien/opencl/CLBufferTest.java index b6029e3c..f768c5ae 100644 --- a/test/com/mbien/opencl/CLBufferTest.java +++ b/test/com/mbien/opencl/CLBufferTest.java @@ -101,10 +101,25 @@ public class CLBufferTest { final int elements = NUM_ELEMENTS; final int sizeInBytes = elements*SIZEOF_INT; - CLContext context = CLContext.create(); + CLContext context = null; + CLBuffer<?> clBufferA = null; + CLBuffer<?> clBufferB = null; + + // We will have to allocate mappable NIO memory on non CPU contexts + // since we can't map e.g GPU memory. + if(CLPlatform.getDefault().listCLDevices(CLDevice.Type.CPU).length > 0) { + + context = CLContext.create(CLDevice.Type.CPU); - CLBuffer<?> clBufferA = context.createBuffer(sizeInBytes, Mem.READ_WRITE); - CLBuffer<?> clBufferB = context.createBuffer(sizeInBytes, Mem.READ_WRITE); + clBufferA = context.createBuffer(sizeInBytes, Mem.READ_WRITE); + clBufferB = context.createBuffer(sizeInBytes, Mem.READ_WRITE); + }else{ + + context = CLContext.create(); + + clBufferA = context.createByteBuffer(sizeInBytes, Mem.READ_WRITE, Mem.USE_BUFFER); + clBufferB = context.createByteBuffer(sizeInBytes, Mem.READ_WRITE, Mem.USE_BUFFER); + } CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); |