Java Code Examples for com.sun.jna.Native#getDirectBufferPointer()

The following examples show how to use com.sun.jna.Native#getDirectBufferPointer() . 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: MxNDArray.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public ByteBuffer toByteBuffer() {
    Shape sh = getShape();
    DataType dType = getDataType();
    long product = sh.size();
    long len = dType.getNumOfBytes() * product;
    ByteBuffer bb = manager.allocateDirect(Math.toIntExact(len));
    Pointer pointer = Native.getDirectBufferPointer(bb);
    JnaUtils.syncCopyToCPU(getHandle(), pointer, Math.toIntExact(product));
    return bb;
}
 
Example 2
Source File: TestHelper.java    From djl with Apache License 2.0 5 votes vote down vote up
public static Pointer toPointer(int[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
    bb.order(ByteOrder.nativeOrder());
    bb.asIntBuffer().put(arr);
    bb.rewind();
    return Native.getDirectBufferPointer(bb);
}
 
Example 3
Source File: TestHelper.java    From djl with Apache License 2.0 5 votes vote down vote up
public static Pointer toPointer(byte[] buf) {
    ByteBuffer bb = ByteBuffer.allocateDirect(buf.length);
    bb.order(ByteOrder.nativeOrder());
    bb.put(buf);
    bb.rewind();
    return Native.getDirectBufferPointer(bb);
}
 
Example 4
Source File: JnaUtils.java    From djl with Apache License 2.0 4 votes vote down vote up
public static void syncCopyFromCPU(Pointer ndArray, Buffer data, int len) {
    NativeSize size = new NativeSize(len);
    Pointer pointer = Native.getDirectBufferPointer(data);
    checkCall(LIB.MXNDArraySyncCopyFromCPU(ndArray, pointer, size));
}