public LongPointer asLongPointer() { return new LongPointer(this); }
/** * Creates a long indexer to access efficiently the data of a pointer. * * @param pointer data to access via a buffer or to copy to an array * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new long indexer backed by the raw memory interface, a buffer, or an array */ public static LongIndexer create(final LongPointer pointer, long[] sizes, long[] strides, boolean direct) { if (direct) { return Raw.getInstance() != null ? new LongRawIndexer(pointer, sizes, strides) : new LongBufferIndexer(pointer.asBuffer(), sizes, strides); } else { final long position = pointer.position(); long[] array = new long[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); return new LongArrayIndexer(array, sizes, strides) { @Override public void release() { pointer.position(position).put(array); super.release(); } }; } }
/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ public LongRawIndexer(LongPointer pointer, long[] sizes, long[] strides) { super(sizes, strides); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); }
LongPointer pointer = new LongPointer(data); Pointer srcPtr = new CudaPointer(pointer.address() + (dstOffset * elementSize)); pointer.address();
val iArgs = op.iArgs().length > 0 ? new LongPointer(op.iArgs().length) : null; cnt = 0; for (val i: op.iArgs()) iArgs.put(cnt++, i);
/** Returns {@link #tensor_data()} wrapped in a {@link Buffer} of appropriate type starting at given index. */ public <B extends Buffer> B createBuffer(long index) { BytePointer ptr = tensor_data(); long size = TotalBytes(); switch (dtype()) { case DT_COMPLEX64: case DT_FLOAT: return (B)new FloatPointer(ptr).position(index).capacity(size/4).asBuffer(); case DT_DOUBLE: return (B)new DoublePointer(ptr).position(index).capacity(size/8).asBuffer(); case DT_QINT32: case DT_INT32: return (B)new IntPointer(ptr).position(index).capacity(size/4).asBuffer(); case DT_BOOL: case DT_QUINT8: case DT_UINT8: case DT_QINT8: case DT_INT8: return (B)ptr.position(index).capacity(size).asBuffer(); case DT_BFLOAT16: case DT_INT16: return (B)new ShortPointer(ptr).position(index).capacity(size/2).asBuffer(); case DT_INT64: return (B)new LongPointer(ptr).position(index).capacity(size/8).asBuffer(); case DT_STRING: default: assert false; } return null; }
case DT_BFLOAT16: return (I)UShortIndexer.create(new ShortPointer(ptr).capacity(size/2), sizes, strides, direct).indexable(this); case DT_INT16: return (I)ShortIndexer.create(new ShortPointer(ptr).capacity(size/2), sizes, strides, direct).indexable(this); case DT_INT64: return (I)LongIndexer.create(new LongPointer(ptr).capacity(size/8), sizes, strides, direct).indexable(this); case DT_STRING: default: assert false;
/** @return {@code get(array, 0, array.length)} */ public LongPointer get(long[] array) { return get(array, 0, array.length); } /** @return {@code put(array, 0, array.length)} */
/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(long[]) */ public LongPointer(LongBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { long[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**
/** * Allocates enough memory for the array and copies it. * * @param array the array to copy * @see #put(long[]) */ public LongPointer(long ... array) { this(array.length); put(array); } /**
LongPointer pointer = new LongPointer(LongUtils.toLongs(data)); Pointer srcPtr = new CudaPointer(pointer.address() + (dstOffset * elementSize)); pointer.address();
val iArgs = op.iArgs().length > 0 ? new LongPointer(op.iArgs().length) : null; iArgs.put(cnt++, i);
/** @return the i-th {@code long long} of a native array */ public native long get(long i); /** @return {@code put(0, l)} */
/** @return {@code put(0, l)} */ public LongPointer put(long l) { return put(0, l); } /**
/** * Creates one by one a new {@link LongPointer} for each {@code long[]}, * and writes them into the native {@code void*} array. * * @param array the array of {@code long[]} to read from * @return this */ public PointerPointer<P> put(long[] ... array) { pointerArray = (P[])new LongPointer[array.length]; for (int i = 0; i < array.length; i++) { pointerArray[i] = array[i] != null ? (P)new LongPointer(array[i]) : null; } return put(pointerArray); } /**
LongPointer pointer = new LongPointer(LongUtils.toLongs(data)); Pointer srcPtr = new CudaPointer(pointer.address() + (dstOffset * elementSize)); pointer.address();
@Override public long nextLong() { long next = 0; synchronized (this) { if (position.get() >= numberOfElements) { position.set(0); generation++; } next = hostPointer.get(position.getAndIncrement()); if (generation > 1) next = next ^ generation + 11; if (amplifier != seed) next = next ^ amplifier + 11; } return next < 0 ? -1 * next : next; }