LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 628 forks source link

Default CUDA library name is incorrect for linux #884

Closed DJtheRedstoner closed 1 year ago

DJtheRedstoner commented 1 year ago

Version

3.3.2

Platform

Linux x64

JDK

openjdk version "17.0.6" (Ubuntu package)

Module

CUDA

Bug description

The default library name for CUDA is set to nvcuda, which is correct for Windows but on Linux the library name is just cuda. https://github.com/LWJGL/lwjgl3/blob/5ed7786c0461ee7621078fd8a437f8455948ac6a/modules/lwjgl/cuda/src/generated/java/org/lwjgl/cuda/CU.java#L34

Setting -Dorg.lwjgl.cuda.libname=cuda fixes this problem.

Stacktrace or crash log output

[LWJGL] Failed to load a library. Possible solutions:
    a) Install the library or the driver that provides the library.
    b) Ensure that the library is accessible from the system library paths.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
[LWJGL] Enable the SharedLibraryLoader debug mode with -Dorg.lwjgl.util.DebugLoader=true for better diagnostics.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: libnvcuda.so
    at org.lwjgl.system.Library.loadNative(Library.java:346)
    at org.lwjgl.system.Library.loadNative(Library.java:236)
    at org.lwjgl.system.Library.loadNative(Library.java:217)
    at org.lwjgl.system.Library.loadNative(Library.java:431)
    at org.lwjgl.system.Library.loadNative(Library.java:402)
    at org.lwjgl.cuda.CU.<clinit>(CU.java:34)
    at me.djtheredstoner.gitvanity.cuda.CUDATest.main(CUDATest.java:33)
======== Error: Application returned non-zero code 1
Spasi commented 1 year ago

Thanks @DJtheRedstoner, will be fixed in the first 3.3.3 snapshot.

Ealrann commented 4 months ago

Hello, I'm trying to run the HelloCuda, and I encounter exactly the same problem on the v3.3.3 :

[LWJGL] Failed to load a library. Possible solutions:
        a) Install the library or the driver that provides the library.
        b) Ensure that the library is accessible from the system library paths.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
[LWJGL] Enable the SharedLibraryLoader debug mode with -Dorg.lwjgl.util.DebugLoader=true for better diagnostics.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: libnvcuda.so
        at org.lwjgl@3.3.3+5/org.lwjgl.system.Library.loadNative(Library.java:346)
        at org.lwjgl@3.3.3+5/org.lwjgl.system.Library.loadNative(Library.java:236)
        at org.lwjgl@3.3.3+5/org.lwjgl.system.Library.loadNative(Library.java:217)
        at org.lwjgl@3.3.3+5/org.lwjgl.system.Library.loadNative(Library.java:431)
        at org.lwjgl@3.3.3+5/org.lwjgl.system.Library.loadNative(Library.java:402)
        at org.lwjgl.cuda@3.3.3+5/org.lwjgl.cuda.CUDA.isPerThreadDefaultStreamSupported(CUDA.java:76)
        at org.nyaneer/org.xyz.CudaTest.run(CudaTest.java:94)
        at org.nyaneer/org.xyz.XYZApplicationLauncher.main(XYZApplicationLauncher.java:26)

I'm on Archlinux, with cuda package installed. It looks like the library is named "libcuda.so" there

# find / -name "*cuda.so" -type f 2>/dev/null
/opt/cuda/targets/x86_64-linux/lib/stubs/libcuda.so
Ealrann commented 4 months ago

Ok, I got it working, but there is still a problem.

On Archlinux, libcuda.so is located in the package nvidia-utils (and not in package cuda)

But LWJGL 3.3.3 is still looking for a lib named libnvcuda.so. As a workaround, I made a symbolic link: ln -s /usr/lib/libcuda.so /usr/lib/libnvcuda.so