Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Trying to connect Java and CUDA via JNI

User_T542MMay 7 2021

I am having difficulty in creating CUDA (C++ code) act as native function for Java:

First:
I wrote a simple matrix multiplication using CUDA (based on parallel threads).
It runs well as an executable. And also, as a shared library (myCUDAlib.so), when I call it from a C executable.
Since CUDA is C++, I use
extern "C"
{
int kernelEntry()
{
return kernelMatrixMult();
}
}
to encapsulate the CUDA kernel kernelMatrixMult() with a C function kernelEntry() and therefore this becomes my shared C library.
It runs well even for large size matrices, like 1024 x 1024.
==========================================
Next, I tried to let C++ code implement a native function for Java (JNI) which calls the kernel but this does not work.
==========================================
So, I make the C code (which calls the CUDA library) be a shared library instead of executable, and I call it (myClib.so )
It implements a function myJNImethod() which serves as the implementation of my native method for Java. This function simply calls the function kernelEntry() (mentioned above) which calls kernelMatrixMult() that multiplies the two matrices in CUDA
The aim is to get Java to call the matrix multiplication which is executed by the C++ (CUDA) code.
For this, I wrote a simple Java code that loads up the shared library myClib.so and then calls the native method that corresponds to the C function myJNImethod() which is implemented in this library, which as said above, calls the CUDA library.
But this works only for small size matrices (up to 128 x 128). When I try to this Java + CUDA for matrices larger than 128 x 128, I get a segmentation fault.
I therefore suspect that there may be some memory issue.
Does anyone have some experience with hooking up Java and CUDA via JNI?
Is there a problem in the way I encapsulate the CUDA code to appear as C library that contains also the C function that implements the native method?
Is there known memory limitation when using JNI with libraries that are executed on a multi-thread GPU?
I appreciate any leads on this.

Cheers

Comments

Arnoschots-Oracle Apr 22 2020 — edited on Apr 22 2020

Hi,

The "sudo al-config -s" doesn't work on my Autonomous Linux instance.

Command output:

[opc@opsserver ~]$ sudo al-config -s

/sbin/al-config: illegal option -- s

Configure OCI notification service topic OCID:

  Usage:

    al-config -T [topic OCID]

  Options:

    -T [topic OCID] OCI notification service topic OCID

Configure OCI CLI profile:

  Usage:

    al-config -u [user OCID] -t [tenancy OCID] -k [key file]

  Options:

    -u [user OCID] OCI User OCID

    -t [tenancy OCID] OCI Tenancy OCID

    -k [key file] from which we obtaion the API private key

    -p [key passphrase file] from which we obtain API key passphrase. Provide

       this if API private key is encrypted. If not provided, user will be

       prompted to enter passphrase.

1 - 1

Post Details

Added on May 7 2021
0 comments
457 views