diff options
author | Joseph Huber <35342157+jhuber6@users.noreply.github.com> | 2023-09-11 13:07:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 13:07:56 -0500 |
commit | 76af6e77c0e5d8c444daa3aea07f381c07b17da7 (patch) | |
tree | e6262fb8deb29a7feb9a0c478677649ede50f399 | |
parent | 2344a72dd63661098244b3bc43696710686ef9d9 (diff) | |
download | llvm-76af6e77c0e5d8c444daa3aea07f381c07b17da7.zip llvm-76af6e77c0e5d8c444daa3aea07f381c07b17da7.tar.gz llvm-76af6e77c0e5d8c444daa3aea07f381c07b17da7.tar.bz2 |
[libc] Manually set the AMDGPU code object version (#65986)
Summary:
There is currently effort to change over the default AMDGPU code object
version https://github.com/llvm/llvm-project/pull/65410. However, this
unfortunately causes problems in the LLVM LibC test suite that leads to
a hang while executing. This is most likely a bug to do with indirect
call optimization, as it can be avoided without optimizations or with
manually preventing inlining in the AMDGPU startup code.
This patch sets the AMDGPU code object version to be four explicitly on
the LibC test suite. This should unblock the efforts to move the default
to 5 without breaking the test suite. This isn't a great solution, but
there is currently some time pressure to get COV5 landed and this seems
to be the easiest solution.
-rw-r--r-- | libc/cmake/modules/LLVMLibCObjectRules.cmake | 4 | ||||
-rw-r--r-- | libc/cmake/modules/LLVMLibCTestRules.cmake | 7 | ||||
-rw-r--r-- | libc/cmake/modules/prepare_libc_gpu_build.cmake | 10 | ||||
-rw-r--r-- | libc/startup/gpu/amdgpu/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/test/IntegrationTest/CMakeLists.txt | 1 |
5 files changed, 21 insertions, 3 deletions
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index 2c3cf11..709acd9 100644 --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -278,7 +278,9 @@ function(_build_gpu_objects fq_target_name internal_target_name) target_compile_options(${internal_target_name} BEFORE PRIVATE ${common_compile_options} --target=${LIBC_GPU_TARGET_TRIPLE}) if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) - target_compile_options(${internal_target_name} PRIVATE -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto) + target_compile_options(${internal_target_name} PRIVATE + "SHELL:-Xclang -mcode-object-version=none" + -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) target_compile_options(${internal_target_name} PRIVATE ${nvptx_options}) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index 4d17dca..e1286b4 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -528,7 +528,8 @@ function(add_integration_test test_name) if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) target_compile_options(${fq_build_target_name} PRIVATE -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} - -flto --target=${LIBC_GPU_TARGET_TRIPLE}) + -flto --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) target_compile_options(${fq_build_target_name} PRIVATE @@ -578,7 +579,9 @@ set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT} # The GPU build requires overriding the default CMake triple and architecture. if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS - -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto --target=${LIBC_GPU_TARGET_TRIPLE}) + -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto + --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake index 063c3b3..0b6067f 100644 --- a/libc/cmake/modules/prepare_libc_gpu_build.cmake +++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake @@ -115,3 +115,13 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_filename_component(LIBC_CUDA_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE) endif() endif() + +if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) + # The AMDGPU environment uses different code objects to encode the ABI for + # kernel calls and intrinsic functions. We want to specify this manually to + # conform to whatever the test suite was built to handle. + # FIXME: The test suite currently hangs when compiled targeting version five. + # This occurrs during traversal of the callback array in the startup code. We + # deliberately use version four until this can be addressed. + set(LIBC_GPU_CODE_OBJECT_VERSION 4) +endif() diff --git a/libc/startup/gpu/amdgpu/CMakeLists.txt b/libc/startup/gpu/amdgpu/CMakeLists.txt index e7c0aea..723ed9b 100644 --- a/libc/startup/gpu/amdgpu/CMakeLists.txt +++ b/libc/startup/gpu/amdgpu/CMakeLists.txt @@ -13,6 +13,7 @@ add_startup_object( -nogpulib # Do not include any GPU vendor libraries. -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -emit-llvm # AMDGPU's intermediate object file format is bitcode. + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI. --target=${LIBC_GPU_TARGET_TRIPLE} NO_GPU_BUNDLE # Compile this file directly without special GPU handling. ) @@ -26,4 +27,5 @@ target_link_libraries( "--target=${LIBC_GPU_TARGET_TRIPLE}" "-flto" "-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0" + "-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}" ) diff --git a/libc/test/IntegrationTest/CMakeLists.txt b/libc/test/IntegrationTest/CMakeLists.txt index 0c4c38d..3d32b6c 100644 --- a/libc/test/IntegrationTest/CMakeLists.txt +++ b/libc/test/IntegrationTest/CMakeLists.txt @@ -3,6 +3,7 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -emit-llvm # AMDGPU's intermediate object file format is bitcode. --target=${LIBC_GPU_TARGET_TRIPLE} + -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI. ) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) set(TEST_COMPILE_FLAGS |