Skip to content

Commit

Permalink
Merge Removing hip path manipulation
Browse files Browse the repository at this point in the history
This merge removes the setting of the `HIP_PATH` environment variable. It also removes setting the paths for each rocm library individually. Instead, it is expected that user provide the correct `CMAKE_PREFIX_PATH` during configuration.
Additionally, a check is introduced to warn about rocm's faulty CMake setup. For rocm 5.0-5.6 the default installation (as provided in the rocm/dev images) has some bugs, which prevent even the simplest CMake setup to enable the HIP language. 

Related PR: #1673
  • Loading branch information
MarcelKoch authored Oct 15, 2024
2 parents 2bbcfb9 + f6eb48a commit 8530831
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 124 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(PROJECT_VERSION_TAG ${Ginkgo_VERSION_TAG})
set(THREADS_PREFER_PTHREAD_FLAG ON)

# Determine which modules can be compiled
include(cmake/hip_path.cmake)
include(cmake/autodetect_executors.cmake)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
Expand Down
3 changes: 1 addition & 2 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ set(GINKGO_HAVE_VTUNE "@GINKGO_HAVE_VTUNE@")
set(GINKGO_HAVE_METIS "@GINKGO_HAVE_METIS@")
set_and_check(VTune_PATH "@VTune_PATH@")

# ensure Threads settings
# ensure Threads settings
set(THREADS_PREFER_PTHREAD_FLAG ON)

# NOTE: we do not export benchmarks, examples, tests or devel tools
Expand Down Expand Up @@ -176,7 +176,6 @@ if((NOT GINKGO_BUILD_SHARED_LIBS) AND GINKGO_BUILD_HIP)
find_dependency(hipsparse)
find_dependency(rocrand)
find_dependency(rocthrust)
set_and_check(ROCTRACER_PATH "@ROCTRACER_PATH@")
find_dependency(ROCTX)
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/FindROCTX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
# ``ROCTX_FOUND``
# If false, do not try to use the ROCTX library.

find_path(ROCTX_INCLUDE_DIR NAMES roctx.h HINTS ${ROCTRACER_PATH}/include)
find_path(ROCTX_INCLUDE_DIR NAMES roctx.h HINTS ${ROCTRACER_PATH}/include ${ROCM_PATH}/include/roctracer)
mark_as_advanced(ROCTX_INCLUDE_DIR)

if(NOT ROCTX_LIBRARY)
find_library(ROCTX_LIBRARY NAMES roctx64 HINTS ${ROCTRACER_PATH}/lib)
find_library(ROCTX_LIBRARY NAMES roctx64 HINTS ${ROCTRACER_PATH}/lib ${ROCM_PATH}/lib)
endif()

include(FindPackageHandleStandardArgs)
Expand Down
3 changes: 3 additions & 0 deletions cmake/autodetect_executors.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ if (NOT DEFINED GINKGO_BUILD_HIP)
if(CMAKE_HIP_COMPILER)
message(STATUS "Enabling HIP executor")
set(GINKGO_HAS_HIP ON)
else ()
include(cmake/hip_helpers.cmake)
ginkgo_check_hip_detection_issue()
endif()
endif()

Expand Down
116 changes: 12 additions & 104 deletions cmake/hip.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)

include(cmake/hip_helpers.cmake)
include(CheckLanguage)
check_language(HIP)
ginkgo_check_hip_detection_issue()

enable_language(HIP)

# We keep using NVCC/HCC for consistency with previous releases even if AMD
# updated everything to use NVIDIA/AMD in ROCM 4.1
set(GINKGO_HIP_PLATFORM_NVCC 0)
set(GINKGO_HIP_PLATFORM_HCC 0)
if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA")
set(GINKGO_HIP_PLATFORM "nvidia")
set(GINKGO_HIP_PLATFORM_NVIDIA ON)
Expand All @@ -12,110 +23,7 @@ else()
set(GINKGO_HIP_PLATFORM_HCC 1)
endif()


if(NOT DEFINED ROCM_PATH)
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to which ROCM has been installed")
elseif(DEFINED ENV{HIP_PATH})
set(ROCM_PATH "$ENV{HIP_PATH}/.." CACHE PATH "Path to which ROCM has been installed")
else()
set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which ROCM has been installed")
endif()
endif()

if(NOT DEFINED HIPBLAS_PATH)
if(DEFINED ENV{HIPBLAS_PATH})
set(HIPBLAS_PATH $ENV{HIPBLAS_PATH} CACHE PATH "Path to which HIPBLAS has been installed")
else()
set(HIPBLAS_PATH "${ROCM_PATH}/hipblas" CACHE PATH "Path to which HIPBLAS has been installed")
endif()
endif()

if(NOT DEFINED HIPFFT_PATH)
if(DEFINED ENV{HIPFFT_PATH})
set(HIPFFT_PATH $ENV{HIPFFT_PATH} CACHE PATH "Path to which HIPFFT has been installed")
else()
set(HIPFFT_PATH "${ROCM_PATH}/hipfft" CACHE PATH "Path to which HIPFFT has been installed")
endif()
endif()

if(NOT DEFINED HIPRAND_PATH)
if(DEFINED ENV{HIPRAND_PATH})
set(HIPRAND_PATH $ENV{HIPRAND_PATH} CACHE PATH "Path to which HIPRAND has been installed")
else()
set(HIPRAND_PATH "${ROCM_PATH}/hiprand" CACHE PATH "Path to which HIPRAND has been installed")
endif()
endif()

