This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Use hip's config mode to find libraries
ClosedPublic

Authored by krzysz00 on Sep 27 2022, 11:01 AM.

Details

Summary

Instead of using find_package(HIP) to find FindHIP.cmake, which
doesn't seem to be the preferred way to find HIP anymore, use
find_package(hip CONFIG) to find the HIP configuration. Give
preference to ${ROCM_PATH} over ${ROCM_PATH}/hip in order to handle
the fact that newer ROCm versions prefer the include path to use
${ROCM_PATH}/include/hip over ${ROCM_PATH}/hip/innclude/hip (the
latter throws up a bunch of deprecation warnings)

Then, instead of trying to manually find the host-side headers and
runtime library by hand, use the hip::host and hip::amdhip64 libraries
that the config module defines.

This makes the CMake config much less error-prone and brings it in
line with the recommended approach to finding HIP.

Diff Detail

Event Timeline

krzysz00 created this revision.Sep 27 2022, 11:01 AM
krzysz00 requested review of this revision.Sep 27 2022, 11:01 AM
mehdi_amini accepted this revision.Sep 27 2022, 9:54 PM
This revision is now accepted and ready to land.Sep 27 2022, 9:54 PM
This revision was automatically updated to reflect the committed changes.
arsenm added a subscriber: arsenm.Jan 7 2023, 6:16 AM
arsenm added inline comments.
mlir/lib/ExecutionEngine/CMakeLists.txt
193

This is a cmake crime, CMAKE_PREFIX_PATH should not be modified. find_package(hip) should know the default location to search

197

Can this use amdgpu-arch from clang instead? That would cut down the number of dependencies to just the hip libraries

krzysz00 added inline comments.Jan 9 2023, 8:17 AM
mlir/lib/ExecutionEngine/CMakeLists.txt
193

Unfortulately, per the latest documentation I was able to find, these CMake crimes are what the HIP documentation tells you to do https://rocmdocs.amd.com/en/latest/Installation_Guide/Using-CMake-with-AMD-ROCm.html .

Also, from memory (I can test this if you'd like), not doing this makes find_package(hip) fail to find its own dependencies because the CMake code for find_package(hip) doesn't set PATHS or HINTS appropriately when it calls find_package(...). So I think this is best viewed as a bug against HIP.

197

Having just tried running amdgpu-arch on a development machine, it segfaulted, while rocm_agent_enumerator worked just fine.

arsenm added inline comments.Jan 9 2023, 8:20 AM
mlir/lib/ExecutionEngine/CMakeLists.txt
193

Those documents are just wrong. CMAKE_PREFIX_PATH is for users to set on the command line, not for scripts to mess with. find_package hip absolutely must use PATHS and HINTs for the default install location (I know at somepoint someone was working on a very wrong project to remove all of these HINTS and PATHs everywhere that I thought we put a stop to)

krzysz00 added inline comments.Jan 9 2023, 8:36 AM
mlir/lib/ExecutionEngine/CMakeLists.txt
193

From looking at /opt/rocm-5.3.0/lib/cmake/hip/hip-config.cmake on my system ... the find_dependency macro in there doesn't set PATHS or HINTS and so this attempt to stop the project apparently didn't happen.