/** Returns {@code create(pointer, sizes, strides, true)} */ public static LongIndexer create(LongPointer pointer, long[] sizes, long[] strides) { return create(pointer, sizes, strides, true); } /**
/** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ public static LongIndexer create(LongPointer pointer) { return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
/** * * @param data * @param copy */ public BaseDataBuffer(long[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new LongPointer(data); setIndexer(LongIndexer.create((LongPointer) pointer)); length = data.length; underlyingLength = data.length; }
/** * Create a data buffer from * the given length * * @param buffer * @param length */ public BaseDataBuffer(ByteBuffer buffer, long length) { if (length < 1) throw new IllegalArgumentException("Length must be >= 1"); initTypeAndSize(); this.length = length; allocationMode = AllocUtil.getAllocationModeFromContext(); if (dataType() == Type.DOUBLE) { pointer = new DoublePointer(buffer.asDoubleBuffer()); setIndexer(DoubleIndexer.create((DoublePointer) pointer)); } else if (dataType() == Type.FLOAT) { pointer = new FloatPointer(buffer.asFloatBuffer()); setIndexer(FloatIndexer.create((FloatPointer) pointer)); } else if (dataType() == Type.INT) { pointer = new IntPointer(buffer.asIntBuffer()); setIndexer(IntIndexer.create((IntPointer) pointer)); } else if (dataType() == Type.LONG) { pointer = new LongPointer(buffer.asLongBuffer()); setIndexer(LongIndexer.create((LongPointer) pointer)); } // log.info("Creating new buffer of size: {}; dtype: {}; D", length, dataType()); }
/** * * @param length * @param elementSize */ public BaseDataBuffer(long length, int elementSize) { if (length < 1) throw new IllegalArgumentException("Length must be >= 1"); initTypeAndSize(); allocationMode = AllocUtil.getAllocationModeFromContext(); this.length = length; this.underlyingLength = length; this.elementSize = (byte) elementSize; if (dataType() == Type.DOUBLE) { pointer = new DoublePointer(length); indexer = DoubleIndexer.create((DoublePointer) pointer); } else if (dataType() == Type.FLOAT) { pointer = new FloatPointer(length); setIndexer(FloatIndexer.create((FloatPointer) pointer)); } else if (dataType() == Type.INT) { pointer = new IntPointer(length); setIndexer(IntIndexer.create((IntPointer) pointer)); } else if (dataType() == Type.LONG) { pointer = new LongPointer(length); setIndexer(LongIndexer.create((LongPointer) pointer)); } // log.info("Creating new buffer of size: {}; dtype: {}; C", length, dataType()); }
} else if (dataType() == Type.LONG) { pointer = new LongPointer(length()); setIndexer(LongIndexer.create((LongPointer) pointer));
setIndexer(LongIndexer.create((LongPointer) pointer));
public void pointerIndexerByGlobalType(Type currentType) { if (currentType == Type.LONG) { pointer = new LongPointer(length()); setIndexer(LongRawIndexer.create((LongPointer) pointer)); type = Type.LONG; } else if (currentType == Type.INT) { pointer = new IntPointer(length()); setIndexer(IntIndexer.create((IntPointer) pointer)); type = Type.INT; } else { if (DataTypeUtil.getDtypeFromContext() == Type.DOUBLE) { pointer = new DoublePointer(length()); indexer = DoubleIndexer.create((DoublePointer) pointer); } else if (DataTypeUtil.getDtypeFromContext() == Type.FLOAT) { pointer = new FloatPointer(length()); setIndexer(FloatIndexer.create((FloatPointer) pointer)); } else if (DataTypeUtil.getDtypeFromContext() == Type.LONG) { pointer = new LongPointer(length()); setIndexer(LongIndexer.create((LongPointer) pointer)); } } }
private Indexer indexerForType(DataBuffer.Type type,Pointer pointer) { switch(type) { case DOUBLE: return DoubleIndexer.create(new DoublePointer(pointer)); case FLOAT: return FloatIndexer.create(new FloatPointer(pointer)); case INT: return IntIndexer.create(new IntPointer(pointer)); case LONG: return LongIndexer.create(new LongPointer(pointer)); default: throw new IllegalArgumentException("Illegal type " + type); } }
: (I)IntIndexer.create(new IntPointer((IntBuffer)buffer), sizes, strides, false).indexable(this); case DEPTH_LONG: return array != null ? (I)LongIndexer.create((long[])array, sizes, strides).indexable(this) : direct ? (I)LongIndexer.create((LongBuffer)buffer, sizes, strides).indexable(this) : (I)LongIndexer.create(new LongPointer((LongBuffer)buffer), sizes, strides, false).indexable(this); case DEPTH_FLOAT: return array != null ? (I)FloatIndexer.create((float[])array, sizes, strides).indexable(this)
: (I)IntIndexer.create(new IntPointer((IntBuffer)buffer), sizes, strides, false).indexable(this); case DEPTH_LONG: return array != null ? (I)LongIndexer.create((long[])array, sizes, strides).indexable(this) : direct ? (I)LongIndexer.create((LongBuffer)buffer, sizes, strides).indexable(this) : (I)LongIndexer.create(new LongPointer((LongBuffer)buffer), sizes, strides, false).indexable(this); case DEPTH_FLOAT: return array != null ? (I)FloatIndexer.create((float[])array, sizes, strides).indexable(this)
} else if (underlyingBuffer.dataType() == Type.LONG) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asLongPointer(); indexer = LongIndexer.create((LongPointer) pointer);
public BaseCudaDataBuffer(@NonNull DataBuffer underlyingBuffer, long length, long offset) { //this(length, underlyingBuffer.getElementSize(), offset); this.allocationMode = AllocationMode.LONG_SHAPE; initTypeAndSize(); this.wrappedDataBuffer = underlyingBuffer; this.originalBuffer = underlyingBuffer.originalDataBuffer() == null ? underlyingBuffer : underlyingBuffer.originalDataBuffer(); this.length = length; this.offset = offset; this.originalOffset = offset; this.trackingPoint = underlyingBuffer.getTrackingPoint(); this.elementSize = (byte) underlyingBuffer.getElementSize(); this.allocationPoint = ((BaseCudaDataBuffer) underlyingBuffer).allocationPoint; if (underlyingBuffer.dataType() == Type.DOUBLE) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asDoublePointer(); indexer = DoubleIndexer.create((DoublePointer) pointer); } else if (underlyingBuffer.dataType() == Type.FLOAT) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asFloatPointer(); indexer = FloatIndexer.create((FloatPointer) pointer); } else if (underlyingBuffer.dataType() == Type.INT) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asIntPointer(); indexer = IntIndexer.create((IntPointer) pointer); } else if (underlyingBuffer.dataType() == Type.HALF) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asShortPointer(); indexer = HalfIndexer.create((ShortPointer) pointer); } else if (underlyingBuffer.dataType() == Type.LONG) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), originalBuffer.length()).asLongPointer(); indexer = LongIndexer.create((LongPointer) pointer); } }
indexer = LongIndexer.create((LongPointer) pointer);
indexer = LongIndexer.create((LongPointer) pointer);
public BaseCudaDataBuffer(long length, int elementSize, boolean initialize) { this.allocationMode = AllocationMode.LONG_SHAPE; initTypeAndSize(); this.allocationPoint = AtomicAllocator.getInstance().allocateMemory(this, new AllocationShape(length, elementSize, dataType()), initialize); this.length = length; //allocationPoint.attachBuffer(this); this.elementSize = (byte) elementSize; this.trackingPoint = allocationPoint.getObjectId(); this.offset = 0; this.originalOffset = 0; // if (Nd4j.getAffinityManager().getDeviceForCurrentThread() == 0) //log.info("Allocating {} bytes on device_{}", length, Nd4j.getAffinityManager().getDeviceForCurrentThread()); if (dataType() == Type.DOUBLE) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asDoublePointer(); indexer = DoubleIndexer.create((DoublePointer) pointer); } else if (dataType() == Type.FLOAT) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asFloatPointer(); indexer = FloatIndexer.create((FloatPointer) pointer); } else if (dataType() == Type.INT) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asIntPointer(); indexer = IntIndexer.create((IntPointer) pointer); } else if (dataType() == Type.HALF) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asShortPointer(); indexer = HalfIndexer.create((ShortPointer) pointer); } else if (dataType() == Type.LONG) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asLongPointer(); indexer = LongIndexer.create((LongPointer) pointer); } }
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;
} else if (dataType() == Type.LONG) { this.pointer = new CudaPointer(allocationPoint.getPointers().getHostPointer(), length, 0).asLongPointer(); indexer = LongIndexer.create((LongPointer) pointer);
setIndexer(LongIndexer.create(((CudaPointer) this.pointer).asLongPointer()));
setIndexer(LongIndexer.create(((CudaPointer) this.pointer).asLongPointer()));