Skip to content

Commit

Permalink
[libc] Manually set the AMDGPU code object version (#65986)
Browse files Browse the repository at this point in the history
Summary:
There is currently effort to change over the default AMDGPU code object
version #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.
  • Loading branch information
jhuber6 committed Sep 11, 2023
1 parent 2344a72 commit 76af6e7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion libc/cmake/modules/LLVMLibCObjectRules.cmake
Expand Up @@ -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})
Expand Down
7 changes: 5 additions & 2 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions libc/cmake/modules/prepare_libc_gpu_build.cmake
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions libc/startup/gpu/amdgpu/CMakeLists.txt
Expand Up @@ -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.
)
Expand All @@ -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}"
)
1 change: 1 addition & 0 deletions libc/test/IntegrationTest/CMakeLists.txt
Expand Up @@ -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
Expand Down

0 comments on commit 76af6e7

Please sign in to comment.