1

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.

Sam Faith
  • 175
  • 5

3 Answers3

1

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

deimus
  • 9,565
  • 12
  • 63
  • 107
  • Please can you tell me how I do that, this is the first time when I use linux and cuda. How I get this file ? – Sam Faith Apr 23 '15 at 10:04
  • Use `find` to find a file from command like this `find / -name 'libJCudaRuntime-linux-x86_64.so' ` – deimus Apr 23 '15 at 10:05
  • OK, but how to make a symbolic link to this file or add the path of the directory where I find it to the ldconfig ? – Sam Faith Apr 23 '15 at 12:11
  • For symbolic link perform following `ln -s /lib/libJCudaRuntime-linux-x86_64.so `, ignore for a while the `ldconfig` option. Let me know about the result after symbolic link creation – deimus Apr 23 '15 at 12:13
  • I write this command: ln -s /lib/libJCudaRuntime-linux-x86_64.so but I have this error: bash: syntax error near unexpected token "newline". I'm sorry, but i'm newer with linux. – Sam Faith Apr 23 '15 at 12:27
  • Remove `< ... >` brackets, its not a part of a legal command, it was a notation from me to you. Also you are not pointing to `.so` file. I.e. `ln -s /lib/libJCudaRuntime-linux-x86_64.so /home/faith/JCuda-All-0.4.2-bin-linux-x86_64/PUT_THE_SO_FILE_NAME_HERE` – deimus Apr 23 '15 at 12:33
  • ah sorry. Now I have this error: ln: Unable to create the symbolic link "/home/faith/JCuda-All-0.4.2-bin-linux-x86_64/libJCudaRuntime-linux-x86_64.so ': File exists – Sam Faith Apr 23 '15 at 12:37
  • now you sorry me, I've fixed the parameters order you have to do it like this `ln -s /home/faith/JCuda-All-0.4.2-bin-linux-x86_64/PUT_THE_SO_FILE_NAME_HERE /lib/libJCudaRuntime-linux-x86_64.so ` – deimus Apr 23 '15 at 12:38
  • OK, I do it but the same problem, when I execute my cude program in eclipse I have the same errors. – Sam Faith Apr 23 '15 at 12:45
  • Are you sure the error message is the same, please recheck also copy paste here the listing of your `/lib/` directory filter out unnecessary things I'm interested only in `libJCudaRuntime-linux-x86_64.so` file – deimus Apr 23 '15 at 12:48
  • Yes it is tha same, I beleive that the problem is in the native library. I edit the native lbrary location to the JCuda-All-0.4.2-bin-linux-x86_64 file. ls JCuda-All-0.4.2-bin-linux-x86_64/ CUDPP license.txt jcusparse-0.4.2.jar jcublas-0.4.2.jar libJCublas2-linux-x86_64.so jcuda-0.4.2.jar libJCublas-linux-x86_64.so jcufft-0.4.2.jar libJCudaRuntime-linux-x86_64.so ...... – Sam Faith Apr 23 '15 at 13:01
  • Its unclear what you mean by "I edit the native lbrary location to the JCuda-All-0.4.2-bin-linux-x86_64 file." ? – deimus Apr 23 '15 at 13:12
  • I ceated a project java and I went to the Java Build Path tree item and select the Libraries tab. Click Add External Jars, navigate to the extracted folder of jcuda, and pick jCuda-0.4.2.jar. With the Libraries tab still open, expand the tree for the jCuda-0.4.2.jar wich I added and I clicked on Native library location (none). Then I clicked the Edit button. I asked for a location. I Clicked External Folder and I chose the jcuda extracted folder. And I Clicked OK. THis procedure is it true?! – Sam Faith Apr 23 '15 at 13:17
  • I found this site:http://forum.byte-welt.net/byte-welt-projekte-projects/swogl-jcuda-jocl/jcuda/2972-jcuda-faq-please-read-posting.html#post116058 , which speak about Type 1: UnsatisfiedLinkError: Could not load native library, it mentionned that we can resolve it by adding an argument in EClipse, but I don't know what I must add in the VM Arguments? – Sam Faith Apr 23 '15 at 13:40
  • sorry I need to go home, will try to help you out when I'm home – deimus Apr 23 '15 at 13:42
  • The error message seems to be of **Type 5** (according to the "Ne peut ouvrir le fichier d'objet partagé"). So you have to create a symbolic link to '/usr/lib/libcuda.so.1' in '/usr/lib/nvidia/libcuda.so.1' **OR** add '/usr/lib/nvidia' to your ldconfig. (Sorry, I don't really know what this *means* admittedly - I just added it to the FAQ because I found some hints on the web that this can be the solution when it says "cannot open shared object file" on linux (I'm mainly a Windows user) – Marco13 Apr 30 '15 at 15:58
1

Copy the .so files to lib directory:

$ sudo cp *.so /lib/
spongebob
  • 8,370
  • 15
  • 50
  • 83
0

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

Mysterion
  • 9,050
  • 3
  • 30
  • 52