Java Code Examples for org.nd4j.linalg.api.buffer.DataBuffer#TypeEx

The following examples show how to use org.nd4j.linalg.api.buffer.DataBuffer#TypeEx . 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: Int8.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: Uint8.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: Float16.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: NoOp.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 6
Source File: NativeOpExecutioner.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Override
public INDArray thresholdDecode(INDArray encoded, INDArray target) {
    DataBuffer buffer = encoded.data();

    if (buffer.dataType() != DataBuffer.Type.INT)
        throw new ND4JIllegalStateException("thresholdEncoded array should have dataType of INT");

    long compressedLength = buffer.getInt(0);
    long originalLength = buffer.getInt(1);
    float threshold = buffer.getInt(2);

    if (target.lengthLong() != originalLength)
        throw new ND4JIllegalStateException("originalLength ["+ originalLength+"] stored in encoded array doesn't match target length ["+ target.lengthLong()+"]");

    DataBuffer.TypeEx typeDst = AbstractCompressor.getBufferTypeEx(target.data());

    loop.convertTypes(null, DataBuffer.TypeEx.THRESHOLD.ordinal(), buffer.addressPointer(), target.length(), typeDst.ordinal(), target.data().addressPointer());

    return target;
}
 
Example 7
Source File: JCublasNDArrayFactory.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 8
Source File: Int16.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@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 9
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 5 votes vote down vote up
protected static DataBuffer.TypeEx convertType(DataBuffer.Type type) {
    if (type == DataBuffer.Type.HALF) {
        return DataBuffer.TypeEx.FLOAT16;
    } else if (type == DataBuffer.Type.FLOAT) {
        return DataBuffer.TypeEx.FLOAT;
    } else if (type == DataBuffer.Type.DOUBLE) {
        return DataBuffer.TypeEx.DOUBLE;
    } else
        throw new IllegalStateException("Unknown dataType: [" + type + "]");
}
 
Example 10
Source File: JCublasNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public void convertDataEx(DataBuffer.TypeEx typeSrc, Pointer source, DataBuffer.TypeEx typeDst, Pointer target,
                long length) {
    nativeOps.convertTypes(null, typeSrc.ordinal(), source, length, typeDst.ordinal(), target);
}
 
Example 11
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public static DataBuffer.TypeEx getBufferTypeEx(DataBuffer buffer) {
    DataBuffer.Type type = buffer.dataType();

    return convertType(type);
}
 
Example 12
Source File: CpuSparseNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public DataBuffer convertDataEx(DataBuffer.TypeEx typeSrc, DataBuffer source, DataBuffer.TypeEx typeDst) {
    return null;
}
 
Example 13
Source File: JCusparseNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) {
    return null;
}
 
Example 14
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public void convertDataEx(DataBuffer.TypeEx typeSrc, Pointer source, DataBuffer.TypeEx typeDst, Pointer target,
                          long length) {
    nativeOps.convertTypes(null, typeSrc.ordinal(), source, length, typeDst.ordinal(), target);
}
 
Example 15
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public void convertDataEx(DataBuffer.TypeEx typeSrc, DataBuffer source, DataBuffer.TypeEx typeDst,
                          DataBuffer target) {
    convertDataEx(typeSrc, source.addressPointer(), typeDst, target.addressPointer(), target.length());
}
 
Example 16
Source File: CpuThreshold.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length, int elementSize) {
    throw new UnsupportedOperationException();
}
 
Example 17
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected abstract CompressedDataBuffer compressPointer(DataBuffer.TypeEx srcType, Pointer srcPointer, int length,
int elementSize);
 
Example 18
Source File: NDArrayFactory.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param typeSrc
 * @param source
 * @param typeDst
 * @return
 */
DataBuffer convertDataEx(DataBuffer.TypeEx typeSrc, DataBuffer source, DataBuffer.TypeEx typeDst);
 
Example 19
Source File: NDArrayFactory.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param typeSrc
 * @param source
 * @param typeDst
 * @param target
 * @param length
 */
void convertDataEx(DataBuffer.TypeEx typeSrc, Pointer source, DataBuffer.TypeEx typeDst, Pointer target,
                long length);
 
Example 20
Source File: JCusparseNDArrayFactory.java    From nd4j with Apache License 2.0 2 votes vote down vote up
@Override
public void convertDataEx(DataBuffer.TypeEx typeSrc, DataBuffer source, DataBuffer.TypeEx typeDst, DataBuffer target) {

}