[linux/eclipse]Error while loading native library with base name "JCudaDriver"

Hi,
I’m creating my first program with JCuda library in Linux with Eclipse IDE.
I installed driver, toolkit, sdk and set environment variables.
I copied the example JCudaDriverCubinSample, and add to the build path the Jars from JCuda-All-0.3.2a-bin-linux-x86.
when I execute this example the result is:

Error while loading native library with base name „JCudaDriver“
Operating system name: Linux
Architecture : i386
Architecture bit size: 32
Exception in thread „main“ java.lang.UnsatisfiedLinkError: Could not load native library
at jcuda.LibUtils.loadLibrary(LibUtils.java:79)
at jcuda.driver.JCudaDriver.(JCudaDriver.java:113)
at executable.JCudaDriverCubinSample.main(JCudaDriverCubinSample.java:25)

so I looked at the class jcuda.LibUtils:

 /**
     * Loads the specified library. The full name of the library
     * is created by calling {@link LibUtils#createLibName(String)}
     * with the given argument.
     *
     * @param baseName The base name of the library
     * @throws UnsatisfiedLinkError if the native library can
     * not be loaded.
     */

    public static void loadLibrary(String baseName)
    {
        try
        {
            System.loadLibrary(LibUtils.createLibName(baseName));
        }
        catch (Throwable t)
        {
            System.err.println("Error while loading native library with base name \""+baseName+"\"");
            System.err.println("Operating system name: "+System.getProperty("os.name"));
            System.err.println("Architecture         : "+System.getProperty("os.arch"));
            System.err.println("Architecture bit size: "+System.getProperty("sun.arch.data.model"));
            throw new UnsatisfiedLinkError("Could not load native library");
        }
    }

    /**
     * Creates the name for the native library with the given base
     * name for the current operating system and architecture.
     * The resulting name will be of the form<br />
     * baseName-OSType-ARCHType<br />
     * where OSType and ARCHType are the <strong>lower case</strong> Strings
     * of the respective enum constants. Example: <br />
     * JCuda-windows-x86<br />
     *
     * @param baseName The base name of the library
     * @return The library name
     */
    public static String createLibName(String baseName)
    {
        OSType osType = calculateOS();
        ARCHType archType = calculateArch();
        String libName = baseName;
        libName += "-" + osType.toString().toLowerCase(Locale.ENGLISH);
        libName += "-" + archType.toString().toLowerCase(Locale.ENGLISH);
        return libName;
    }

I think when in lib JCudaDriver it calls LibUtils.loadLibrary(„JCudaDriver“) , System.loadLibrary() try to load „JCudaDriver-linux-x86“.

but where is this library? and why the program (or jcuda library) can’t find it?

thanks for the help :slight_smile:

Hello,

It will try to load the library “libJCudaDriver-linux-x86**.so**” (the prefix and the extension are automatically added by the Java “loadLibrary” function). This file is included in the JCuda archive. All the .so-Files from the ZIP should be located in the root directory of the project, or alternatively, in a path that may be specified as the “java.library.path”.

(There recently had been some problems with the linux builds. According to some feedback that I received via mail, the 32bit libraries should work now, but in one thread here in the forum, some problems still had been reported… Hope it works for you…)

bye
Marco

Thanks for the answer, now I add the position where the file .os are at the native library path of JCuca.jar (in eclipse, see image)
Error is the same, but the details of message are:
/home/luca/workspace/cuda/prova1/CudaProva/JCuda-All-0.3.2a-bin-linux-x86/libJCudaDriver-linux-x86.so: libcuda.so.1: impossibile aprire il file oggetto condiviso: Nessun file o directory (cannot open shared object file: no such file or directory)

where can I find libcuda.so.1 ?
in /usr/local/cuda/lib I can’t find it…

thx
Luca

I found libcuda.so.1 in /usr/lib/nvidia-current,
have I to add this path in $LD_LIBRARY_PATH or in other library path?

I can’t remember having seen the directory “nvidia-current” before - but this may be because I don’t have a real, CUDA-capable Linux PC: The results of a quick websearch look like it may be the “standard” directory for the driver. The websearch also brought up this thread where someone mentioned that he…
had to manually create a symbolic link to /usr/lib/nvidia-current/libcuda.so in /usr/local/cuda/lib64

So (with my rather limited Linux knowledge) I think there are two things that you could try:

  • Adding the “nvidia-current” directory the to the LD_LIBRARY_PATH
  • Creating a “symbolic link” as described above: IN the /local/cuda/lib directory (which presumably already is in the LD_LIBRARY_PATH), TO the libcuda.so file.

If it does not work, I’ll try to find someone who has used the 32bit binaries successfully, maybe he can help.

thanks,:slight_smile: now I’m working at the university lab and on a linux 64 bit where cuda sdk examples works fine.
now I’ve another error:

/usr/lib/jvm/java-6-sun-1.6.0.22/bin/java: symbol lookup error: ~/JCuda-All-0.3.2a-bin-linux-x86_64/libJCudaDriver-linux-x86_64.so: undefined symbol: cuInit.

JCudaDriver.cuInit(0); is the first function the example calls, if I comment this line the error is on the second function
JCudaDriver.cuDeviceGet(dev, 0); and so on…

perhaps there’s an link error, but I can’t make a simbolic link because on this pc /usr/lib/nvidia-current is empty…
Do you know the directory where cuda drivers could be (in particular libcuda.so )?
Or do you have another idea to resolve this error?

sorry, I find it:
$ whereis libcuda.so
libcuda: /usr/lib/libcuda.so /usr/lib64/libcuda.so

I will do more testing this afternoon

Sorry, the version 0.3.2a of the Linux64 binaries seems to be broken (I’ve contacted the contributor who provided these libraries, but he did not respond :frowning: I’ll remove these from the Website ASAP).

But the Linux64 binaries of version 0.3.2 should work. (The ‚a‘ version only contained a small bugfix for Win64 systems with >2GB of GPU memory).

thank, now with lib 0.3.2 it works!
I run JCudaDriverCubinSample, the result is: “Test FAILED” :twisted:

the test is

// Verify the result
        boolean passed = true;
        for(int i = 0; i < numThreads; i++)
        {
            float expected = 0;
            for(int j = 0; j < size; j++)
            {
                expected += hostInput**[j];
            }
            if (Math.abs(hostOutput** - expected) > 1e-5)
            {
            	System.out.println("host:"+hostOutput**+" expected:"+expected);  //I add this line
                passed = false;
                break;
            }
        }
        System.out.println("Test "+(passed?"PASSED":"FAILED"));

it prints:

host:0.0 expected:8128.0
Test FAILED

Great to hear that - this should have been the largest hurdle :wink:

Did you use the CUBIN file from the website? Note that this is for 32 bit (and I think it’s even specific for the GPU architecture). You may try compiling it specifically for your architecture, e.g.
nvcc -m64 -cubin input.cu -o output.cubin

You can also specifiy the architecture of your GPU, like
nvcc -m64 -arch sm_20 -cubin input.cu -o output.cubin
for GPUs with compute capability 2.0. (This is also explained in detail in the NVCC documentation)

You may also want to have a look at the KernelLauncher class from the Utilities section, it makes the kernel invocation itself a little bit easier.

EDIT: Oh, I just noticed that the compilation in the JCudaDriverCubinSample by default adds the „-arch sm_11“ argument for GPUs with Compute Capability 1.1 - you could change this to match the Compute Capability of your GPU. This should also be updated in the sample… I definitely have to allocate some time for these cleanups and updates…

with sm_20: „test PASSED“ :smiley:

now it works fine!! ::banana great, thanks a lot for your help