@Override public boolean isView() { return Shape.offset(shapeInformation) > 0 || data().originalDataBuffer() != null; // TODO or if sparseOffset/flags != [0, ..,0] }
/** * This method returns True, if this INDArray instance is attached to some Workspace. False otherwise. * * @return */ @Override public boolean isAttached() { return data.isAttached() || (data.underlyingDataBuffer() != null && data.underlyingDataBuffer().isAttached()) || (data.originalDataBuffer() != null && data.originalDataBuffer().isAttached()); }
if (underlyingBuffer.originalDataBuffer() == null) { this.originalBuffer = underlyingBuffer; this.originalOffset = offset; } else { this.originalBuffer = underlyingBuffer.originalDataBuffer();
@Override public boolean isView() { /* We don't really use Shape offset value anywhere And it's possible to be not a view, and have non-empty originalBuffer */ // length/data.length can be different in case of Threshold conversion return Shape.offset(javaShapeInformation) > 0 || (length() < data().length() && data.dataType() != DataBuffer.Type.INT) || data().originalDataBuffer() != null; }
@Override public void tickHostWrite(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); tickHostWrite(buffer); }
/** * This method should be called to make sure that data on host side is actualized * * @param array */ @Override public void synchronizeHostData(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); synchronizeHostData(buffer); }
@Override public void tickHostWrite(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); tickHostWrite(buffer); }
/** * This method should be called to make sure that data on host side is actualized * * @param array */ @Override public void synchronizeHostData(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); synchronizeHostData(buffer); }
@Override public AllocationPoint getAllocationPoint(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); return getAllocationPoint(buffer); }
@Override public AllocationPoint getAllocationPoint(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); return getAllocationPoint(buffer); }
@Override public void tickDeviceWrite(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); AllocationPoint point = getAllocationPoint(buffer.getTrackingPoint()); point.tickDeviceWrite(); }
@Override public void tickDeviceWrite(INDArray array) { DataBuffer buffer = array.data().originalDataBuffer() == null ? array.data() : array.data().originalDataBuffer(); AllocationPoint point = getAllocationPoint(buffer.getTrackingPoint()); point.tickDeviceWrite(); }
@Override public boolean isView() { /* We don't really use Shape offset value anywhere And it's possible to be not a view, and have non-empty originalBuffer */ // length/data.length can be different in case of Threshold conversion return Shape.offset(javaShapeInformation) > 0 || (length() < data().length() && data.dataType() != DataBuffer.Type.INT) || data().originalDataBuffer() != null; }
@Override public CudaContext prepareActionAllWrite(INDArray... operands) { CudaContext context = (CudaContext) allocator.getDeviceContext().getContext(); int cId = allocator.getDeviceId(); for (INDArray operand : operands) { if (operand == null) continue; Nd4j.getCompressor().autoDecompress(operand); AllocationPoint pointData = allocator.getAllocationPoint(operand); AllocationPoint pointShape = allocator.getAllocationPoint(operand.shapeInfoDataBuffer()); pointData.acquireLock(); if (pointData.getDeviceId() != cId && pointData.getDeviceId() >= 0) { DataBuffer buffer = operand.data().originalDataBuffer() == null ? operand.data() : operand.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer); } if (pointShape.getDeviceId() != cId && pointShape.getDeviceId() >= 0) { ((JCublasNDArray) operand).setShapeInfoDataBuffer( Nd4j.getConstantHandler().relocateConstantSpace(operand.shapeInfoDataBuffer())); } prepareDelayedMemory(operand); allocator.getAllocationPoint(operand).setCurrentContext(context); } return context; }
@Override public CudaContext prepareActionAllWrite(INDArray... operands) { CudaContext context = (CudaContext) allocator.getDeviceContext().getContext(); int cId = allocator.getDeviceId(); for (INDArray operand : operands) { if (operand == null) continue; Nd4j.getCompressor().autoDecompress(operand); AllocationPoint pointData = allocator.getAllocationPoint(operand); AllocationPoint pointShape = allocator.getAllocationPoint(operand.shapeInfoDataBuffer()); pointData.acquireLock(); if (pointData.getDeviceId() != cId && pointData.getDeviceId() >= 0) { DataBuffer buffer = operand.data().originalDataBuffer() == null ? operand.data() : operand.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer); } if (pointShape.getDeviceId() != cId && pointShape.getDeviceId() >= 0) { ((JCublasNDArray) operand).setShapeInfoDataBuffer( Nd4j.getConstantHandler().relocateConstantSpace(operand.shapeInfoDataBuffer())); } prepareDelayedMemory(operand); allocator.getAllocationPoint(operand).setCurrentContext(context); } return context; }
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); } }
initTypeAndSize(); this.wrappedDataBuffer = underlyingBuffer; this.originalBuffer = underlyingBuffer.originalDataBuffer() == null ? underlyingBuffer : underlyingBuffer.originalDataBuffer(); this.length = length; this.offset = offset;
DataBuffer buffer = result.data().originalDataBuffer() == null ? result.data() : result.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer); DataBuffer buffer = operand.data().originalDataBuffer() == null ? operand.data() : operand.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer);
DataBuffer buffer = result.data().originalDataBuffer() == null ? result.data() : result.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer); DataBuffer buffer = operand.data().originalDataBuffer() == null ? operand.data() : operand.data().originalDataBuffer(); allocator.getMemoryHandler().relocateObject(buffer);