Skip to content

Set RUNPATH so installed tests can find the required shared libraries - #136627

Closed
kundaMwiza wants to merge 2 commits into
pytorch:mainfrom
graphcore:mwizak/fix-cxx-tests-runpath
Closed

kundaMwiza wants to merge 2 commits into
pytorch:mainfrom
graphcore:mwizak/fix-cxx-tests-runpath

Conversation

@kundaMwiza

@kundaMwiza kundaMwiza commented Sep 25, 2024 •

Copy link
Copy Markdown
Collaborator

This change fixes the RUNPATH of installed c++ tests so that the linker can find the shared libraries they depend on.

For example, currently:

venv/lib/python3.10/site-packages/torch $ ./bin/test_lazy
./bin/test_lazy: error while loading shared libraries: libtorch.so: cannot open shared object file: No such file or directory

@pytorch-bot

pytorch-bot Bot commented Sep 25, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/136627

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b9d88b2 with merge base 60c1433 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Sep 25, 2024
@kundaMwiza

Copy link
Copy Markdown
Collaborator Author

Broken executables found using:

import subprocess
import argparse
import pathlib

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--torch-install-dir",
        type=pathlib.Path,
        default=pathlib.Path(__file__).parent / "third_party" / "pytorch" / "torch",
    )
    args = parser.parse_args()

    out = subprocess.check_output(
        "find -type f -executable",
        cwd=args.torch_install_dir,
        shell=True,
    )

    executables = out.decode(encoding="utf-8").splitlines()
    problematic_executables: str = []
    for exe in executables:
        print(exe)
        if ".so" in exe or ".py" in exe:
            continue
        try:
            out = subprocess.check_output(
                exe, cwd=args.torch_install_dir, shell=True, stderr=subprocess.STDOUT
            )
        except subprocess.CalledProcessError as e:
            if "error while loading shared libraries" in e.output.decode(
                encoding="utf-8"
            ):
                problematic_executables.append(exe)
            else:
                print(e)

    with open("torch_executables_missing_rpath.txt", "w") as f:
        f.write("\n".join(problematic_executables))

@cpuhrsch
cpuhrsch requested a review from malfet September 27, 2024 02:21
@cpuhrsch cpuhrsch added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 27, 2024
@kundaMwiza

Copy link
Copy Markdown
Collaborator Author

@malfet bump

@kundaMwiza

Copy link
Copy Markdown
Collaborator Author

Related: #106476

@malfet malfet added release notes: build release notes category topic: improvements topic category and removed topic: not user facing topic category labels Oct 23, 2024
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 23, 2024
@malfet

malfet commented Oct 23, 2024

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -r

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 23, 2024
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch push -f https://github.com/graphcore/pytorch-fork.git pull/136627/head:mwizak/fix-cxx-tests-runpath returned non-zero exit code 128

remote: Permission to graphcore/pytorch-fork.git denied to pytorchmergebot.
fatal: unable to access 'https://github.com/graphcore/pytorch-fork.git/': The requested URL returned error: 403

This is likely because the author did not allow edits from maintainers on the PR or because the repo has additional permissions settings that mergebot does not qualify.
Raised by https://github.com/pytorch/pytorch/actions/runs/11473781665

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@malfet

malfet commented Oct 23, 2024

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: Lint / Test run_test.py is usable without boto3/rockset

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@kundaMwiza
kundaMwiza force-pushed the mwizak/fix-cxx-tests-runpath branch from 4064003 to b9d88b2 Compare October 23, 2024 07:03
@kundaMwiza

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Jan 26, 2025
#136627 has almost fixed the issue that test binaries' runpath has not been set correctly, with few cases left.

This PR fixes the rest.

The binaries are found by `auditwheel repair` a wheel built with `BUILD_TEST=1`.

@malfet

Pull Request resolved: #144305
Approved by: https://github.com/malfet
nWEIdia pushed a commit to nWEIdia/pytorch that referenced this pull request Jan 27, 2025
pytorch#136627 has almost fixed the issue that test binaries' runpath has not been set correctly, with few cases left.

This PR fixes the rest.

The binaries are found by `auditwheel repair` a wheel built with `BUILD_TEST=1`.

@malfet

Pull Request resolved: pytorch#144305
Approved by: https://github.com/malfet
xinyazhang pushed a commit to ROCm/pytorch that referenced this pull request Jul 16, 2025
…pytorch#136627)

This change fixes the RUNPATH of installed c++ tests so that the linker can find the shared libraries they depend on.

For example, currently:
```bash
venv/lib/python3.10/site-packages/torch $ ./bin/test_lazy
./bin/test_lazy: error while loading shared libraries: libtorch.so: cannot open shared object file: No such file or directory
```

