From ec3d97ab8dc9beac37f7ddf83848c9ed41a7754e Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Thu, 22 Aug 2024 11:58:01 +0100 Subject: [PATCH] SWDEV-477039 - Use rocm_agent_enumerator to setup targets for static build The amdgpu-arch tool is not supported for static build. This commit adds changes to detect the build type during cmake config and use the rocm_agent_enumerator for static build. Change-Id: I8a295e01f54075507390ef540f16b28bb20237a9 [ROCm/clr commit: a02888af58bb231ca8a7b8d7fd6842051af6f11b] --- projects/clr/hipamd/hip-config-amd.cmake | 21 +++++++++++++++++---- projects/clr/hipamd/hip-config.cmake.in | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/hip-config-amd.cmake b/projects/clr/hipamd/hip-config-amd.cmake index 4cb52ceba9..1ac1716eb9 100755 --- a/projects/clr/hipamd/hip-config-amd.cmake +++ b/projects/clr/hipamd/hip-config-amd.cmake @@ -69,11 +69,16 @@ endif() # If AMDGPU_TARGETS is not defined by the app, amdgpu-arch is run to find the gpu archs # of all the devices present in the machine if(NOT AMDGPU_TARGETS) - if (WIN32) - set(AMDGPU_ARCH "${HIP_CLANG_ROOT}/bin/amdgpu-arch.exe") + if(BUILD_SHARED_LIBS) + if (WIN32) + set(AMDGPU_ARCH "${HIP_CLANG_ROOT}/bin/amdgpu-arch.exe") + else() + set(AMDGPU_ARCH "${HIP_CLANG_ROOT}/bin/amdgpu-arch") + endif() else() - set(AMDGPU_ARCH "${HIP_CLANG_ROOT}/bin/amdgpu-arch") + set(AMDGPU_ARCH "${ROCM_PATH}/bin/rocm_agent_enumerator") endif() + execute_process( COMMAND ${AMDGPU_ARCH} RESULT_VARIABLE AMDGPU_ARCH_RESULT @@ -90,8 +95,11 @@ if(NOT AMDGPU_TARGETS) " Output: '${AMDGPU_ARCH_OUTPUT}'\n \n" " As a result, --offload-arch will not be set for subsuqent\n" - " compilations, and the default architecture (gfx906) will be used\n") + " compilations, and the default architecture\n" + " (gfx906 for dynamic build / gfx942 for static build) will be used\n") else() + # rocm_agent_enumerator adds gfx000 entry + string(REPLACE "gfx000\n" "" AMDGPU_ARCH_OUTPUT "${AMDGPU_ARCH_OUTPUT}") if (NOT AMDGPU_ARCH_OUTPUT STREQUAL "") string(REPLACE "\n" ";" AMDGPU_ARCH_OUTPUT ${AMDGPU_ARCH_OUTPUT}) set(AMDGPU_TARGETS ${AMDGPU_ARCH_OUTPUT} CACHE STRING "AMD GPU targets to compile for") @@ -99,6 +107,11 @@ if(NOT AMDGPU_TARGETS) endif() endif() +if (NOT AMDGPU_TARGETS AND NOT BUILD_SHARED_LIBS) + # The default architecture is gfx942 for static build + set(AMDGPU_TARGETS "gfx942" CACHE STRING "AMD GPU targets to compile for") +endif() + set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "GPU targets to compile for") if(NOT WIN32) find_dependency(amd_comgr HINTS ${ROCM_PATH} PATHS "/opt/rocm") diff --git a/projects/clr/hipamd/hip-config.cmake.in b/projects/clr/hipamd/hip-config.cmake.in index 8b63fdc8bb..d8565603e1 100755 --- a/projects/clr/hipamd/hip-config.cmake.in +++ b/projects/clr/hipamd/hip-config.cmake.in @@ -122,6 +122,7 @@ endif() if(HIP_PLATFORM STREQUAL "amd") set(HIP_RUNTIME "rocclr") set(HIP_COMPILER "clang") + set(BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@") include( "${hip_LIB_INSTALL_DIR}/cmake/hip/hip-config-amd.cmake" ) elseif(HIP_PLATFORM STREQUAL "nvidia") set(HIP_RUNTIME "cuda")