Skip to content

Commit

Permalink
Make detecting of HIP dependencies more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
csbnw committed Jul 12, 2024
1 parent 253c327 commit eb48fd8
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmake/cudawrappers-dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
if(${CUDAWRAPPERS_BACKEND_HIP})
# cmake-format: off
# This following code attempts to locate the HIP runtime library's root directory.
#
# 1. Checks if the ROCM_ROOT and ROCM_PATH variables are defined.
# - Assign them from corresponding environment variables if not defined.
# 2. Searches for the HIP runtime header file in the paths specified by ROCM_ROOT and ROCM_PATH.
# - If the path is set but HIP is not found, an error message is generated.
# 3. If HIP is still not found, the script searches in the default path.
# 4. Adding HIP_ROOT_DIR to CMAKE_PREFIX_PATH and Finding Packages
# - The HIP runtime directory (HIP_ROOT_DIR) is appended to CMAKE_PREFIX_PATH
# to ensure that CMake can find the HIP-related packages.
#
# Usage:
# Set the ROCM_ROOT or ROCM_PATH environment variables or pass them as CMake options, e.g.:
# cmake -DROCM_ROOT=/path/to/rocm ..
# or
# ROCM_ROOT=/path/to/rocm cmake ..
# cmake-format: on

foreach(var IN ITEMS ROCM_ROOT ROCM_PATH)
# Step 1.
if(NOT DEFINED ${var})
set(${var} $ENV{${var}})
endif()

# Step 2.
find_path(
HIP_ROOT_DIR
NAMES include/hip/hip_runtime.h
PATHS ${${var}}
NO_DEFAULT_PATH
)

if(NOT HIP_ROOT_DIR AND ${var})
message(FATAL_ERROR "HIP not found in " ${${var}})
endif()
endforeach()

if(NOT HIP_ROOT_DIR)
# Step 3.
find_path(
HIP_ROOT_DIR
NAMES include/hip/hip_runtime.h
PATHS /opt/rocm
)
endif()

# Step 4.
list(APPEND CMAKE_PREFIX_PATH ${HIP_ROOT_DIR})
find_package(hip REQUIRED)
find_package(hipfft REQUIRED)
else()
Expand Down

0 comments on commit eb48fd8

Please sign in to comment.