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

Add Initial Java Support for GDS to KvikIO #396

Open
wants to merge 32 commits into
base: branch-24.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
83044ff
Initial commit
aslobodaNV Jun 25, 2024
62649e6
Update documentation to better flash out how to compile and run the e…
aslobodaNV Jun 25, 2024
161b260
code touchups and Readme update
aslobodaNV Jun 25, 2024
30aa3dc
Update README with markdown formatting. Improve instructions and linkage
aslobodaNV Jun 26, 2024
299bdb6
Add initial maven setup, needs to be debugged
aslobodaNV Jul 12, 2024
1162efc
Update maven build to properly generate shared library
aslobodaNV Jul 12, 2024
3f29546
Merge branch 'branch-24.10' into add_initial_java_support
jakirkham Jul 24, 2024
b3dd38f
Merge branch 'rapidsai:branch-24.10' into add_initial_java_support
aslobodaNV Sep 4, 2024
fe91427
Fix pre-commit issues
aslobodaNV Sep 4, 2024
4ad08c6
move example to be a test, update pom and dependencies to support CI …
aslobodaNV Sep 4, 2024
83875b6
pre-commit fixes
aslobodaNV Sep 4, 2024
4120e4c
add github workflow items
aslobodaNV Sep 4, 2024
888d6a7
Updating workflows
aslobodaNV Sep 18, 2024
d337a16
Merge branch 'branch-24.10' into add_initial_java_support
aslobodaNV Sep 18, 2024
833ad32
Formatting inconsistencies
aslobodaNV Sep 18, 2024
93598a8
Merge remote-tracking branch 'upstream/branch-24.12' into add_initial…
aslobodaNV Oct 1, 2024
661fcce
Update yaml files based on CR feedback, update versions to 24.12 from…
aslobodaNV Oct 1, 2024
7610edb
Fix needs and permissions.
bdice Oct 1, 2024
3eb3daa
Remove test_python_legate.
bdice Oct 1, 2024
13b9a05
Merge branch 'branch-24.12' into add_initial_java_support
bdice Oct 1, 2024
e3f8448
Merge branch 'add_initial_java_support' of github.com:aslobodaNV/kvik…
bdice Oct 1, 2024
fa749a3
Update java/pom.xml
aslobodaNV Oct 2, 2024
222426c
Update package for java bindings.
aslobodaNV Oct 11, 2024
c704108
Use cmake instead of explicit nvcc command
aslobodaNV Oct 11, 2024
69b6d39
Merge remote-tracking branch 'upstream/branch-24.12' into add_initial…
aslobodaNV Oct 11, 2024
40a588f
Merge branch 'branch-24.12' into add_initial_java_support
aslobodaNV Oct 18, 2024
fabd3c1
Fix style issues and missing license
aslobodaNV Oct 18, 2024
c29ac7b
Fix CMakeLists style issues
aslobodaNV Oct 18, 2024
157867f
Update dependencies to try and fix container build
aslobodaNV Oct 18, 2024
acc6777
Just add make not ninja
aslobodaNV Oct 18, 2024
cfa183a
Fix some of the build and container issues, linking issues remain
aslobodaNV Oct 22, 2024
2d41f10
Merge remote-tracking branch 'upstream/branch-24.12' into add_initial…
aslobodaNV Oct 22, 2024
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
51 changes: 27 additions & 24 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>bindings.kvikio</groupId>
<groupId>ai.rapids.kvikio</groupId>
<artifactId>cufile</artifactId>
<version>24.12.0-SNAPSHOT</version>

