From 26cf01efb700e9077b28ed5a8832a9a8b829712e Mon Sep 17 00:00:00 2001 From: Zach Kimberg Date: Mon, 9 May 2022 18:26:36 -0700 Subject: [PATCH 1/2] Add rpath fix to Native Publish PyTorch This adds the install name tool fix to downloading the pytorch native libraries. It also updates the gradle script that runs the publish to run on osx which has the fixer tool instead of osx. It does have a minor breaking aspect as now the publish must be run from osx. I did add an early error in case it is run from a different os. --- .github/workflows/native_publish_pytorch.yml | 2 +- engines/pytorch/pytorch-native/build.gradle | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/native_publish_pytorch.yml b/.github/workflows/native_publish_pytorch.yml index d69748d30e7..2ba5e67d6b9 100644 --- a/.github/workflows/native_publish_pytorch.yml +++ b/.github/workflows/native_publish_pytorch.yml @@ -10,7 +10,7 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: macos-latest steps: - uses: actions/checkout@v2 diff --git a/engines/pytorch/pytorch-native/build.gradle b/engines/pytorch/pytorch-native/build.gradle index 77fb518402a..dcaf02dfb71 100644 --- a/engines/pytorch/pytorch-native/build.gradle +++ b/engines/pytorch/pytorch-native/build.gradle @@ -76,6 +76,10 @@ def downloadBuildAndroid(String ver) { } def prepareNativeLib(String binaryRoot, String ver) { + if (!System.properties['os.name'].toLowerCase(Locale.ROOT).contains("mac")) { + throw new GradleException("This command must be run from osx") + } + def officialPytorchUrl = "https://download.pytorch.org/libtorch" def aarch64PytorchUrl = "https://djl-ai.s3.amazonaws.com/publish/pytorch" String cu11 @@ -102,6 +106,14 @@ def prepareNativeLib(String binaryRoot, String ver) { copyNativeLibToOutputDir(files, binaryRoot, officialPytorchUrl) copyNativeLibToOutputDir(aarch64Files, binaryRoot, aarch64PytorchUrl) + + + exec { + commandLine 'install_name_tool', '-add_rpath', '"@loader_path"', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch_cpu.dylib" + } + exec { + commandLine 'install_name_tool', '-add_rpath', '"@loader_path"', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch.dylib" + } } def copyNativeLibToOutputDir(Map fileStoreMap, String binaryRoot, String url) { From e9c4689e3f5da917ef3ae905fbdf88806b48af3a Mon Sep 17 00:00:00 2001 From: Zach Kimberg Date: Mon, 9 May 2022 19:52:16 -0700 Subject: [PATCH 2/2] Fix loader path --- engines/pytorch/pytorch-native/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/pytorch/pytorch-native/build.gradle b/engines/pytorch/pytorch-native/build.gradle index dcaf02dfb71..66e3e791728 100644 --- a/engines/pytorch/pytorch-native/build.gradle +++ b/engines/pytorch/pytorch-native/build.gradle @@ -109,10 +109,10 @@ def prepareNativeLib(String binaryRoot, String ver) { exec { - commandLine 'install_name_tool', '-add_rpath', '"@loader_path"', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch_cpu.dylib" + commandLine 'install_name_tool', '-add_rpath', '@loader_path', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch_cpu.dylib" } exec { - commandLine 'install_name_tool', '-add_rpath', '"@loader_path"', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch.dylib" + commandLine 'install_name_tool', '-add_rpath', '@loader_path', "${binaryRoot}/cpu/osx-x86_64/native/lib/libtorch.dylib" } }