From 153b9512c2725c8d1a44b0ef67cc225b18a6c2fd Mon Sep 17 00:00:00 2001 From: Rahul Manocha Date: Tue, 13 Aug 2024 15:42:52 -0700 Subject: [PATCH] SWDEV-479073 - Use amdgpu-arch for sample 16 and 17 Change-Id: Ia6a2d7171d0ed296166f3bbf5f40c56305518de3 [ROCm/hip-tests commit: b8a0b33f67e415c6cc62c2ac4fb745b73710db5b] --- .../16_assembly_to_executable/CMakeLists.txt | 34 ++++++++++++++++++ .../17_llvm_ir_to_executable/CMakeLists.txt | 35 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/projects/hip-tests/samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt b/projects/hip-tests/samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt index 032ac7a610..ad00fe1cce 100644 --- a/projects/hip-tests/samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt +++ b/projects/hip-tests/samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt @@ -41,6 +41,40 @@ if(NOT DEFINED GPU_ARCH) set(GPU_ARCH gfx900 gfx906 gfx908 gfx90a gfx940 gfx941 gfx942 gfx1010 gfx1030 gfx1100 gfx1101 gfx1102 gfx1103) endif() +# Append Current device arch from rocm_agent_enumerator +# if rocm_agent_enumerator is not found, support --offload-arch +# to pass arch use format like -DOFFLOAD_ARCH_STR="--offload-arch=gfx1032 --offload-arch=gfx1031" +if(UNIX) +set(ARCH_PATH "${ROCM_PATH}/llvm/bin/amdgpu-arch") +else() +set(ARCH_PATH "${ROCM_PATH}/bin/amdgpu-arch") +endif() + +if(NOT DEFINED OFFLOAD_ARCH_STR + AND EXISTS "${ARCH_PATH}" + AND HIP_PLATFORM STREQUAL "amd") + execute_process(COMMAND "${ARCH_PATH}" + OUTPUT_VARIABLE HIP_GPU_ARCH + RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT HIP_GPU_ARCH STREQUAL "") + string(REGEX REPLACE "\n" ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH}") + list(REMOVE_DUPLICATES HIP_GPU_ARCH_LIST) + list(LENGTH HIP_GPU_ARCH_LIST HIP_GPU_ARCH_LEN) + foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST}) + list(APPEND GPU_ARCH ${_hip_gpu_arch}) + endforeach() + else() + message(STATUS "ROCm Agent Enumerator found no valid architectures") + endif() +elseif(DEFINED OFFLOAD_ARCH_STR) + string(REPLACE "--offload-arch=" "" HIP_GPU_ARCH_LIST ${OFFLOAD_ARCH_STR}) + string(REGEX REPLACE " " ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH_LIST}") + foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST}) + list(APPEND GPU_ARCH ${_hip_gpu_arch}) + endforeach() +endif() + if(TARGET build_cookbook) set(ALL_OPTION ) else() diff --git a/projects/hip-tests/samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt b/projects/hip-tests/samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt index 3f541d10d7..36807c536d 100644 --- a/projects/hip-tests/samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt +++ b/projects/hip-tests/samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt @@ -44,6 +44,41 @@ if(NOT DEFINED GPU_ARCH) set(GPU_ARCH gfx900 gfx906 gfx908 gfx90a gfx940 gfx941 gfx942 gfx1010 gfx1030 gfx1100 gfx1101 gfx1102 gfx1103) endif() +# Append Current device arch from rocm_agent_enumerator +# if rocm_agent_enumerator is not found, support --offload-arch +# to pass arch use format like -DOFFLOAD_ARCH_STR="--offload-arch=gfx1032 --offload-arch=gfx1031" + +if(UNIX) +set(ARCH_PATH "${ROCM_PATH}/llvm/bin/amdgpu-arch") +else() +set(ARCH_PATH "${ROCM_PATH}/bin/amdgpu-arch") +endif() + +if(NOT DEFINED OFFLOAD_ARCH_STR + AND EXISTS "${ARCH_PATH}" + AND HIP_PLATFORM STREQUAL "amd") + execute_process(COMMAND "${ARCH_PATH}" + OUTPUT_VARIABLE HIP_GPU_ARCH + RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT HIP_GPU_ARCH STREQUAL "") + string(REGEX REPLACE "\n" ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH}") + list(REMOVE_DUPLICATES HIP_GPU_ARCH_LIST) + list(LENGTH HIP_GPU_ARCH_LIST HIP_GPU_ARCH_LEN) + foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST}) + list(APPEND GPU_ARCH ${_hip_gpu_arch}) + endforeach() + else() + message(STATUS "ROCm Agent Enumerator found no valid architectures") + endif() +elseif(DEFINED OFFLOAD_ARCH_STR) + string(REPLACE "--offload-arch=" "" HIP_GPU_ARCH_LIST ${OFFLOAD_ARCH_STR}) + string(REGEX REPLACE " " ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH_LIST}") + foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST}) + list(APPEND GPU_ARCH ${_hip_gpu_arch}) + endforeach() +endif() + if(TARGET build_cookbook) set(ALL_OPTION ) else()