Skip to content

Commit

Permalink
use address and length for GDS reads/writes (#8301)
Browse files Browse the repository at this point in the history
Since we want GDS reads/writes to be 4 KiB aligned, sometimes we can't use the `DeviceMemoryBuffer` as is and need to adjust the size written. This change makes the JNI APIs more flexible to accommodate those.

Authors:
  - Rong Ou (https://github.com/rongou)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #8301
  • Loading branch information
rongou authored May 20, 2021
1 parent 3975f10 commit 2a1075e
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions java/src/main/java/ai/rapids/cudf/CuFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,25 @@ public static boolean libraryLoaded() {
* @param path The file path to copy to.
* @param file_offset The file offset from which to write the buffer.
* @param buffer The device buffer to copy from.
* @return The file offset from which the buffer was appended.
*/
public static void writeDeviceBufferToFile(File path, long file_offset,
BaseDeviceMemoryBuffer buffer) {
writeToFile(path.getAbsolutePath(), file_offset, buffer.getAddress(), buffer.getLength());
writeDeviceMemoryToFile(path, file_offset, buffer.getAddress(), buffer.getLength());
}

/**
* Write device memory to a given file path synchronously.
* <p>
* This method is NOT thread safe if the path points to the same file on disk.
*
* @param path The file path to copy to.
* @param file_offset The file offset from which to write the buffer.
* @param address The device memory address to copy from.
* @param length The length to copy.
*/
public static void writeDeviceMemoryToFile(File path, long file_offset, long address,
long length) {
writeToFile(path.getAbsolutePath(), file_offset, address, length);
}

/**
Expand All @@ -95,7 +109,21 @@ public static void writeDeviceBufferToFile(File path, long file_offset,
* @return The file offset from which the buffer was appended.
*/
public static long appendDeviceBufferToFile(File path, BaseDeviceMemoryBuffer buffer) {
return appendToFile(path.getAbsolutePath(), buffer.getAddress(), buffer.getLength());
return appendDeviceMemoryToFile(path, buffer.getAddress(), buffer.getLength());
}

/**
* Append device memory to a given file path synchronously.
* <p>
* This method is NOT thread safe if the path points to the same file on disk.
*
* @param path The file path to copy to.
* @param address The device memory address to copy from.
* @param length The length to copy.
* @return The file offset from which the buffer was appended.
*/
public static long appendDeviceMemoryToFile(File path, long address, long length) {
return appendToFile(path.getAbsolutePath(), address, length);
}

/**
Expand All @@ -109,7 +137,21 @@ public static long appendDeviceBufferToFile(File path, BaseDeviceMemoryBuffer bu
*/
public static void readFileToDeviceBuffer(BaseDeviceMemoryBuffer buffer, File path,
long fileOffset) {
readFromFile(buffer.getAddress(), buffer.getLength(), path.getAbsolutePath(), fileOffset);
readFileToDeviceMemory(buffer.getAddress(), buffer.getLength(), path, fileOffset);
}

/**
* Read a file into device memory synchronously.
* <p>
* This method is NOT thread safe if the path points to the same file on disk.
*
* @param address The device memory address to read into.
* @param length The length to read.
* @param path The file path to copy from.
* @param fileOffset The file offset from which to copy the content.
*/
public static void readFileToDeviceMemory(long address, long length, File path, long fileOffset) {
readFromFile(address, length, path.getAbsolutePath(), fileOffset);
}

private static native void writeToFile(String path, long file_offset, long address, long length);
Expand Down

0 comments on commit 2a1075e

Please sign in to comment.