diff --git a/src/aeminium/gpu/backends/gpu/GPURecursiveCall.java b/src/aeminium/gpu/backends/gpu/GPURecursiveCall.java index 601e28a..4907fb9 100644 --- a/src/aeminium/gpu/backends/gpu/GPURecursiveCall.java +++ b/src/aeminium/gpu/backends/gpu/GPURecursiveCall.java @@ -67,8 +67,8 @@ public void execute(CLContext ctx, CLQueue q) { workUnits = args.length(); //end - start; // Using Limits from Decider bufferSize = workUnits * DEFAULT_SPAWN; - argbuffer = BufferHelper.createInputOutputBufferFor(ctx, args, - bufferSize); + args.set(bufferSize-1, args.get(0)); + argbuffer = BufferHelper.createInputOutputBufferFor(ctx, args); synchronized (kernel) { kernel.setArgs(counter, workUnits, rbuffer, accbuffer, argbuffer); @@ -98,12 +98,12 @@ public void execute(CLContext ctx, CLQueue q) { if (argsNext.isEmpty()) { isDone = true; } else { - if (argsNext.size() < MAX_ITEMS) { + if (argsNext.size() <= MAX_ITEMS) { args = argsNext; argsNext = args.subList(0, 0); } else { - args = argsNext.subList(0, MAX_ITEMS); - argsNext = argsNext.subList(MAX_ITEMS, argsNext.size()); + args = argsNext.subList(argsNext.size() - MAX_ITEMS, argsNext.size()); + argsNext = argsNext.subList(0, argsNext.size() - MAX_ITEMS); } } } diff --git a/src/aeminium/gpu/devices/BestContextDeviceFactory.java b/src/aeminium/gpu/devices/BestContextDeviceFactory.java index 64b8f5d..b84a4f0 100644 --- a/src/aeminium/gpu/devices/BestContextDeviceFactory.java +++ b/src/aeminium/gpu/devices/BestContextDeviceFactory.java @@ -1,26 +1,37 @@ package aeminium.gpu.devices; +import com.nativelibs4java.opencl.CLContext; +import com.nativelibs4java.opencl.CLDevice; import com.nativelibs4java.opencl.CLException; +import com.nativelibs4java.opencl.CLPlatform; import com.nativelibs4java.opencl.JavaCL; public class BestContextDeviceFactory implements DeviceFactory { - static GPUDevice d; @Override public GPUDevice getDevice() { if (d != null) return d; - if (JavaCL.listGPUPoweredPlatforms().length > 0) { - try { - d = new GPUDevice(JavaCL.createBestContext()); - return d; - } catch (CLException e) { - return null; + for (CLPlatform p : JavaCL.listGPUPoweredPlatforms()) { + for (CLDevice dev : p.listDevices(CLDevice.Type.GPU, true)) { + if (System.getenv("DEBUGCL") != null) { + System.out.println(p); + System.out.println(dev); + System.out.println(dev.getVendor()); + } + try { + CLContext ctx = JavaCL.createContext(null, dev); + if (dev.getType().contains(CLDevice.Type.GPU)) { + d = new GPUDevice(ctx); + return d; + } + } catch (CLException e) { + continue; + } } - } else { - return null; } + return null; } } diff --git a/templates/opencl/RecursiveCallKernel.clt b/templates/opencl/RecursiveCallKernel.clt index 290bc77..ff8cecd 100644 --- a/templates/opencl/RecursiveCallKernel.clt +++ b/templates/opencl/RecursiveCallKernel.clt @@ -1,5 +1,3 @@ -#pragma OPENCL EXTENSION cl_khr_fp64: enable - // Other Sources Required {{other_sources}}