Skip to content

Commit 7d65804

Browse files
Merge pull request #48 from psychocoderHPC/topic-updateToModernCMake
use native CMake HIP support
2 parents 025bc92 + 5e21d30 commit 7d65804

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
cmake_minimum_required(VERSION 3.16.0)
66

7-
87
################################################################################
98
# Project
109
################################################################################
1110

11+
include(CheckLanguage) # check for CUDA/HIP language support
12+
1213
project(CUDA_memtest LANGUAGES CXX)
1314

1415
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
@@ -70,15 +71,26 @@ else()
7071
# Find HIP
7172
################################################################################
7273
# supported HIP version range
73-
set(CUDA_MEMTEST_HIP_MIN_VER 4.0)
74-
set(CUDA_MEMTEST_HIP_MAX_VER 5.0)
75-
find_package(hip "${CUDA_MEMTEST_HIP_MAX_VER}")
76-
if(NOT TARGET hip)
77-
message(STATUS "Could not find HIP ${CUDA_MEMTEST_HIP_MAX_VER}. Now searching for HIP ${CUDA_MEMTEST_HIP_MIN_VER}")
78-
find_package(hip "${CUDA_MEMTEST_HIP_MIN_VER}")
79-
endif()
74+
check_language(HIP)
75+
76+
if(CMAKE_HIP_COMPILER)
77+
enable_language(HIP)
78+
find_package(hip REQUIRED)
79+
80+
set(CUDA_MEMTEST_HIP_MIN_VER 5.2)
81+
set(CUDA_MEMTEST_HIP_MAX_VER 6.1)
8082

81-
if(NOT TARGET hip)
83+
# construct hip version only with major and minor level
84+
# cannot use hip_VERSION because of the patch level
85+
# 6.0 is smaller than 6.0.1234, so CUDA_MEMTEST_HIP_MAX_VER would have to be defined with a large patch level or
86+
# the next minor level, e.g. 6.1, would have to be used.
87+
set(_hip_MAJOR_MINOR_VERSION "${hip_VERSION_MAJOR}.${hip_VERSION_MINOR}")
88+
89+
if(${_hip_MAJOR_MINOR_VERSION} VERSION_LESS ${CUDA_MEMTEST_HIP_MIN_VER} OR ${_hip_MAJOR_MINOR_VERSION} VERSION_GREATER ${CUDA_MEMTEST_HIP_MAX_VER})
90+
message(WARNING "HIP ${_hip_MAJOR_MINOR_VERSION} is not official supported by cuda_memtest. Supported versions: ${CUDA_MEMTEST_HIP_MIN_VER} - ${CUDA_MEMTEST_HIP_MAX_VER}")
91+
endif()
92+
93+
else()
8294
message(FATAL_ERROR "Optional alpaka dependency HIP could not be found!")
8395
endif()
8496
endif()
@@ -135,6 +147,7 @@ if(CUDA_MEMTEST_BACKEND STREQUAL "cuda")
135147
else()
136148
target_link_libraries(cuda_memtest PRIVATE hip::host)
137149
target_link_libraries(cuda_memtest PRIVATE hip::device)
150+
target_compile_definitions(cuda_memtest PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:-D__HIP_PLATFORM_AMD__>")
138151
target_compile_definitions(cuda_memtest PRIVATE "ENABLE_NVML=0")
139152
endif()
140153

0 commit comments

Comments
 (0)