Skip to content

[AMD] Avoid double loading libamdhip64.so if loaded in process#4255

Merged
antiagainst merged 3 commits intotriton-lang:mainfrom
ROCm:xinyazhang/dlopen-dl_iterate_phdr
Aug 23, 2024
Merged

[AMD] Avoid double loading libamdhip64.so if loaded in process#4255
antiagainst merged 3 commits intotriton-lang:mainfrom
ROCm:xinyazhang/dlopen-dl_iterate_phdr

Conversation

@xinyazhang
Copy link
Copy Markdown
Contributor

@xinyazhang xinyazhang commented Jul 3, 2024

PyTorch have ways to load the libamdhip64.so library, and the original logic has problems detecting this shared object file because it can be placed at any location with venv/DT_RUNPATH/LD_LIBRARY_PATH//etc/ld.so.conf.d/*.conf/LD_PRELOAD. Notably the RUNPATH has become the preferred approach for multi-version ROCm installations.

This patch let Triton enumerate the address space with dl_iterate_phdr, and choose the libamdhip64.so that is already loaded into address space unless TRITON_LIBHIP_PATH is already set.

Complete the following tasks before sending your PR, and replace [ ] with [x] to indicate you have done them.

  • I am not making a trivial change, such as fixing a typo in a comment.
  • I have written a PR description following these
    rules.
  • I have run pre-commit run --from-ref origin/main --to-ref HEAD.
  • Select one of the following.
    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because of no additional features.
  • Select one of the following.
    • I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

@antiagainst antiagainst marked this pull request as draft July 3, 2024 21:00
PyTorch have ways to load the libamdhip64.so library, and the original logic has problems
detecting this shared object file because it can be placed at any location with
venv/DT_RUNPATH/LD_LIBRARY_PATH.

Now Triton enumerates the address space with dl_iterate_phdr, and prefer the
libamdhip64.so that is already loaded into address space over everything else
except for TRITON_LIBHIP_PATH.
@xinyazhang xinyazhang force-pushed the xinyazhang/dlopen-dl_iterate_phdr branch from c5fd338 to 3013fd4 Compare July 4, 2024 06:27
@antiagainst antiagainst changed the title Avoid the double loading problem of libamdhip64.so if a copy is already loaded [AMD] Avoid double loading libamdhip64.so if loaded in process Jul 23, 2024
@antiagainst antiagainst force-pushed the xinyazhang/dlopen-dl_iterate_phdr branch from e46ad61 to a2a0462 Compare August 23, 2024 21:36
@antiagainst antiagainst force-pushed the xinyazhang/dlopen-dl_iterate_phdr branch from a2a0462 to f719c95 Compare August 23, 2024 21:50
@antiagainst antiagainst marked this pull request as ready for review August 23, 2024 22:15
@antiagainst antiagainst merged commit e0613c6 into triton-lang:main Aug 23, 2024
@antiagainst antiagainst deleted the xinyazhang/dlopen-dl_iterate_phdr branch August 23, 2024 22:17
bertmaher pushed a commit to bertmaher/triton that referenced this pull request Sep 24, 2024
…ng#4255)

PyTorch have ways to load the libamdhip64.so library, and the original
logic has problems detecting this shared object file because it can be
placed at any location with `venv`/`DT_RUNPATH`/`LD_LIBRARY_PATH`/
`/etc/ld.so.conf.d/*.conf`/`LD_PRELOAD`. Notably the `RUNPATH`
has become the preferred approach for multi-version ROCm installations.

This patch let Triton enumerate the address space with
`dl_iterate_phdr`, and choose the libamdhip64.so that is already loaded
into address space unless `TRITON_LIBHIP_PATH` is already set.

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
bertmaher pushed a commit to bertmaher/triton that referenced this pull request Dec 10, 2024
…ng#4255)

PyTorch have ways to load the libamdhip64.so library, and the original
logic has problems detecting this shared object file because it can be
placed at any location with `venv`/`DT_RUNPATH`/`LD_LIBRARY_PATH`/
`/etc/ld.so.conf.d/*.conf`/`LD_PRELOAD`. Notably the `RUNPATH`
has become the preferred approach for multi-version ROCm installations.

This patch let Triton enumerate the address space with
`dl_iterate_phdr`, and choose the libamdhip64.so that is already loaded
into address space unless `TRITON_LIBHIP_PATH` is already set.

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants