Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use address and length for GDS reads/writes [skip ci] #8301

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 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,26 @@ 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.
* @deprecated Use writeDeviceMemoryToFile instead.
jlowe marked this conversation as resolved.
Show resolved Hide resolved
*/
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 @@ -93,9 +108,24 @@ public static void writeDeviceBufferToFile(File path, long file_offset,
* @param path The file path to copy to.
* @param buffer The device buffer to copy from.
* @return The file offset from which the buffer was appended.
* @deprecated Use appendDeviceMemoryToFile instead.
*/
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 @@ -106,10 +136,25 @@ public static long appendDeviceBufferToFile(File path, BaseDeviceMemoryBuffer bu
* @param buffer The device buffer to copy into.
* @param path The file path to copy from.
* @param fileOffset The file offset from which to copy the content.
* @deprecated Use readFileToDeviceMemory instead.
*/
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
12 changes: 6 additions & 6 deletions java/src/test/java/ai/rapids/cudf/CuFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private void verifyCopyToFile(File tempFile) {
HostMemoryBuffer dest = HostMemoryBuffer.allocate(16)) {
orig.setLong(0, 123456789);
from.copyFromHostBuffer(orig);
CuFile.writeDeviceBufferToFile(tempFile, 0, from);
CuFile.readFileToDeviceBuffer(to, tempFile, 0);
CuFile.writeDeviceMemoryToFile(tempFile, 0, from.address, from.length);
CuFile.readFileToDeviceMemory(to.address, to.length, tempFile, 0);
dest.copyFromDeviceBuffer(to);
assertEquals(123456789, dest.getLong(0));
}
Expand All @@ -87,17 +87,17 @@ private void verifyAppendToFile(File tempFile) {
HostMemoryBuffer dest = HostMemoryBuffer.allocate(16)) {
orig.setLong(0, 123456789);
from.copyFromHostBuffer(orig);
assertEquals(0, CuFile.appendDeviceBufferToFile(tempFile, from));
assertEquals(0, CuFile.appendDeviceMemoryToFile(tempFile, from.address, from.length));

orig.setLong(0, 987654321);
from.copyFromHostBuffer(orig);
assertEquals(16, CuFile.appendDeviceBufferToFile(tempFile, from));
assertEquals(16, CuFile.appendDeviceMemoryToFile(tempFile, from.address, from.length));

CuFile.readFileToDeviceBuffer(to, tempFile, 0);
CuFile.readFileToDeviceMemory(to.address, to.length, tempFile, 0);
dest.copyFromDeviceBuffer(to);
assertEquals(123456789, dest.getLong(0));

CuFile.readFileToDeviceBuffer(to, tempFile, 16);
CuFile.readFileToDeviceMemory(to.address, to.length, tempFile, 16);
dest.copyFromDeviceBuffer(to);
assertEquals(987654321, dest.getLong(0));
}
Expand Down