Sam Faith
Sam Faith

Reputation: 175

Error when executing a jcuda program in eclipse

I'm new with JCuda. I try to write a simple example in Eclipse on Linux. I have this error, but I haven't understand what it means. Here the code:

 import jcuda.Pointer;
 import jcuda.runtime.JCuda;
 public class cudaTest {
 public static 
 void main(String[] args) {
    Pointer pointer = new Pointer();
    JCuda.cudaMalloc(pointer, 4);
    System.out.println("Pointer: " + pointer);
    JCuda.cudaFree(pointer);
 }
}

I add the Jcuda.jar from the Java Build Path, and edit the Native library location by selecting the extracted JCuda file. The error is:

Error while loading native library "JCudaRuntime-linux-x86_64" with base name "JCudaRuntime"
Operating system name: Linux
Architecture         : amd64
Architecture bit size: 64
Stack trace from the attempt to load the library as a resource:
java.lang.NullPointerException: No resource found with name '/lib/libJCudaRuntime-linux-x86_64.so'
    at jcuda.LibUtils.loadLibraryResource(LibUtils.java:151)
    at jcuda.LibUtils.loadLibrary(LibUtils.java:83)
    at jcuda.runtime.JCuda.initialize(JCuda.java:303)
    at jcuda.runtime.JCuda.<clinit>(JCuda.java:290)
    at cudaTest.main(cudaTest.java:8)
Stack trace from the attempt to load the library as a file:
java.lang.UnsatisfiedLinkError: /home/Faith/JCuda-All-0.4.2-bin-linux-x86_64/libJCudaRuntime-linux-x86_64.so: libcudart.so.4: Ne peut ouvrir le fichier d'objet partagé: Aucun fichier ou dossier de ce type
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at jcuda.LibUtils.loadLibrary(LibUtils.java:94)
    at jcuda.runtime.JCuda.initialize(JCuda.java:303)
    at jcuda.runtime.JCuda.<clinit>(JCuda.java:290)
    at cudaTest.main(cudaTest.java:8)

Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load the native library
    at jcuda.LibUtils.loadLibrary(LibUtils.java:129)
    at jcuda.runtime.JCuda.initialize(JCuda.java:303)
    at jcuda.runtime.JCuda.<clinit>(JCuda.java:290)
    at cudaTest.main(cudaTest.java:8)

Could tou help me please, I'm really need the solution. Thank you in advance.

Upvotes: 1

Views: 1147

Answers (3)

user3337633
user3337633

Reputation: 11

Copy the .so files to lib directory:

$ sudo cp *.so /lib/

Upvotes: 1

Mysterion
Mysterion

Reputation: 9320

One of the possible idea - is to give a try to my project called Mavenized JCuda https://github.com/MysterionRise/mavenized-jcuda

It's specifically created for the purpose of not fighting against classpath and other problems. It's really easy to use it, all you need to do - is to put needed version of JCuda in pom.xml, then run mvn clean package and then mvn exec:exec.

Full HowTo is available on Github page. Feel free to ask me question about that or raise question about the project

Upvotes: 0

deimus
deimus

Reputation: 9875

Look for libJCudaRuntime-linux-x86_64.so file in your system, and make a symoblic link to /lib/libJCudaRuntime-linux-x86_64.so OR add the path of the directory where you find it to your ldconfig

Upvotes: 1

Related Questions