<name>cufile</name>
<description>
This project provides java bindings for the GPUDirect Storage cufile library, enabling the GPU to load and
This project provides Java bindings for the GPUDirect Storage cufile library, enabling the GPU to load and
save large amounts of data to and from persistent storage. This is still a work in progress so some APIs may change.
</description>
<url>http://ai.rapids</url>
Expand All @@ -21,18 +21,22 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<junit.version>5.4.2</junit.version>
<jcuda.version>12.0.0</jcuda.version>
<cmake.version>3.16.3-b2</cmake.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jcuda</groupId>
<artifactId>jcuda</artifactId>
<version>12.0.0</version>
<version>${jcuda.version}</version>
<scope>test</scope>
</dependency>
aslobodaNV marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>org.jcuda</groupId>
<artifactId>jcuda-natives</artifactId>
<version>12.0.0</version>
<version>${jcuda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -113,31 +117,30 @@
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<groupId>com.googlecode.cmake-maven-project</groupId>
<artifactId>cmake-maven-plugin</artifactId>
<version>${cmake.version}</version>
<executions>
<execution>
<id>compile-native-code</id>
<phase>generate-sources</phase>
<id>cmake-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourcePath>${project.basedir}/src/main/native</sourcePath>
<targetPath>${project.build.directory}/native-build</targetPath>
<options>
<option>-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${project.build.directory}</option>
</options>
</configuration>
</execution>
<execution>
<id>cmake-compile</id>
<goals>
<goal>run</goal>
<goal>compile</goal>
</goals>
<configuration>
<target>
<!-- Compile native code using nvcc -->
<exec executable="/usr/local/cuda/bin/nvcc">
<arg value="-shared"/>
<arg value="-o"/>
<arg value="${project.build.directory}/libCuFileJNI.so"/>
<arg value="-I/usr/local/cuda/include/"/>
<arg value="-I/usr/lib/jvm/java-21-openjdk-amd64/include/"/>
<arg value="-I/usr/lib/jvm/java-21-openjdk-amd64/include/linux"/>
<arg value="${project.basedir}/src/main/native/src/CuFileJni.cpp"/>
<arg value="--compiler-options"/>
<arg value="-fPIC"/>
<arg value="-lcufile"/>
</exec>
</target>
<projectDirectory>${project.build.directory}/native-build</projectDirectory>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

public class CuFile {
private static boolean initialized = false;
Expand All @@ -34,7 +34,7 @@ static synchronized void initialize() {
}));
initialized = true;
} catch (Throwable t) {
System.out.println("could not load cufile jni library");
System.out.println("could not load cufile jni library:"+ t.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

final class CuFileDriver implements AutoCloseable {
private final long pointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

abstract class CuFileHandle implements AutoCloseable {
private final long pointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

public final class CuFileReadHandle extends CuFileHandle {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

public final class CuFileWriteHandle extends CuFileHandle {

Expand Down
21 changes: 21 additions & 0 deletions java/src/main/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAPIDS requires a minimum of cmake 3.26.4 right now, I think. Can we set a higher minimum for these bindings? I don't think we will ever test with a CMake version as old as 3.10.


project(CuFileJNI LANGUAGES CXX CUDA)

find_package(CUDA REQUIRED)

find_package(JNI REQUIRED)

add_library(CuFileJNI SHARED
src/CuFileJni.cpp
)

set_source_files_properties(src/CuFileJni.cpp PROPERTIES LANGUAGE CUDA)

target_include_directories(CuFileJNI PRIVATE
${CUDA_INCLUDE_DIRS}
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
)

target_link_libraries(CuFileJNI cufile)
14 changes: 7 additions & 7 deletions java/src/main/native/src/CuFileJni.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused by these bindings. They look to be bindings to the cufile API, and not the kvikio API. Is that deliberate? It seems like if so one will have to replicate a lot of the implementation that already exists in kvikio here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, these are directly bound to the underlying cufile API. In the initial discussions with the rest of the GDS team there was some concern about potential performance overhead of Java bindings -> C++ bindings -> C API. I have not investigated the overhead yet, but definitely see the benefit you are suggesting to sharing one underlying set of bindings. If you don't mind, I will add an issue to my backlog to investigate the potential performance differences and, if they are minimal, update these to point to the C++ bindings at a later date.

Copy link
Member

@madsbk madsbk Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let's continue with raw java bindings for now.

Side note, I would be very surprised if the basic C++ API introduce any significant overhead. E.g. the overhead of calling read() vs. calling cuFileRead() is tiny.

Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class cufile_driver {
extern "C" {
#include <jni.h>

JNIEXPORT jlong JNICALL Java_bindings_kvikio_cufile_CuFileDriver_create(JNIEnv* env, jclass)
JNIEXPORT jlong JNICALL Java_ai_rapids_kvikio_cufile_CuFileDriver_create(JNIEnv* env, jclass)
{
try {
return reinterpret_cast<jlong>(new cufile_driver());
Expand All @@ -179,29 +179,29 @@ JNIEXPORT jlong JNICALL Java_bindings_kvikio_cufile_CuFileDriver_create(JNIEnv*
}
}

JNIEXPORT void JNICALL Java_bindings_kvikio_cufile_CuFileDriver_destroy(JNIEnv* env,
JNIEXPORT void JNICALL Java_ai_rapids_kvikio_cufile_CuFileDriver_destroy(JNIEnv* env,
jclass,
jlong pointer)
{
delete reinterpret_cast<cufile_driver*>(pointer);
}

JNIEXPORT void JNICALL Java_bindings_kvikio_cufile_CuFileHandle_destroy(JNIEnv* env,
JNIEXPORT void JNICALL Java_ai_rapids_kvikio_cufile_CuFileHandle_destroy(JNIEnv* env,
jclass,
jlong pointer)
{
delete reinterpret_cast<cufile_file*>(pointer);
}

JNIEXPORT jlong JNICALL Java_bindings_kvikio_cufile_CuFileReadHandle_create(JNIEnv* env,
JNIEXPORT jlong JNICALL Java_ai_rapids_kvikio_cufile_CuFileReadHandle_create(JNIEnv* env,
jclass,
jstring path)
{
auto file = cufile_file::make_reader(env->GetStringUTFChars(path, nullptr));
return reinterpret_cast<jlong>(file.release());
}

JNIEXPORT void JNICALL Java_bindings_kvikio_cufile_CuFileReadHandle_readFile(JNIEnv* env,
JNIEXPORT void JNICALL Java_ai_rapids_kvikio_cufile_CuFileReadHandle_readFile(JNIEnv* env,
jclass,
jlong file_pointer,
jlong device_pointer,
Expand All @@ -214,15 +214,15 @@ JNIEXPORT void JNICALL Java_bindings_kvikio_cufile_CuFileReadHandle_readFile(JNI
file_ptr->read(dev_ptr, size, file_offset, device_offset);
}

JNIEXPORT jlong JNICALL Java_bindings_kvikio_cufile_CuFileWriteHandle_create(JNIEnv* env,
JNIEXPORT jlong JNICALL Java_ai_rapids_kvikio_cufile_CuFileWriteHandle_create(JNIEnv* env,
jclass,
jstring path)
{
auto file = cufile_file::make_writer(env->GetStringUTFChars(path, nullptr));
return reinterpret_cast<jlong>(file.release());
}

JNIEXPORT void JNICALL Java_bindings_kvikio_cufile_CuFileWriteHandle_writeFile(JNIEnv* env,
JNIEXPORT void JNICALL Java_ai_rapids_kvikio_cufile_CuFileWriteHandle_writeFile(JNIEnv* env,
jclass,
jlong file_pointer,
jlong device_pointer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package bindings.kvikio.cufile;
package ai.rapids.kvikio.cufile;

import org.junit.jupiter.api.Test;

Expand Down
Loading