- 3,734,448 Users
- 2,246,973 Discussions
- 7,857,295 Comments
- 380.9K All Categories
- 2.1K Data
- 203 Big Data Appliance
- 1.9K Data Science
- 446.1K Databases
- 220.4K General Database Discussions
- 23 Multilingual Engine
- 506 MySQL Community Space
- 459 NoSQL Database
- 7.7K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 438 SQLcl
- 3.9K SQL Developer Data Modeler
- 185.4K SQL & PL/SQL
- 20.8K SQL Developer
- 291.3K Development
- 6 Developer Projects
- 117 Programming Languages
- 288.1K Development Tools
- 96 DevOps
- 3K QA/Testing
- 645.2K Java
- 18 Java Learning Subscription
- 36.9K Database Connectivity
- 149 Java Community Process
- 104 Java 25
- 22.1K Java APIs
- 137.7K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 12 Java Essentials
- 138 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 195 Java User Groups
- 181 LiveLabs
- 34 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 165 Deutsche Oracle Community
- 1.2K Español
- 1.9K Japanese
- 225 Portuguese
Trying to connect Java and CUDA via JNI
I am having difficulty in creating CUDA (C++ code) act as native function for Java:
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
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 (
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
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.