/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueReadBuffer.html">clEnqueueReadBuffer</a>.<br> * @param queue Execution queue for this operation. * @param out output buffer * @param blocking whether the operation should be blocking (and return null), or non-blocking (and return a completion event) * @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 CLEvent read(CLQueue queue, Pointer<T> out, boolean blocking, CLEvent... eventsToWaitFor) { return read(queue, 0, -1, out, blocking, 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 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 Pair<Pointer<T>, CLEvent> mapLater(CLQueue queue, MapFlags flags, CLEvent... eventsToWaitFor) throws CLException.MapFailure { return map(queue, flags, 0, getElementCount(), false, eventsToWaitFor); } /**
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueWriteBuffer.html">clEnqueueWriteBuffer</a>.<br> * @param queue Execution queue for this operation. * @param in input buffer * @param blocking whether the operation should be blocking (and return null), or non-blocking (and return a completion event) * @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 CLEvent write(CLQueue queue, Pointer<T> in, boolean blocking, CLEvent... eventsToWaitFor) { return write(queue, 0, -1, in, blocking, eventsToWaitFor); }
/** * enqueues a command to copy a buffer object identified by src_buffer to another buffer object identified by destination. * @param destination destination buffer object * @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 CLEvent copyTo(CLQueue queue, CLMem destination, CLEvent... eventsToWaitFor) { return copyTo(queue, 0, getElementCount(), destination, 0, eventsToWaitFor); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueCopyBuffer.html">clEnqueueCopyBuffer</a>.<br> * @param queue Execution queue for this operation. * @param destination destination buffer object * @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 CLEvent copyTo(CLQueue queue, CLBuffer destination, CLEvent... eventsToWaitFor) { return copyBytesTo(queue, destination, 0, 0, getByteCount(), eventsToWaitFor); }
longArray[i] = i; clInBuff.write(q, Pointer.pointerToLongs(longArray), true); kernel.setArg(0, clInBuff); kernel.setArg(1, clOutBuff); if (false) { Pointer<Long> outBuffJava = Pointer.pointerToLongs(outPrim); clOutBuff.read(q, 0, size,outBuffJava, true); } else { Pointer<Long> outBuffJava = Pointer.allocateLongs(size).order(context.getByteOrder()); clOutBuff.read(q, 0, size,outBuffJava, true); Pointer<Long> outBuffJava2 = clOutBuff.read(q); long[] outPrim2 = new long[size]; outBuffJava2.getLongs(outPrim2);
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueReadBuffer.html">clEnqueueReadBuffer</a>.<br> */ public Pointer<T> read(CLQueue queue, CLEvent... eventsToWaitFor) { Pointer<T> out = allocateCompatibleMemory(queue.getDevice()); read(queue, out, true, eventsToWaitFor); return out; } /**
public <B> void testReadWrite(Class<B> bufferClass, int n, int zeroOffset, int zeroLength) { CLBuffer<B> buf = context.createBuffer(CLMem.Usage.InputOutput, bufferClass, n); assertEquals(n, buf.getElementCount()); buf.write(queue, initial, true); Pointer<B> retrieved = buf.read(queue); assertEquals(buf.getElementCount(), retrieved.getValidElements()); buf.write(queue, zeroOffset, zeroLength, zeroes, true); buf.read(queue, readBuffer, true);
@Override public Pointer<B> reduce(CLQueue queue, CLBuffer<B> input, CLEvent... eventsToWaitFor) { return reduce(queue, input, input.getElementCount(), DEFAULT_MAX_REDUCTION_SIZE, eventsToWaitFor); } @Override
public Pointer<T> transform(CLQueue queue, Pointer<T> in, boolean inverse) { long inputSize = (int)in.getValidElements(); long length = inputSize / 2; CLBuffer<T> inBuf = context.createBuffer(CLMem.Usage.Input, in, true); // true = copy CLBuffer<T> outBuf = context.createBuffer(CLMem.Usage.Output, primitiveClass, computeOutputSize(inputSize)); CLEvent dftEvt = transform(queue, inBuf, outBuf, inverse); inBuf.release(); Pointer<T> out = outBuf.read(queue, dftEvt); outBuf.release(); return out; }
public <T> Object testArrayArg(String type, Object array, Class<T> targetType) { long size = BridJ.sizeOf(targetType); long length = Array.getLength(array); CLBuffer<Byte> out = context.createByteBuffer(Usage.Output, size * length); StringBuilder b = new StringBuilder( "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" + "kernel void f(" + type + length + " arg, global " + type + "* out, long length) {\n"); for (long i = 0; i < length; i++) { b.append("out[" + i + "] = arg.s" + (i < 10 ? i + "" : ((char)((int)'a' + (i - 10))) + "") + ";\n"); } b.append("}\n"); System.out.println(b); CLKernel k = context.createProgram(b.toString()).createKernel("f", array, out, length); CLEvent e = k.enqueueTask(queue); return out.as(targetType).read(queue, e).getArray(); }
@Test public void testCopyTo_full() { CLBuffer<Integer> b = context.createIntBuffer(CLMem.Usage.InputOutput, pointerToInts(1, 2, 3, 4, 5, 6)); CLBuffer<Integer> out = context.createIntBuffer(CLMem.Usage.InputOutput, 6); CLEvent e = b.copyTo(queue, out); assertArrayEquals(new int[] { 1, 2, 3, 4, 5, 6 }, out.read(queue, e).getInts()); } @Test
public CLBuffer<Float> asCLFloatBuffer() { return as(Float.class); }
@Test public void testCopyTo_partial() { CLBuffer<Integer> b = context.createIntBuffer(CLMem.Usage.InputOutput, pointerToInts(1, 2, 3, 4, 5, 6)); CLBuffer<Integer> out = context.createIntBuffer(CLMem.Usage.InputOutput, 6); CLEvent e = b.copyElementsTo(queue, out, 2, 1, 2); assertArrayEquals(new int[] { 3, 4 }, out.read(queue, e).next().validElements(2).getInts()); } }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillBuffer.html">clEnqueueFillBuffer</a>.<br> * @param queue Execution queue for this operation. * @param pattern Data pattern to fill the buffer with. * @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 CLEvent fillBuffer(CLQueue queue, Pointer<T> pattern, CLEvent... eventsToWaitFor) { return fillBuffer(queue, pattern, pattern.getValidElements(), 0, getElementCount(), eventsToWaitFor); }
public <T> CLBuffer<T> as(Class<T> newTargetType) { long mem = getEntity(); assert mem != 0; error(CL.clRetainMemObject(mem)); PointerIO<T> newIO = PointerIO.getInstance(newTargetType); return copyGLMark(new CLBuffer<T>(context, getByteCount(), mem, owner, newIO)); }
public CLDefaultMatrix2D(Primitive primitive, CLBuffer<T> buffer, long rows, long columns, int blockSize, CLKernels kernels) { this.primitive = primitive; this.primitiveClass = (Class<T>)primitive.primitiveType; this.stride = CLMatrixUtils.roundUp(columns, blockSize); this.length = this.stride * CLMatrixUtils.roundUp(rows, blockSize); if (buffer != null) { if (buffer.getElementCount() < this.length) { throw new IllegalArgumentException("Buffer size too small; buffer of size " + this.length + " expected, size " + buffer.getByteCount() + " was given"); } this.buffer = buffer; } else { this.buffer = (CLBuffer)kernels.getContext().createBuffer(Usage.InputOutput, primitive.primitiveType, length); } this.kernels = kernels; this.rows = rows; this.columns = columns; this.queue = kernels.getQueue(); this.context = kernels.getContext(); this.blockSize = blockSize; assert getBuffer().getElementCount() >= stride * rows && getBuffer().getElementCount() <= stride * CLMatrixUtils.roundUp(rows, getBlockSize()); }
public CLBuffer<T> emptyClone(CLMem.Usage usage) { return (CLBuffer)getContext().createBuffer(usage, io, getElementCount()); }
byteCount = getByteCount(), destByteCount = destination.getByteCount(), eltSize = getElementSize(), actualSrcOffset = srcOffset * eltSize, actualDestOffset = destOffset * eltSize, error(CL.clEnqueueCopyBuffer( queue.getEntity(), getEntity(), destination.getEntity(), actualSrcOffset,
public long getElementCount() { return getByteCount() / getElementSize(); } /**