Skip to content

Commit

Permalink
fixed CLBufferTest.mapBufferTest() for non CPU contexts.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbien committed Feb 19, 2010
1 parent a49b223 commit ed40efb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/com/mbien/opencl/CLPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public CLDevice[] listCLDevices(CLDevice.Type type) {

//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));
Expand Down
21 changes: 18 additions & 3 deletions test/com/mbien/opencl/CLBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,25 @@ public void mapBufferTest() {
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();

Expand Down

0 comments on commit ed40efb

Please sign in to comment.