Skip to content

Commit

Permalink
Add rpath fix to Native Publish PyTorch (#1639)
Browse files Browse the repository at this point in the history
* 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.

* Fix loader path
  • Loading branch information
zachgk authored May 10, 2022
1 parent 12d043e commit 84f43ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/native_publish_pytorch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 12 additions & 0 deletions engines/pytorch/pytorch-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, String> fileStoreMap, String binaryRoot, String url) {
Expand Down

0 comments on commit 84f43ab

Please sign in to comment.