CLProgram program = context.createProgram(codeAndMacros.getFirst()); program.defineMacros(codeAndMacros.getValue()); program.build(); CLKernel[] kernels = program.createKernels(); public Pair<CLBuffer<B>, CLEvent[]> reduceHelper(CLQueue queue, CLBuffer<B> input, int inputLength, int maxReductionSize, CLEvent... eventsToWaitFor) { if (inputLength == 1) { return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); depth++; return new Pair<CLBuffer<B>, CLEvent[]>(currentOutput, eventsToWaitFor);
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMapBuffer.html">clEnqueueMapBuffer</a>.<br> * @param queue Execution queue for this operation. * @param flags Map flags. * @param offset offset in the {@link CLBuffer} * @param length length to write (in bytes) * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ public Pointer<T> map(CLQueue queue, MapFlags flags, long offset, long length, CLEvent... eventsToWaitFor) throws CLException.MapFailure { return map(queue, flags, offset, length, true, eventsToWaitFor).getFirst(); }
CLEvent createEvent() { CLContext c = createContext(); return c.createBuffer(CLMem.Usage.Input, Integer.class, 10).mapLater(c.createDefaultQueue(), CLMem.MapFlags.Read).getSecond(); }
@Test public void testGPUPerfFloat() throws IOException { //CLKernels.setInstance(new CLKernels(JavaCL.createBestContext(DeviceFeature.GPU).createDefaultQueue())); //int size = 100; for (int size : new int[] { 10, 50, 100/*, 200, 400*/ }) { DefaultDenseFloatMatrix2D mJava = new DefaultDenseFloatMatrix2D(size, size); Matrix pJava = testPerf("Java(size = " + size +")", mJava).getValue(); for (DeviceFeature feat : new DeviceFeature[] { DeviceFeature.CPU, DeviceFeature.GPU }) { CLKernels.setInstance(new CLKernels(JavaCL.createBestContext(feat).createDefaultQueue())); CLDevice device = CLKernels.getInstance().getQueue().getDevice(); CLDenseFloatMatrix2D mCL = new CLDenseFloatMatrix2D(size, size); Matrix pCL = testPerf("OpenCL(size = " + size +", device = " + device + ")", mCL).getValue(); assertEquals(pJava, pCL); } } }
CLProgram program = context.createProgram(codeAndMacros.getFirst()); program.defineMacros(codeAndMacros.getValue()); program.build(); CLKernel[] kernels = program.createKernels(); public Pair<CLBuffer<B>, CLEvent[]> reduceHelper(CLQueue queue, CLBuffer<B> input, int inputLength, int maxReductionSize, CLEvent... eventsToWaitFor) { if (inputLength == 1) { return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); depth++; return new Pair<CLBuffer<B>, CLEvent[]>(currentOutput, eventsToWaitFor);
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMapBuffer.html">clEnqueueMapBuffer</a>.<br> * @param queue Execution queue for this operation. * @param flags Map flags. * @param offset offset in the {@link CLBuffer} * @param length length to write (in bytes) * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ public Pointer<T> map(CLQueue queue, MapFlags flags, long offset, long length, CLEvent... eventsToWaitFor) throws CLException.MapFailure { return map(queue, flags, offset, length, true, eventsToWaitFor).getFirst(); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMapBuffer.html">clEnqueueMapBuffer</a>.<br> * @param queue Execution queue for this operation. * @param flags Map flags. * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ public Pointer<T> map(CLQueue queue, MapFlags flags, CLEvent... eventsToWaitFor) throws CLException.MapFailure { return map(queue, flags, 0, getElementCount(), true, eventsToWaitFor).getFirst(); } /**
@SuppressWarnings("unchecked") public int compareTo(Pair<U, V> o) { Comparable<U> cu = (Comparable<U>)getFirst(); if (cu == null) { if (first != null) return 1; } else { int d = cu.compareTo(o.getFirst()); if (d != 0) return d; } Comparable<V> cv = (Comparable<V>)getSecond(); if (cv == null) return second != null ? 1 : -1; return cv.compareTo(o.getSecond()); }
return new Pair<Map<CLDevice, byte[]>, String>(ret, source);
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMapBuffer.html">clEnqueueMapBuffer</a>.<br> * @param queue Execution queue for this operation. * @param flags Map flags. * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ public Pointer<T> map(CLQueue queue, MapFlags flags, CLEvent... eventsToWaitFor) throws CLException.MapFailure { return map(queue, flags, 0, getElementCount(), true, eventsToWaitFor).getFirst(); } /**
@SuppressWarnings("unchecked") public CLEvent reduce(CLQueue queue, CLBuffer<B> input, long inputLength, Pointer<B> output, int maxReductionSize, CLEvent... eventsToWaitFor) { Pair<CLBuffer<B>, CLEvent[]> outAndEvts = reduceHelper(queue, input, (int)inputLength, maxReductionSize, eventsToWaitFor); return outAndEvts.getFirst().read(queue, 0, valueChannels, output, false, outAndEvts.getSecond()); } @Override
return new Pair<Map<CLDevice, byte[]>, String>(ret, source);
public ByteBuffer map(CLQueue queue, MapFlags flags, long offsetX, long offsetY, long offsetZ, long lengthX, long lengthY, long lengthZ, long rowPitch, long slicePitch, boolean blocking, CLEvent... eventsToWaitFor) { return map(queue, flags, pointerToSizeTs(offsetX, offsetY, offsetZ), pointerToSizeTs(lengthX, lengthY, lengthZ), rowPitch, slicePitch, true, eventsToWaitFor).getFirst(); } /**
@SuppressWarnings("unchecked") public CLEvent reduce(CLQueue queue, CLBuffer<B> input, long inputLength, Pointer<B> output, int maxReductionSize, CLEvent... eventsToWaitFor) { Pair<CLBuffer<B>, CLEvent[]> outAndEvts = reduceHelper(queue, input, (int)inputLength, maxReductionSize, eventsToWaitFor); return outAndEvts.getFirst().read(queue, 0, valueChannels, output, false, outAndEvts.getSecond()); } @Override
@SuppressWarnings("unchecked") public Pair<CLBuffer<B>, CLEvent[]> reduceHelper(CLQueue queue, CLBuffer<B> input, int inputLength, int maxReductionSize, CLEvent... eventsToWaitFor) { if (inputLength == 1) { return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); return new Pair<CLBuffer<B>, CLEvent[]>(input, new CLEvent[0]); depth++; return new Pair<CLBuffer<B>, CLEvent[]>(currentOutput, eventsToWaitFor);
public ByteBuffer map(CLQueue queue, MapFlags flags, long offsetX, long offsetY, long offsetZ, long lengthX, long lengthY, long lengthZ, long rowPitch, long slicePitch, boolean blocking, CLEvent... eventsToWaitFor) { return map(queue, flags, pointerToSizeTs(offsetX, offsetY, offsetZ), pointerToSizeTs(lengthX, lengthY, lengthZ), rowPitch, slicePitch, true, eventsToWaitFor).getFirst(); } /**