/** Returns {@code create(pointer, sizes, strides, true)} */ public static IntIndexer create(IntPointer pointer, long[] sizes, long[] strides) { return create(pointer, sizes, strides, true); } /**
/** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ public static IntIndexer create(IntPointer pointer) { return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
/** * @param intPointer * @param length * @return */ @Override public DataBuffer create(IntPointer intPointer, long length) { intPointer.capacity(length); intPointer.limit(length); intPointer.position(0); return new IntBuffer(intPointer, IntIndexer.create(intPointer), length); }
/** * * @param data * @param copy */ public BaseDataBuffer(int[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new IntPointer(data); setIndexer(IntIndexer.create((IntPointer) pointer)); length = data.length; underlyingLength = data.length; // // log.info("Creating new buffer of size: {}; dtype: {}; B", data.length, dataType()); }
/** * 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()); }
public BaseDataBuffer(int[] data, boolean copy, MemoryWorkspace workspace) { allocationMode = AllocUtil.getAllocationModeFromContext(); length = data.length; underlyingLength = data.length; attached = true; parentWorkspace = workspace; initTypeAndSize(); //log.info("Allocating FloatPointer from array of {} elements", data.length); pointer = workspace.alloc(data.length * getElementSize(), dataType(), false).asIntPointer().put(data); workspaceGenerationId = workspace.getGenerationId(); indexer = IntIndexer.create((IntPointer) pointer); //wrappedBuffer = pointer.asByteBuffer(); }
/** * * @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()); }
setIndexer(IntIndexer.create((IntPointer) pointer)); if (initialize) fillPointerWithZero();
setIndexer(IntIndexer.create((IntPointer) 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)); } } }
/** * @param intPointer * @param length * @return */ @Override public DataBuffer create(IntPointer intPointer, long length) { return new CudaIntDataBuffer(intPointer, IntIndexer.create(intPointer),length); }
/** * @param intPointer * @param length * @return */ @Override public DataBuffer create(IntPointer intPointer, long length) { return new CudaIntDataBuffer(intPointer, IntIndexer.create(intPointer),length); }
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)ShortIndexer.create(new ShortPointer((ShortBuffer)buffer), sizes, strides, false).indexable(this); case DEPTH_INT: return array != null ? (I)IntIndexer.create((int[])array, sizes, strides).indexable(this) : direct ? (I)IntIndexer.create((IntBuffer)buffer, 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)
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); } }
} 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();
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_DOUBLE: return (I)DoubleIndexer.create(new DoublePointer(ptr).capacity(size/8), sizes, strides, direct).indexable(this); case DT_QINT32: case DT_INT32: return (I)IntIndexer.create(new IntPointer(ptr).capacity(size/4), sizes, strides, direct).indexable(this); case DT_BOOL: case DT_QUINT8:
} 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();