Skip to content

Commit 3c95aa1

Browse files
Use enable_language(HIP) (#702)
Co-authored-by: Chris White <[email protected]>
1 parent 2bf714a commit 3c95aa1

File tree

11 files changed

+165
-47
lines changed

11 files changed

+165
-47
lines changed

.gitlab/build_ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This is the share configuration of jobs for ruby
33
.on_ruby:
44
variables:
5-
SCHEDULER_PARAMETERS: "--res=ci --exclusive=user --deadline=now+1hour -N1 -t ${ALLOC_TIME}"
5+
SCHEDULER_PARAMETERS: "--reservation=ci --exclusive=user --deadline=now+1hour -N1 -t ${ALLOC_TIME}"
66
tags:
77
- batch
88
- ruby

.gitlab/build_tioga.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@
2727

2828
####
2929
# Build jobs
30-
tioga-clang_16_0_0_hip:
30+
tioga-clang_18_0_0_hip:
3131
variables:
32-
HOST_CONFIG: "clang@16.0.0_hip.cmake"
32+
HOST_CONFIG: "clang@18.0.0_hip.cmake"
3333
extends: .src_build_on_tioga
3434

3535

3636
####
3737
# HIP project tests
38-
tioga-clang_16.0.0_hip_config_test:
38+
tioga-clang_18.0.0_hip_config_test:
3939
variables:
4040
ENABLED_BLT_TESTS: "hip-config-test"
41-
HOST_CONFIG: "[email protected]_hip.cmake"
41+
HOST_CONFIG: "[email protected]_hip.cmake"
42+
extends: [.run_project_integration_test_on_tioga]
43+
44+
tioga-gcc_10.3.1_clang_17.0.0_hip_config_test:
45+
variables:
46+
ENABLED_BLT_TESTS: "hip-config-test"
47+
HOST_CONFIG: "[email protected][email protected]_hip.cmake"
4248
extends: [.run_project_integration_test_on_tioga]

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/
1111

1212
### Added
1313
- Added ``WORKING_DIRECTORY`` option to ``blt_add_test`` and ``blt_add_benchmark``.
14+
- Added `BLT_CXX_FILE_EXTS` variable (split out of `BLT_C_FILE_EXTS`) for use in modified `blt_split_source_list_by_language` macro.
1415

1516
### Changed
1617
- Modified `blt_convert_to_system_includes` to handle multiple targets and recursively update includes for dependencies.
18+
- Modified `blt_split_source_list_by_language` to accept a `CXX_LIST` argument for splitting out C and CXX sources. If not specified, the `C_LIST` will contain both C and C++ sources.
19+
- HIP support now uses enable_language(HIP), and specifying a HIP compiler must use the variable `CMAKE_HIP_COMPILER`.
1720
- Updated GoogleBenchmark to 1.9.1
1821

1922
### Fixed

SetupBLT.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ if (NOT BLT_LOADED)
193193
# File extension lists used to filter sources based on languages for code checks
194194
# and filtering Fortran sources out of cuda/hip source lists
195195
# Note: this filtering is case-insensitive
196-
set(BLT_C_FILE_EXTS ".cpp" ".hpp" ".cxx" ".hxx" ".c" ".h" ".cc" ".hh" ".inl" ".cu" ".cuh"
197-
CACHE STRING "List of known file extensions used for C/CXX sources")
196+
set(BLT_C_FILE_EXTS ".c" ".h"
197+
CACHE STRING "List of known file extensions used for C sources")
198+
set(BLT_CXX_FILE_EXTS ".cpp" ".hpp" ".cxx" ".hxx" ".cc" ".hh" ".inl" ".cu" ".cuh"
199+
CACHE STRING "List of known file extensions used for CXX sources")
198200
set(BLT_Fortran_FILE_EXTS ".f" ".f90"
199201
CACHE STRING "List of known file extensions used for Fortran sources")
200202
set(BLT_Python_FILE_EXTS ".py"

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ strategy:
4343
MPI_DIR: '/usr'
4444
CMAKE_FLAGS: '$(C_COMPILERS) $(MPI_FLAGS) -DENABLE_GTEST_DEATH_TESTS=OFF -DENABLE_OPENMP=ON'
4545
osx_gcc:
46-
VM_ImageName: 'macos-12'
46+
VM_ImageName: 'macos-14'
4747
CMAKE_FLAGS: ''
4848
windows:
4949
VM_ImageName: 'windows-2022'

cmake/BLTMacros.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ macro(blt_add_library)
205205
DEPENDS_ON ${arg_DEPENDS_ON}
206206
LIBRARY_TYPE ${_lib_type})
207207
endif()
208+
209+
if(BLT_ENABLE_HIP)
210+
blt_setup_hip_target(
211+
NAME ${arg_NAME}
212+
SOURCES ${arg_SOURCES}
213+
DEPENDS_ON ${arg_DEPENDS_ON})
214+
endif()
208215
else()
209216
#
210217
# Header-only library support
@@ -320,6 +327,13 @@ macro(blt_add_executable)
320327
DEPENDS_ON ${arg_DEPENDS_ON})
321328
endif()
322329

330+
if(BLT_ENABLE_HIP)
331+
blt_setup_hip_target(
332+
NAME ${arg_NAME}
333+
SOURCES ${arg_SOURCES}
334+
DEPENDS_ON ${arg_DEPENDS_ON})
335+
endif()
336+
323337
# CMake wants to load with C++ if any of the libraries are C++.
324338
# Force to load with Fortran if the first file is Fortran.
325339
list(GET arg_SOURCES 0 _first)

cmake/BLTPrivateMacros.cmake

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,51 @@ macro(blt_setup_cuda_target)
353353
endif()
354354
endmacro(blt_setup_cuda_target)
355355

356+
##------------------------------------------------------------------------------
357+
## blt_setup_hip_target(NAME <name of target>
358+
## SOURCES <list of sources>
359+
## DEPENDS_ON <list of dependencies>
360+
##------------------------------------------------------------------------------
361+
macro(blt_setup_hip_target)
362+
363+
set(options)
364+
set(singleValueArgs NAME)
365+
set(multiValueArgs SOURCES DEPENDS_ON)
366+
367+
# Parse the arguments
368+
cmake_parse_arguments(arg "${options}" "${singleValueArgs}"
369+
"${multiValueArgs}" ${ARGN} )
370+
371+
# Check arguments
372+
if ( NOT DEFINED arg_NAME )
373+
message( FATAL_ERROR "Must provide a NAME argument to the 'blt_setup_hip_target' macro")
374+
endif()
375+
376+
if ( NOT DEFINED arg_SOURCES )
377+
message( FATAL_ERROR "Must provide SOURCES to the 'blt_setup_hip_target' macro")
378+
endif()
379+
380+
# Determine if hip is in DEPENDS_ON
381+
list(FIND arg_DEPENDS_ON "blt_hip" _hip_index)
382+
list(FIND arg_DEPENDS_ON "blt::hip" _hip_index2)
383+
set(_depends_on_hip FALSE)
384+
if(${_hip_index} GREATER -1 OR ${_hip_index2} GREATER -1)
385+
set(_depends_on_hip TRUE)
386+
endif()
387+
388+
if (${_depends_on_hip})
389+
set(_hip_sources)
390+
set(_non_hip_sources)
391+
blt_split_source_list_by_language(SOURCES ${arg_SOURCES}
392+
C_LIST _non_hip_sources
393+
CXX_LIST _hip_sources
394+
Fortran_LIST _non_hip_sources)
395+
396+
set_source_files_properties( ${_hip_sources} PROPERTIES LANGUAGE HIP)
397+
398+
endif()
399+
endmacro(blt_setup_hip_target)
400+
356401

357402
##-----------------------------------------------------------------------------
358403
## blt_make_file_ext_regex( EXTENSIONS [ext1 [ext2 ...]]
@@ -399,6 +444,7 @@ endmacro(blt_make_file_ext_regex)
399444
##------------------------------------------------------------------------------
400445
## blt_split_source_list_by_language( SOURCES <sources>
401446
## C_LIST <list name>
447+
## CXX_LIST <list name>
402448
## Fortran_LIST <list name>
403449
## Python_LIST <list name>
404450
## CMAKE_LIST <list name>)
@@ -414,7 +460,7 @@ endmacro(blt_make_file_ext_regex)
414460
macro(blt_split_source_list_by_language)
415461

416462
set(options)
417-
set(singleValueArgs C_LIST Fortran_LIST Python_LIST CMAKE_LIST)
463+
set(singleValueArgs C_LIST CXX_LIST Fortran_LIST Python_LIST CMAKE_LIST)
418464
set(multiValueArgs SOURCES)
419465

420466
# Parse the arguments
@@ -430,6 +476,9 @@ macro(blt_split_source_list_by_language)
430476
set(BLT_C_FILE_REGEX)
431477
blt_make_file_ext_regex(EXTENSIONS ${BLT_C_FILE_EXTS}
432478
OUTPUT_REGEX BLT_C_FILE_REGEX)
479+
set(BLT_CXX_FILE_REGEX)
480+
blt_make_file_ext_regex(EXTENSIONS ${BLT_CXX_FILE_EXTS}
481+
OUTPUT_REGEX BLT_CXX_FILE_REGEX)
433482
set(BLT_Fortran_FILE_REGEX)
434483
blt_make_file_ext_regex(EXTENSIONS ${BLT_Fortran_FILE_EXTS}
435484
OUTPUT_REGEX BLT_Fortran_FILE_REGEX)
@@ -463,6 +512,13 @@ macro(blt_split_source_list_by_language)
463512
if (DEFINED arg_C_LIST)
464513
list(APPEND ${arg_C_LIST} "${_file}")
465514
endif()
515+
elseif("${_lower_file}" MATCHES "${BLT_CXX_FILE_REGEX}")
516+
if (DEFINED arg_CXX_LIST)
517+
list(APPEND ${arg_CXX_LIST} "${_file}")
518+
# maintain backwards compatibilty by adding to C list if CXX list not set
519+
else()
520+
list(APPEND ${arg_C_LIST} "${_file}")
521+
endif()
466522
elseif("${_lower_file}" MATCHES "${BLT_Fortran_FILE_REGEX}")
467523
if (DEFINED arg_Fortran_LIST)
468524
list(APPEND ${arg_Fortran_LIST} "${_file}")

cmake/thirdparty/BLTSetupHIP.cmake

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
################################
77
# HIP
88
################################
9+
10+
if( ${CMAKE_VERSION} VERSION_LESS "3.21.0" )
11+
message(FATAL_ERROR "HIP support requires CMake >= 3.21.0")
12+
endif ()
13+
14+
enable_language(HIP)
915

1016
if(NOT ROCM_PATH)
1117
# First try finding paths given by the user
@@ -41,32 +47,7 @@ message(STATUS "ROCM path: ${ROCM_PATH}")
4147
message(STATUS "HIP version: ${hip_VERSION}")
4248

4349
# AMDGPU_TARGETS should be defined in the hip-config.cmake that gets "included" via find_package(hip)
44-
# This file is also what hardcodes the --offload-arch flags we're removing here
4550
if(DEFINED AMDGPU_TARGETS)
46-
# If we haven't selected a particular architecture via CMAKE_HIP_ARCHITECTURES,
47-
# we want to remove the unconditionally added compile/link flags from the hip::device target.
48-
# FIXME: This may cause problems for targets whose HIP_ARCHITECTURES property differs
49-
# from CMAKE_HIP_ARCHITECTURES - this only happens when a user manually modifies
50-
# the property after it is initialized
51-
get_target_property(_hip_compile_options hip::device INTERFACE_COMPILE_OPTIONS)
52-
get_target_property(_hip_link_libs hip::device INTERFACE_LINK_LIBRARIES)
53-
54-
foreach(_target ${AMDGPU_TARGETS})
55-
if(NOT "${CMAKE_HIP_ARCHITECTURES}" MATCHES "${_target}")
56-
set(_flag "--offload-arch=${_target}")
57-
set(_generator_compile_flag "$<$<COMPILE_LANGUAGE:CXX>:SHELL:${_flag}>")
58-
set(_generator_link_flag "$<$<LINK_LANGUAGE:CXX>:${_flag}>")
59-
60-
list(REMOVE_ITEM _hip_compile_options ${_generator_compile_flag})
61-
list(REMOVE_ITEM _hip_compile_options ${_flag})
62-
list(REMOVE_ITEM _hip_link_libs ${_generator_link_flag})
63-
list(REMOVE_ITEM _hip_link_libs ${_flag})
64-
endif()
65-
endforeach()
66-
67-
set_property(TARGET hip::device PROPERTY INTERFACE_COMPILE_OPTIONS ${_hip_compile_options})
68-
set_property(TARGET hip::device PROPERTY INTERFACE_LINK_LIBRARIES ${_hip_link_libs})
69-
7051
if(DEFINED CMAKE_HIP_ARCHITECTURES)
7152
set(AMDGPU_TARGETS "${CMAKE_HIP_ARCHITECTURES}" CACHE STRING "" FORCE)
7253
endif()
@@ -87,14 +68,10 @@ else()
8768
endif()
8869

8970
blt_import_library(NAME blt_hip
90-
COMPILE_FLAGS ${_blt_hip_compile_flags}
9171
EXPORTABLE ${BLT_EXPORT_THIRDPARTY}
72+
DEPENDS_ON blt_hip_runtime
9273
GLOBAL ${_blt_hip_is_global})
9374

94-
# Hard-copy inheritable properties instead of depending on hip::device so that we can export
95-
# all required information in our target blt_hip
96-
blt_inherit_target_info(TO blt_hip FROM hip::device OBJECT FALSE)
97-
9875
add_library(blt::hip ALIAS blt_hip)
9976

10077

docs/tutorial/common_hpc_dependencies.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ compilers be set as the main compilers. This will change soon.
167167
**Important Setup Variables**
168168

169169
* ``ENABLE_HIP`` : Enables HIP support in BLT
170-
* ``HIP_ROOT_DIR`` : Root directory for HIP installation
170+
* ``ROCM_ROOT_DIR`` : Root directory for ROCM installation
171171
* ``CMAKE_HIP_ARCHITECTURES`` : GPU architecture to use when generating HIP/ROCm code
172+
* ``CMAKE_HIP_COMPILER``: Compiler to use for HIP compilation, required when the C++ compiler does not support HIP.
172173

173174
**BLT Targets**
174175

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#------------------------------------------------------------------------------
88
# Compilers
99
#------------------------------------------------------------------------------
10-
# Compiler Spec: clang@16.0.0
10+
# Compiler Spec: clang@18.0.0
1111
#------------------------------------------------------------------------------
1212

1313
#_blt_tutorial_hip_compiler_start
14-
set(_compiler_root "/opt/rocm-5.6.0/llvm")
14+
set(_compiler_root "/opt/rocm-6.2.1/llvm")
1515

1616
set(CMAKE_C_COMPILER "${_compiler_root}/bin/amdclang" CACHE PATH "")
1717

@@ -28,7 +28,7 @@ set(ENABLE_FORTRAN ON CACHE BOOL "")
2828
# MPI
2929
#------------------------------------------------------------------------------
3030

31-
set(_mpi_root "/usr/tce/packages/cray-mpich-tce/cray-mpich-8.1.28-rocmcc-5.6.0")
31+
set(_mpi_root "/usr/tce/packages/cray-mpich-tce/cray-mpich-8.1.31-rocmcc-6.2.1")
3232

3333
set(MPI_C_COMPILER "${_mpi_root}/bin/mpicc" CACHE PATH "")
3434

@@ -53,15 +53,14 @@ set(ENABLE_MPI ON CACHE BOOL "")
5353
#------------------------------------------------------------------------------
5454

5555
#_blt_tutorial_useful_hip_variables_start
56-
set(_rocm_root "/opt/rocm-5.6.0")
56+
set(ROCM_ROOT_DIR "/opt/rocm-6.2.1" CACHE PATH "")
5757

5858
set(ENABLE_HIP ON CACHE BOOL "")
5959

60-
set(HIP_ROOT_DIR "${_rocm_root}/hip" CACHE STRING "")
61-
6260
set(CMAKE_HIP_ARCHITECTURES "gfx90a" CACHE STRING "")
6361

64-
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags -L${_rocm_root}/hip/../llvm/lib -L${_rocm_root}/hip/lib -Wl,-rpath,${_rocm_root}/hip/../llvm/lib:${_rocm_root}/hip/lib -lpgmath -lflang -lflangrti -lompstub -lamdhip64 -L${_rocm_root}/hip/../lib64 -Wl,-rpath,${_rocm_root}/hip/../lib64 -L${_rocm_root}/hip/../lib -Wl,-rpath,${_rocm_root}/hip/../lib -lamd_comgr -lhsa-runtime64 " CACHE STRING "")
62+
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags -L${ROCM_ROOT_DIR}/llvm/lib -L${ROCM_ROOT_DIR}/lib -Wl,-rpath,${ROCM_ROOT_DIR}/llvm/lib:${ROCM_ROOT_DIR}/lib -lpgmath -lflang -lflangrti -lompstub -lamdhip64 -L${ROCM_ROOT_DIR}/lib64 -Wl,-rpath,${ROCM_ROOT_DIR}/lib64 -L${ROCM_ROOT_DIR}/lib -Wl,-rpath,${ROCM_ROOT_DIR}/lib -lamd_comgr -lhsa-runtime64 " CACHE STRING "")
63+
6564
#_blt_tutorial_useful_hip_variables_end
6665

6766
#------------------------------------------------

0 commit comments

Comments
 (0)