Skip to content

Commit

Permalink
[Split Build] Fix libtorch_python RPATH (#129088)
Browse files Browse the repository at this point in the history
In the split build we end up with an incorrect RPATH for `libtorch_python.so`. This PR fixes said RPATH.

What the rpath should look like:
```
sahanp@devgpu086 ~/pytorch ((636de71c…))> objdump -p ~/main_so_files/libtorch_python.so | grep "RPATH"                        (pytorch-3.10)
  RPATH                /lib/intel64:/lib/intel64_win:/lib/win-x64:/home/sahanp/pytorch/build/lib:/home/sahanp/.conda/envs/pytorch-3.10/lib:
```

Before

```
sahanp@devgpu086 ~/pytorch ((636de71c…))> objdump -p ~/split_so_files/libtorch_python.so | grep "RPATH"                       (pytorch-3.10)
  RPATH                /home/sahanp/pytorch/torch/lib:/home/sahanp/pytorch/build/lib:
```

After
```
sahanp@devgpu086 ~/pytorch ((636de71c…))> objdump -p build/lib/libtorch_python.so | grep "RPATH"                              (pytorch-3.10)
  RPATH                /lib/intel64:/lib/intel64_win:/lib/win-x64:/home/sahanp/pytorch/build/lib:/home/sahanp/pytorch/torch/lib:/home/sahanp/.conda/envs/pytorch-3.10/lib:
```

Testing that this works is in the above PR. Similarly, after running ciflow/binaries the output of objdump -p should not change https://www.diffchecker.com/14PRmCNz/ (checked manywheel py 3.10 cuda 12.1)
Pull Request resolved: #129088
Approved by: https://github.com/malfet
  • Loading branch information
PaliC authored and pytorchmergebot committed Jun 21, 2024
1 parent c008488 commit 2b1b055
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,29 @@ jobs:
build-environment: linux-focal-cuda12.1-py3.10-gcc9-experimental-split-build
docker-image: ${{ needs.linux-focal-cuda12_1-py3_10-gcc9-experimental-split-build.outputs.docker-image }}
test-matrix: ${{ needs.linux-focal-cuda12_1-py3_10-gcc9-experimental-split-build.outputs.test-matrix }}

linux-focal-py3_12-clang10-experimental-split-build:
name: linux-focal-py3.12-clang10-experimental-split-build
uses: ./.github/workflows/_linux-build-label.yml
with:
use_split_build: True
build-environment: linux-focal-py3.12-clang10
docker-image-name: pytorch-linux-focal-py3.12-clang10
test-matrix: |
{ include: [
{ config: "default", shard: 1, num_shards: 3, runner: "linux.2xlarge" },
{ config: "default", shard: 2, num_shards: 3, runner: "linux.2xlarge" },
{ config: "default", shard: 3, num_shards: 3, runner: "linux.2xlarge" },
{ config: "dynamo", shard: 1, num_shards: 3, runner: "linux.2xlarge" },
{ config: "dynamo", shard: 2, num_shards: 3, runner: "linux.2xlarge" },
{ config: "dynamo", shard: 3, num_shards: 3, runner: "linux.2xlarge" },
]}
linux-focal-py3_12-clang10-experimental-split-build-test:
name: linux-focal-py3.12-clang10-experimental-split-build
uses: ./.github/workflows/_linux-test.yml
needs: linux-focal-py3_12-clang10-experimental-split-build
with:
build-environment: linux-focal-py3.12-clang10-experimental-split-build
docker-image: ${{ needs.linux-focal-py3_12-clang10-experimental-split-build.outputs.docker-image }}
test-matrix: ${{ needs.linux-focal-py3_12-clang10-experimental-split-build.outputs.test-matrix }}
timeout-minutes: 600
10 changes: 10 additions & 0 deletions torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ endif()


add_library(torch_python SHARED ${TORCH_PYTHON_SRCS})

if(CAFFE2_USE_MKL AND BUILD_LIBTORCHLESS)

# Use the RPATH of the linked libraries
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# we need to explicitly link caffe2::mkl in order to have the
# correct RPATH in torch_python for the split build
target_link_libraries(torch_python PRIVATE caffe2::mkl)
endif()

add_dependencies(torch_python onnx_proto)
# Avoid numpy for the DEPLOY build
if(USE_NUMPY)
Expand Down

0 comments on commit 2b1b055

Please sign in to comment.