Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pytorch] Allows to load libstdc++.so.6 form different location #2929

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public static String getLibtorchPath() {

private static void loadLibTorch(LibTorch libTorch) {
Path libDir = libTorch.dir.toAbsolutePath();
if (Files.exists(libDir.resolve("libstdc++.so.6"))) {
String libstd = Utils.getEnvOrSystemProperty("LIBSTDCXX_LIBRARY_PATH");
if (libstd != null) {
try {
logger.info("Loading libstdc++.so.6 from: {}", libstd);
System.load(libstd);
} catch (UnsatisfiedLinkError e) {
logger.warn("Failed Loading libstdc++.so.6 from: {}", libstd);
}
}
}
boolean isCuda = libTorch.flavor.contains("cu");
List<String> deferred =
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class LibUtilsTest {
// Ensure this test run first
public class ALibUtilsTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from LibUtils to ALibUtils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testng use alphabetical order to run the unittest classes. The engine is only initialized once in the JVM. We want make sure this test executed first in all tests.


@BeforeClass
public void setup() {
System.setProperty(
"ai.djl.pytorch.native_helper", "ai.djl.pytorch.integration.LibUtilsTest");
System.setProperty("ai.djl.pytorch.native_helper", ALibUtilsTest.class.getName());
System.setProperty("STDCXX_LIBRARY_PATH", "/usr/lib/non-exists");
System.setProperty("PYTORCH_PRECXX11", "true");
}

@AfterClass
public void teardown() {
System.clearProperty("ai.djl.pytorch.native_helper");
System.clearProperty("LIBSTDCXX_LIBRARY_PATH");
System.clearProperty("PYTORCH_PRECXX11");
}

@Test
Expand Down
Loading