Java Code Examples for org.nd4j.linalg.compression.CompressionDescriptor#setOriginalElementSize()
The following examples show how to use
org.nd4j.linalg.compression.CompressionDescriptor#setOriginalElementSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NoOp.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressionType(getCompressionType()); descriptor.setOriginalLength(length * elementSize); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setOriginalElementSize(elementSize); descriptor.setCompressedLength(length * elementSize); descriptor.setNumberOfElements(length); BytePointer ptr = new BytePointer(length * elementSize); val perfD = PerformanceTracker.getInstance().helperStartTransaction(); // this Pointer.memcpy is used intentionally. This method operates on host memory ALWAYS Pointer.memcpy(ptr, srcPointer, length * elementSize); PerformanceTracker.getInstance().helperRegisterTransaction(0, perfD, length * elementSize, MemcpyDirection.HOST_TO_HOST); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); return buffer; }
Example 2
Source File: Float16.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { BytePointer ptr = new BytePointer(length * 2); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(length * 2); descriptor.setOriginalLength(length * elementSize); descriptor.setOriginalElementSize(elementSize); descriptor.setNumberOfElements(length); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.FLOAT16, ptr, length); return buffer; }
Example 3
Source File: Uint8.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { BytePointer ptr = new BytePointer(length); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(length * 1); descriptor.setOriginalLength(length * elementSize); descriptor.setOriginalElementSize(elementSize); descriptor.setNumberOfElements(length); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.UINT8, ptr, length); return buffer; }
Example 4
Source File: Float8.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { BytePointer ptr = new BytePointer(length); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(length * 1); descriptor.setOriginalLength(length * elementSize); descriptor.setOriginalElementSize(elementSize); descriptor.setNumberOfElements(length); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.FLOAT8, ptr, length); return buffer; }
Example 5
Source File: Int16.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { BytePointer ptr = new BytePointer(length * 2); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(length * 2); descriptor.setOriginalLength(length * elementSize); descriptor.setOriginalElementSize(elementSize); descriptor.setNumberOfElements(length); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.INT16, ptr, length); return buffer; }
Example 6
Source File: Int8.java From nd4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) { BytePointer ptr = new BytePointer(length); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(length * 1); descriptor.setOriginalLength(length * elementSize); descriptor.setOriginalElementSize(elementSize); descriptor.setNumberOfElements(length); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); Nd4j.getNDArrayFactory().convertDataEx(srcType, srcPointer, DataBuffer.TypeEx.INT8, ptr, length); return buffer; }
Example 7
Source File: NoOp.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override protected CompressedDataBuffer compressPointer(DataTypeEx srcType, Pointer srcPointer, int length, int elementSize) { CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressionType(getCompressionType()); descriptor.setOriginalLength(length * elementSize); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setOriginalElementSize(elementSize); descriptor.setCompressedLength(length * elementSize); descriptor.setNumberOfElements(length); BytePointer ptr = new BytePointer(length * elementSize); val perfD = PerformanceTracker.getInstance().helperStartTransaction(); // this Pointer.memcpy is used intentionally. This method operates on host memory ALWAYS Pointer.memcpy(ptr, srcPointer, length * elementSize); PerformanceTracker.getInstance().helperRegisterTransaction(0, perfD, length * elementSize, MemcpyDirection.HOST_TO_HOST); CompressedDataBuffer buffer = new CompressedDataBuffer(ptr, descriptor); return buffer; }
Example 8
Source File: CudaFlexibleThreshold.java From nd4j with Apache License 2.0 | 5 votes |
@Override public DataBuffer compress(DataBuffer buffer) { INDArray temp = Nd4j.createArrayFromShapeBuffer(buffer, Nd4j.getShapeInfoProvider().createShapeInformation(new int[]{1, (int) buffer.length()})); double max = temp.amaxNumber().doubleValue(); int cntAbs = temp.scan(Conditions.absGreaterThanOrEqual(max - (max * threshold))).intValue(); long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 3; // first 3 elements contain header IntPointer pointer = new IntPointer(compressedLength); pointer.put(0, cntAbs); pointer.put(1, (int) buffer.length()); pointer.put(2, Float.floatToIntBits(threshold)); // please note, this value will be ovewritten anyway CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(getBufferTypeEx(buffer), buffer.addressPointer(), DataBuffer.TypeEx.FTHRESHOLD, pointer, buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return cbuff; }
Example 9
Source File: CpuFlexibleThreshold.java From nd4j with Apache License 2.0 | 5 votes |
@Override public DataBuffer compress(DataBuffer buffer) { INDArray temp = Nd4j.createArrayFromShapeBuffer(buffer, Nd4j.getShapeInfoProvider().createShapeInformation(new int[]{1, (int) buffer.length()}).getFirst()); double max = temp.amaxNumber().doubleValue(); int cntAbs = temp.scan(Conditions.absGreaterThanOrEqual(max - (max * threshold))).intValue(); long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 4; // first 3 elements contain header IntPointer pointer = new IntPointer(compressedLength); pointer.put(0, cntAbs); pointer.put(1, (int) buffer.length()); pointer.put(2, Float.floatToIntBits(threshold)); // please note, this value will be ovewritten anyway pointer.put(3, 0); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(getBufferTypeEx(buffer), buffer.addressPointer(), DataBuffer.TypeEx.FTHRESHOLD, pointer, buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return cbuff; }
Example 10
Source File: CpuThreshold.java From nd4j with Apache License 2.0 | 5 votes |
@Override public DataBuffer compress(DataBuffer buffer) { INDArray temp = Nd4j.createArrayFromShapeBuffer(buffer, Nd4j.getShapeInfoProvider().createShapeInformation(new int[]{1, (int) buffer.length()}).getFirst()); MatchCondition condition = new MatchCondition(temp, Conditions.absGreaterThanOrEqual(threshold)); int cntAbs = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); //log.info("density ratio: {}", String.format("%.2f", cntAbs * 100.0f / buffer.length())); if (cntAbs < 2) return null; long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 4; // first 3 elements contain header IntPointer pointer = new IntPointer(compressedLength); pointer.put(0, cntAbs); pointer.put(1, (int) buffer.length()); pointer.put(2, Float.floatToIntBits(threshold)); pointer.put(3, 0); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(getBufferTypeEx(buffer), buffer.addressPointer(), DataBuffer.TypeEx.THRESHOLD, pointer, buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return cbuff; }
Example 11
Source File: CpuFlexibleThreshold.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public DataBuffer compress(DataBuffer buffer) { INDArray temp = Nd4j.createArrayFromShapeBuffer(buffer, Nd4j.getShapeInfoProvider().createShapeInformation(new long[]{1, buffer.length()}, DataType.INT).getFirst()); double max = temp.amaxNumber().doubleValue(); int cntAbs = temp.scan(Conditions.absGreaterThanOrEqual(max - (max * threshold))).intValue(); long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 4; // first 3 elements contain header IntPointer pointer = new IntPointer(compressedLength); pointer.put(0, cntAbs); pointer.put(1, (int) buffer.length()); pointer.put(2, Float.floatToIntBits(threshold)); // please note, this value will be ovewritten anyway pointer.put(3, 0); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(getBufferTypeEx(buffer), buffer.addressPointer(), DataTypeEx.FTHRESHOLD, pointer, buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return cbuff; }
Example 12
Source File: CpuThreshold.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public DataBuffer compress(DataBuffer buffer) { INDArray temp = Nd4j.createArrayFromShapeBuffer(buffer, Nd4j.getShapeInfoProvider().createShapeInformation(new long[]{1, buffer.length()}, buffer.dataType()).getFirst()); MatchCondition condition = new MatchCondition(temp, Conditions.absGreaterThanOrEqual(threshold)); int cntAbs = Nd4j.getExecutioner().exec(condition).getInt(0); //log.info("density ratio: {}", String.format("%.2f", cntAbs * 100.0f / buffer.length())); if (cntAbs < 2) return null; long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 4; // first 3 elements contain header IntPointer pointer = new IntPointer(compressedLength); pointer.put(0, cntAbs); pointer.put(1, (int) buffer.length()); pointer.put(2, Float.floatToIntBits(threshold)); pointer.put(3, 0); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm(getDescriptor()); descriptor.setCompressionType(getCompressionType()); CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(getBufferTypeEx(buffer), buffer.addressPointer(), DataTypeEx.THRESHOLD, pointer, buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return cbuff; }
Example 13
Source File: NativeOpExecutioner.java From nd4j with Apache License 2.0 | 4 votes |
@Override public INDArray thresholdEncode(INDArray input, double threshold, Integer boundary) { MatchCondition condition = new MatchCondition(input, Conditions.absGreaterThanOrEqual(threshold)); int cntAbs = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); if (cntAbs < 2) return null; if (boundary != null) cntAbs = Math.min(cntAbs, boundary); DataBuffer buffer = input.data(); long originalLength = buffer.length() * Nd4j.sizeOfDataType(buffer.dataType()); int compressedLength = cntAbs + 4; // first 3 elements contain header DataBuffer encodedBuffer = Nd4j.getMemoryManager().getCurrentWorkspace() == null ? Nd4j.getDataBufferFactory().createInt(4+cntAbs, false) : Nd4j.getDataBufferFactory().createInt(4+cntAbs, false, Nd4j.getMemoryManager().getCurrentWorkspace()); encodedBuffer.put(0, cntAbs); encodedBuffer.put(1, (int) buffer.length()); encodedBuffer.put(2, Float.floatToIntBits((float) threshold)); // format id encodedBuffer.put(3, ThresholdCompression.FLEXIBLE_ENCODING); CompressionDescriptor descriptor = new CompressionDescriptor(); descriptor.setCompressedLength(compressedLength * 4); // sizeOf(INT) descriptor.setOriginalLength(originalLength); descriptor.setOriginalElementSize(Nd4j.sizeOfDataType(buffer.dataType())); descriptor.setNumberOfElements(buffer.length()); descriptor.setCompressionAlgorithm("THRESHOLD"); descriptor.setCompressionType(CompressionType.LOSSLESS); //CompressedDataBuffer cbuff = new CompressedDataBuffer(pointer, descriptor); Nd4j.getNDArrayFactory().convertDataEx(AbstractCompressor.getBufferTypeEx(buffer), buffer.addressPointer(), DataBuffer.TypeEx.THRESHOLD, encodedBuffer.addressPointer(), buffer.length()); Nd4j.getAffinityManager().tagLocation(buffer, AffinityManager.Location.HOST); return Nd4j.createArrayFromShapeBuffer(encodedBuffer, input.shapeInfoDataBuffer()); }