Pull Request resolved: pytorch#136627
Approved by: https://github.com/malfet
xinyazhang added a commit to ROCm/pytorch that referenced this pull request Jul 16, 2025
…ibraries (pytorch#136627)"

This reverts commit 84040be83ee4f8850e2384065415c1f8c8e997a5.
jeffdaily added a commit to ROCm/pytorch that referenced this pull request Oct 2, 2026
On ROCm, test_api, test_jit and test_cpp_rpc fail `--help` with "libaotriton_v2.so.0.14.1: cannot open shared object file". test.sh symlinks libtorch* into torch/bin, so the test binary loads libtorch_hip.so through that symlink, glibc sets its $ORIGIN to torch/bin, and its own dependencies in torch/lib (AOTriton, and before that libcaffe2_nvrtc.so, which pytorch#106712 patched with one more symlink) are not found.

The symlinks were added in pytorch#62797 because the installed test binaries had no RUNPATH; pytorch#136627 gave them $ORIGIN/../lib, so they are no longer needed. This removes them for test_libtorch, the distributed C++ tests and test_rpc. test_aot_compilation and test_vulkan keep theirs: test_mobile_nnc, aot_model_compiler_test and the vulkan tests never got that RUNPATH.

Test Plan:

With the torch/bin and torch/lib from this PR's mi350 wheel and CI's LD_LIBRARY_PATH: with the symlinks, `test_api --help` exits 127 with the CI error; without them, test_api, test_jit, test_lazy, test_cpp_rpc and the c10d store and process-group tests start, pytest-cpp collects 1024 and 588 tests from test_api and test_jit, and FunctionalTest.Conv1d (the libcaffe2_nvrtc.so case) passes on gfx950:

```
torch/bin/test_api --gtest_filter='FunctionalTest.Conv1d*'
python -m pytest torch/bin/test_api --collect-only -q
```

This change was developed with the assistance of an AI assistant (Claude).
pytorchmergebot pushed a commit that referenced this pull request Oct 2, 2026
ROCm CI reports its C++ gtests as passing while running none of them: every `cpp/*` test in the ROCm shard logs shows `0 items`.

pytest-cpp skips a binary whose `--help` fails, pytest exits 5, and run_test.py treats 5 as success. On ROCm the build/bin binaries fail `--help` with exit 127: their RUNPATH is build/lib under the build job's /__w workspace, which does not exist in the ROCm test container.

- run_test.py: when a C++ test exits 5, fail it if the binary's `--help` fails, and print the error. Binaries that start but define no tests still pass.
- test.sh: put torch/lib on LD_LIBRARY_PATH for the two build/bin runs, test_aten and static_runtime_test.

`test_api`, `test_jit` and `test_cpp_rpc` run from the installed torch/bin and failed `--help` with "libaotriton_v2.so.0.14.1: cannot open shared object file": test.sh symlinked libtorch* into torch/bin, so libtorch_hip.so loaded through the symlink had `$ORIGIN` = torch/bin and could not find its dependencies in torch/lib. Those symlinks predate the `$ORIGIN/../lib` RUNPATH from #136627; this removes them for test_libtorch, the distributed C++ tests and test_rpc (test_aot_compilation and test_vulkan keep theirs, since those binaries never got that RUNPATH).

Test Plan:

```
# in the ROCm test image: exit 127; with torch/lib on LD_LIBRARY_PATH: 8 tests collected
build/bin/basic --help
# fails now with "--help failed with exit code 127"; zero-test binaries still pass
CPP_TESTS_DIR=/tmp/fakebin python test/run_test.py --cpp -i cpp/broken_test
CPP_TESTS_DIR=build/bin python test/run_test.py --cpp -i cpp/c10_ConstexprCrc_test cpp/c10_StreamGuard_test cpp/basic
```

On gfx950 all 19 shard-1 C++ tests pass when they actually run.

Authored with the assistance of Claude (AI).

Pull Request resolved: #199440
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Oct 5, 2026
ROCm CI reports its C++ gtests as passing while running none of them: every `cpp/*` test in the ROCm shard logs shows `0 items`.

pytest-cpp skips a binary whose `--help` fails, pytest exits 5, and run_test.py treats 5 as success. On ROCm the build/bin binaries fail `--help` with exit 127: their RUNPATH is build/lib under the build job's /__w workspace, which does not exist in the ROCm test container.

- run_test.py: when a C++ test exits 5, fail it if the binary's `--help` fails, and print the error. Binaries that start but define no tests still pass.
- test.sh: put torch/lib on LD_LIBRARY_PATH for the two build/bin runs, test_aten and static_runtime_test.

`test_api`, `test_jit` and `test_cpp_rpc` run from the installed torch/bin and failed `--help` with "libaotriton_v2.so.0.14.1: cannot open shared object file": test.sh symlinked libtorch* into torch/bin, so libtorch_hip.so loaded through the symlink had `$ORIGIN` = torch/bin and could not find its dependencies in torch/lib. Those symlinks predate the `$ORIGIN/../lib` RUNPATH from #136627; this removes them for test_libtorch, the distributed C++ tests and test_rpc (test_aot_compilation and test_vulkan keep theirs, since those binaries never got that RUNPATH).

Test Plan:

```
# in the ROCm test image: exit 127; with torch/lib on LD_LIBRARY_PATH: 8 tests collected
build/bin/basic --help
# fails now with "--help failed with exit code 127"; zero-test binaries still pass
CPP_TESTS_DIR=/tmp/fakebin python test/run_test.py --cpp -i cpp/broken_test
CPP_TESTS_DIR=build/bin python test/run_test.py --cpp -i cpp/c10_ConstexprCrc_test cpp/c10_StreamGuard_test cpp/basic
```

On gfx950 all 19 shard-1 C++ tests pass when they actually run.

Authored with the assistance of Claude (AI).

Pull Request resolved: #199440
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
ROCm CI reports its C++ gtests as passing while running none of them: every `cpp/*` test in the ROCm shard logs shows `0 items`.

pytest-cpp skips a binary whose `--help` fails, pytest exits 5, and run_test.py treats 5 as success. On ROCm the build/bin binaries fail `--help` with exit 127: their RUNPATH is build/lib under the build job's /__w workspace, which does not exist in the ROCm test container.

- run_test.py: when a C++ test exits 5, fail it if the binary's `--help` fails, and print the error. Binaries that start but define no tests still pass.
- test.sh: put torch/lib on LD_LIBRARY_PATH for the two build/bin runs, test_aten and static_runtime_test.

`test_api`, `test_jit` and `test_cpp_rpc` run from the installed torch/bin and failed `--help` with "libaotriton_v2.so.0.14.1: cannot open shared object file": test.sh symlinked libtorch* into torch/bin, so libtorch_hip.so loaded through the symlink had `$ORIGIN` = torch/bin and could not find its dependencies in torch/lib. Those symlinks predate the `$ORIGIN/../lib` RUNPATH from pytorch#136627; this removes them for test_libtorch, the distributed C++ tests and test_rpc (test_aot_compilation and test_vulkan keep theirs, since those binaries never got that RUNPATH).

Test Plan:

```
# in the ROCm test image: exit 127; with torch/lib on LD_LIBRARY_PATH: 8 tests collected
build/bin/basic --help
# fails now with "--help failed with exit code 127"; zero-test binaries still pass
CPP_TESTS_DIR=/tmp/fakebin python test/run_test.py --cpp -i cpp/broken_test
CPP_TESTS_DIR=build/bin python test/run_test.py --cpp -i cpp/c10_ConstexprCrc_test cpp/c10_StreamGuard_test cpp/basic
```

On gfx950 all 19 shard-1 C++ tests pass when they actually run.

Authored with the assistance of Claude (AI).

Pull Request resolved: pytorch#199440
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
ROCm CI reports its C++ gtests as passing while running none of them: every `cpp/*` test in the ROCm shard logs shows `0 items`.

pytest-cpp skips a binary whose `--help` fails, pytest exits 5, and run_test.py treats 5 as success. On ROCm the build/bin binaries fail `--help` with exit 127: their RUNPATH is build/lib under the build job's /__w workspace, which does not exist in the ROCm test container.

- run_test.py: when a C++ test exits 5, fail it if the binary's `--help` fails, and print the error. Binaries that start but define no tests still pass.
- test.sh: put torch/lib on LD_LIBRARY_PATH for the two build/bin runs, test_aten and static_runtime_test.

`test_api`, `test_jit` and `test_cpp_rpc` run from the installed torch/bin and failed `--help` with "libaotriton_v2.so.0.14.1: cannot open shared object file": test.sh symlinked libtorch* into torch/bin, so libtorch_hip.so loaded through the symlink had `$ORIGIN` = torch/bin and could not find its dependencies in torch/lib. Those symlinks predate the `$ORIGIN/../lib` RUNPATH from pytorch#136627; this removes them for test_libtorch, the distributed C++ tests and test_rpc (test_aot_compilation and test_vulkan keep theirs, since those binaries never got that RUNPATH).

Test Plan:

```
# in the ROCm test image: exit 127; with torch/lib on LD_LIBRARY_PATH: 8 tests collected
build/bin/basic --help
# fails now with "--help failed with exit code 127"; zero-test binaries still pass
CPP_TESTS_DIR=/tmp/fakebin python test/run_test.py --cpp -i cpp/broken_test
CPP_TESTS_DIR=build/bin python test/run_test.py --cpp -i cpp/c10_ConstexprCrc_test cpp/c10_StreamGuard_test cpp/basic
```

On gfx950 all 19 shard-1 C++ tests pass when they actually run.

Authored with the assistance of Claude (AI).

Pull Request resolved: pytorch#199440
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: build release notes category topic: improvements topic category topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants