Skip to content

Commit d2a7475

Browse files
committed
CMake: CMAKE_HIP_ARCHITECTURES thoughts. far from trivial, maybe just native for now?
1 parent 97ab805 commit d2a7475

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

cmake/GPUArchitectures.cmake

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 3.25.2...4.3.0 FATAL_ERROR)
12
#[[[
23
# Handle CMAKE_CUDA_ARCHITECTURES/CMAKE_HIP_ARCHITECTURES gracefully, allowing library CMakeLists.txt to provide a sane library default if not user-specified
34
#
@@ -69,15 +70,15 @@ endfunction()
6970
# Set the CMAKE_CUDA_ARCHITECTURES/CMAKE_HIP_ARCHITECTURES value to the environment/cache provided value, or generate a CUDA/HIP version-appropriate default value for a library (i.e all-major or equivalent)
7071
#
7172
# For CUDA:
72-
# If the ENV{CUDAARCHS}, or CMAKE_CUDA_ARCHITECTURES cache variable did not specify a value before the CUDA language was enabled, use build an version-appropriate default for a llibrary, based on the CMake and NVCC version.
73+
# If the ENV{CUDAARCHS}, or CMAKE_CUDA_ARCHITECTURES cache variable did not specify a value before the CUDA language was enabled, use a CUDA version-appropriate default for a llibrary, based on the CMake and NVCC version.
7374
# Effectively all-major (-real for all major architectures, and PTX for the most recent)
7475
#
7576
# If the user provided a value, it will be validated against nvcc --help unless NO_VALIDATE_ARCHITECTURES is set, or was set in a previous call to flamegpu_init_gpu_architectures without a PROJECT.
7677
#
77-
# For HIP:
78-
# Todo: figure this out
79-
# Todo: what is the sensible default for HIP?
80-
# Todo: what bout hip but with PLATFORM=nvidia? should re-use the cuda bits somehow.
78+
# For HIP (with CMAKE_HIP_PLATFORM=amd):
79+
# If CMAKE_HIP_ARCHITECTURES cache variable did not specify a value before the HIP language was enabled, use a HIP version-appropriate default for a library, based on the CMake and HIP compiler verisions
80+
# This should effectively be the equivalent to all-major
81+
# Todo: what about hip but with PLATFORM=nvidia? should re-use the cuda bits somehow.
8182
#
8283
# CUDA or HIP must be enabled as a language prior to this method being called.
8384
# Todo: This will be a problem for project-name injection that is also CUDA/HIP compatible. Might have to remove that option...
@@ -93,11 +94,10 @@ function(flamegpu_set_gpu_architectures)
9394
""
9495
${ARGN}
9596
)
96-
# This function requires that the CUDA language is enabled on the current project.
97+
# This function requires that CUDA or HIP language is enabled on the current project.
9798
if(NOT (CMAKE_CUDA_COMPILER_LOADED OR CMAKE_HIP_COMPILER_LOADED))
9899
# If in the injected project code, give a different error message
99-
# Todo: is this still viable?
100-
# Todo: update messages to account for HIP
100+
# Todo: is it still viable to support injection of this method? given the project may enable languages?
101101
if(DEFINED flamegpu_IN_PROJECT_INCLUDE AND flamegpu_IN_PROJECT_INCLUDE)
102102
message(FATAL_ERROR
103103
" ${CMAKE_CURRENT_FUNCTION} requires the CUDA or HIP language to be enabled\n"
@@ -113,7 +113,7 @@ function(flamegpu_set_gpu_architectures)
113113

114114
endif()
115115

116-
# Handle CUDA (Todo: handle hip with nvidia the same way?)
116+
# Handle CUDA (Todo: hip but with CUDA as the backend?)
117117
if (CMAKE_CUDA_COMPILER_LOADED)
118118
# Query NVCC for the acceptable SM values, this is used in multiple places
119119
if(NOT DEFINED SUPPORTED_CUDA_ARCHITECTURES_NVCC)
@@ -141,12 +141,6 @@ function(flamegpu_set_gpu_architectures)
141141
set(using_keyword_arch FALSE)
142142
# native requires CMake >= 3.24, and must be the only option.
143143
if("native" IN_LIST CMAKE_CUDA_ARCHITECTURES)
144-
# Error if CMake is too old
145-
if(CMAKE_VERSION VERSION_LESS 3.24)
146-
message(FATAL_ERROR
147-
" CMAKE_CUDA_ARCHITECTURES value `native` requires CMake >= 3.24.\n"
148-
" CMAKE_CUDA_ARCHITECTURES=\"${CMAKE_CUDA_ARCHITECTURES}\"")
149-
endif()
150144
# Error if there are multiple architectures specified.
151145
if(arch_count GREATER 1)
152146
message(FATAL_ERROR
@@ -157,12 +151,6 @@ function(flamegpu_set_gpu_architectures)
157151
endif()
158152
# all requires 3.23, and must be the sole value.
159153
if("all" IN_LIST CMAKE_CUDA_ARCHITECTURES)
160-
# Error if CMake is too old
161-
if(CMAKE_VERSION VERSION_LESS 3.23)
162-
message(FATAL_ERROR
163-
" CMAKE_CUDA_ARCHITECTURES value `all` requires CMake >= 3.23.\n"
164-
" CMAKE_CUDA_ARCHITECTURES=\"${CMAKE_CUDA_ARCHITECTURES}\"")
165-
endif()
166154
# Error if there are multiple architectures specified.
167155
if(arch_count GREATER 1)
168156
message(FATAL_ERROR
@@ -173,12 +161,6 @@ function(flamegpu_set_gpu_architectures)
173161
endif()
174162
# all-major requires 3.23, and must be the sole value.
175163
if("all-major" IN_LIST CMAKE_CUDA_ARCHITECTURES)
176-
# Error if CMake is too old
177-
if(CMAKE_VERSION VERSION_LESS 3.23)
178-
message(FATAL_ERROR
179-
" CMAKE_CUDA_ARCHITECTURES value `all-major` requires CMake >= 3.23.\n"
180-
" CMAKE_CUDA_ARCHITECTURES=\"${CMAKE_CUDA_ARCHITECTURES}\"")
181-
endif()
182164
# Error if there are multiple architectures specified.
183165
if(arch_count GREATER 1)
184166
message(FATAL_ERROR
@@ -226,6 +208,14 @@ function(flamegpu_set_gpu_architectures)
226208
# Promote the value to the cache for reconfigure persistence, as the enable_language sets it on the cache
227209
set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}" CACHE STRING "CUDA architectures" FORCE)
228210
elseif(CMAKE_HIP_COMPILER_LOADED)
229-
message(AUTHOR_WARNING "Todo: implement flamegpu_set_gpu_architectures for HIP")
211+
# I cannot find a good, way to programatically get a list of (major) device architectrues for a given version of rocm.
212+
# rocm_agent_enumerator --all only lists architectures in this machine
213+
# amdclang --target=amdgcn-amd-amdhsa --print-supported-cpus lists all possible gpu architectures for this version of clang, including those not officially supported by this rocm release
214+
# and there are 53 listed for rocm 7.2 (amdclang --target=amdgcn-amd-amdhsa --print-supported-cpus |& grep gfx | sort | uniq | wc -l ))
215+
# https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html for 7.2.1 included 9 supported architectures gfx1201;gfx1200;gfx1101;gfx1100;gfx1030;gfx950;gfx942;gfx90a;gfx908
216+
# The ROCm on Radeon and Ryzen docs (https://rocm.docs.amd.com/projects/radeon-ryzen/en/latest/docs/compatibility/compatibilityryz/native_linux/native_linux_compatibility.html) include some additioanl architectrues, but seems to be very partial support.
217+
# Generic architectures are the closest thing to building for SM_50 and it running on 52. I.e. gfx10-1-generic, but this might not be available for all supported families (https://rocm.docs.amd.com/projects/llvm-project/en/latest/conceptual/code-portability.html#generic-code-objects)
218+
# As this is so hard to detect, we probably just leave default as to use the native build and document this? Then for any redistributable CI either list everything, or use the -generic architectures (whcich could be extracted via --target=amdgcn-amd-amdhsa --print-supported-cpus)?
219+
message(AUTHOR_WARNING "Todo: implement flamegpu_set_gpu_architectures for HIP. This is non trivial.")
230220
endif()
231221
endfunction()

0 commit comments

Comments
 (0)