if(NOT DEFINED ROCRAND_PATH)
if(DEFINED ENV{ROCRAND_PATH})
set(ROCRAND_PATH $ENV{ROCRAND_PATH} CACHE PATH "Path to which ROCRAND has been installed")
else()
set(ROCRAND_PATH "${ROCM_PATH}/rocrand" CACHE PATH "Path to which ROCRAND has been installed")
endif()
endif()

if(NOT DEFINED HIPSPARSE_PATH)
if(DEFINED ENV{HIPSPARSE_PATH})
set(HIPSPARSE_PATH $ENV{HIPSPARSE_PATH} CACHE PATH "Path to which HIPSPARSE has been installed")
else()
set(HIPSPARSE_PATH "${ROCM_PATH}/hipsparse" CACHE PATH "Path to which HIPSPARSE has been installed")
endif()
endif()

if(NOT DEFINED HIP_CLANG_PATH)
if(NOT DEFINED ENV{HIP_CLANG_PATH})
set(HIP_CLANG_PATH "${ROCM_PATH}/llvm/bin" CACHE PATH "Path to which HIP compatible clang binaries have been installed")
else()
set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH} CACHE PATH "Path to which HIP compatible clang binaries have been installed")
endif()
endif()

if(NOT DEFINED ROCTRACER_PATH)
if(DEFINED ENV{ROCTRACER_PATH})
set(ROCTRACER_PATH $ENV{ROCTRACER_PATH} CACHE PATH "Path to which ROCTRACER has been installed")
else()
set(ROCTRACER_PATH "${ROCM_PATH}/roctracer" CACHE PATH "Path to which ROCTRACER has been installed")
endif()
endif()

find_program(
HIP_HIPCONFIG_EXECUTABLE
NAMES hipconfig
PATHS
"${HIP_ROOT_DIR}"
ENV ROCM_PATH
ENV HIP_PATH
/opt/rocm
/opt/rocm/hip
PATH_SUFFIXES bin
NO_DEFAULT_PATH
)
if(NOT HIP_HIPCONFIG_EXECUTABLE)
# Now search in default paths
find_program(HIP_HIPCONFIG_EXECUTABLE hipconfig)
endif()

execute_process(
COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE GINKGO_HIP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)

## Setup all CMAKE variables to find HIP and its dependencies
set(GINKGO_HIP_MODULE_PATH "${HIP_PATH}/cmake")
list(APPEND CMAKE_MODULE_PATH "${GINKGO_HIP_MODULE_PATH}")
if (GINKGO_HIP_PLATFORM_AND)
list(APPEND CMAKE_PREFIX_PATH "${HIP_PATH}/lib/cmake")
endif()
list(APPEND CMAKE_PREFIX_PATH
"${HIPBLAS_PATH}/lib/cmake"
"${HIPFFT_PATH}/lib/cmake"
"${HIPRAND_PATH}/lib/cmake"
"${HIPSPARSE_PATH}/lib/cmake"
"${ROCRAND_PATH}/lib/cmake"
)
ginkgo_find_hip_version()

find_package(hipblas REQUIRED)
find_package(hipfft) # optional dependency
Expand Down
43 changes: 43 additions & 0 deletions cmake/hip_helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function(ginkgo_find_hip_version)
find_program(
HIP_HIPCONFIG_EXECUTABLE
NAMES hipconfig
PATHS
"${HIP_ROOT_DIR}"
ENV ROCM_PATH
ENV HIP_PATH
/opt/rocm
/opt/rocm/hip
PATH_SUFFIXES bin
NO_DEFAULT_PATH
)
if(NOT HIP_HIPCONFIG_EXECUTABLE)
# Now search in default paths
find_program(HIP_HIPCONFIG_EXECUTABLE hipconfig)
endif()

execute_process(
COMMAND ${HIP_HIPCONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE GINKGO_HIP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
set(GINKGO_HIP_VERSION ${GINKGO_HIP_VERSION} PARENT_SCOPE)
endfunction()

# This function checks if ROCm might not be detected correctly.
# ROCm < 5.7 has a faulty CMake setup that requires setting
# CMAKE_PREFIX_PATH=$ROCM_PATH/lib/cmake, otherwise HIP will not be detected.
function(ginkgo_check_hip_detection_issue)
if(NOT CMAKE_HIP_COMPILER)
ginkgo_find_hip_version()
if (GINKGO_HIP_VERSION AND GINKGO_HIP_VERSION VERSION_LESS 5.7)
message(WARNING
"Could not find a HIP compiler, but HIP version ${GINKGO_HIP_VERSION} was detected through "
"hipconfig. Try setting the environment variable CMAKE_PREFIX_PATH=$ROCM_PATH/lib/cmake, or "
"update to ROCm >= 5.7."
)
endif ()
endif ()
endfunction()

13 changes: 0 additions & 13 deletions cmake/hip_path.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions include/ginkgo/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@

/* What is HIP compiled for, hcc or nvcc? */
// clang-format off
#define GINKGO_HIP_PLATFORM_HCC @GINKGO_HIP_PLATFORM_HCC@
#cmakedefine01 GINKGO_HIP_PLATFORM_HCC


#define GINKGO_HIP_PLATFORM_NVCC @GINKGO_HIP_PLATFORM_NVCC@
#cmakedefine01 GINKGO_HIP_PLATFORM_NVCC
// clang-format on


Expand Down

0 comments on commit 8530831

Please sign in to comment.