Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hip path manipulation #1673

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 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
Loading