[Review][Java] Add detailed error message for libcuvs load failure to UnsupportedProvider/UnsupportedOperationExceptions#1316
Conversation
| Object lib = JVM_LoadLibrary$mh.invoke(name, true); | ||
| if (lib != null) { | ||
| // It wasn't a problem with library loading, so undo what we did | ||
| JVM_UnloadLibrary$mh.invoke(lib); |
There was a problem hiding this comment.
@ldematte nice sleuthing. Let's try to use System.localLibrary earlier so that we can get similar improved error messages.
There was a problem hiding this comment.
I like the idea! Less reflection :)
A first test seems to indicate that System.loadLibrary gives a different and less precise message. I'll dig into that.
In any case, trying to load the library before seems best.
There was a problem hiding this comment.
This is very useful, thanks! I was about to raise this exact change (I was trying to wrap ldd within an external process call to do this instead of using reflection, which is much better than what I was trying :-)) while I was chasing down these librmm.so and rapids_logger.so etc. loading failures. +1 to merge!
On a possibly slightly related note, I had to add the following before creating the CuVSResources to make it work. I'll raise another issue for it.
System.loadLibrary("cudart");
…e-error-messages-3 # Conflicts: # java/cuvs-java/pom.xml
…e-error-messages-3 # Conflicts: # java/cuvs-java/src/main/java22/com/nvidia/cuvs/spi/JDKProvider.java
libcuvs load failure to UnsupportedProvider/UnsupportedOperationExceptionslibcuvs load failure to UnsupportedProvider/UnsupportedOperationExceptions
| static void loadLibraries() throws ProviderInitializationException { | ||
| if (!loaded) { | ||
| try { | ||
| LOADER_STRATEGY.loadLibraries(); |
There was a problem hiding this comment.
@chatman I think pre-loading libraries this way will already solve the problem with cudart, but if it does not we can add the System.loadLibrary around here (e.g. in the implementation of loadLibraries), then also call cudaRuntimeGetVersion and compare it with embeddedLibrariesCudaVersion for an additional check.
Or the other way around: use embeddedLibrariesCudaVersion to load a specific version of cudart
(All of this in a follow-up I think)
java/cuvs-java/src/main/java22/com/nvidia/cuvs/spi/NativeDependencyLoader.java
Show resolved
Hide resolved
|
/ok to test 9efc1ea |
|
/merge |
|
Thank you for this change, @ldematte. It's now been merged. |
This PR further extends #1296 and #1314 to give meaningful error messages in case libcuvs fails to load.
The
jextractgenerated bindings we use in cuvs-java useSymbolLookup#libraryLookupto load thecuvs_cdynamic library; this usesRawNativeLibraries#load(see https://github.com/openjdk/jdk/blob/master/src/java.base/share/native/libjava/RawNativeLibraries.c#L58);RawNativeLibraries#loadin turn callsJVM_LoadLibrary.JVM_LoadLibrarydoes a good job to put together a good error message (e.g. callingdlerror, trying to locate and inspect the file for platform mismatch, etc. Unfortunately,RawNativeLibraries#loadcalls it passing false to thethrowExceptionparameter, which means that the detailed error messages are not surfaced.This PR follows the pattern introduced in #1296 and preloads libcuvs (and dependencies) using
JVM_LoadLibrarydirectly withthrowExceptiontrue; preloading it will also cause the OS to look for and load all dependencies.In case of error we can see what's broken in better detail; e.g. if
libcuvs_c.sois present, butlibrmm.sois missing:Fixes #1321