Skip to content

Commit 76af6e7

Browse files
authored
[libc] Manually set the AMDGPU code object version (#65986)
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.
1 parent 2344a72 commit 76af6e7

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ function(_build_gpu_objects fq_target_name internal_target_name)
278278
target_compile_options(${internal_target_name} BEFORE PRIVATE
279279
${common_compile_options} --target=${LIBC_GPU_TARGET_TRIPLE})
280280
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
281-
target_compile_options(${internal_target_name} PRIVATE -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto)
281+
target_compile_options(${internal_target_name} PRIVATE
282+
"SHELL:-Xclang -mcode-object-version=none"
283+
-mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto)
282284
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
283285
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
284286
target_compile_options(${internal_target_name} PRIVATE ${nvptx_options})

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ function(add_integration_test test_name)
528528
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
529529
target_compile_options(${fq_build_target_name} PRIVATE
530530
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
531-
-flto --target=${LIBC_GPU_TARGET_TRIPLE})
531+
-flto --target=${LIBC_GPU_TARGET_TRIPLE}
532+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
532533
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
533534
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
534535
target_compile_options(${fq_build_target_name} PRIVATE
@@ -578,7 +579,9 @@ set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
578579
# The GPU build requires overriding the default CMake triple and architecture.
579580
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
580581
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
581-
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto --target=${LIBC_GPU_TARGET_TRIPLE})
582+
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
583+
--target=${LIBC_GPU_TARGET_TRIPLE}
584+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
582585
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
583586
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
584587
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS

libc/cmake/modules/prepare_libc_gpu_build.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
115115
get_filename_component(LIBC_CUDA_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE)
116116
endif()
117117
endif()
118+
119+
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
120+
# The AMDGPU environment uses different code objects to encode the ABI for
121+
# kernel calls and intrinsic functions. We want to specify this manually to
122+
# conform to whatever the test suite was built to handle.
123+
# FIXME: The test suite currently hangs when compiled targeting version five.
124+
# This occurrs during traversal of the callback array in the startup code. We
125+
# deliberately use version four until this can be addressed.
126+
set(LIBC_GPU_CODE_OBJECT_VERSION 4)
127+
endif()

libc/startup/gpu/amdgpu/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_startup_object(
1313
-nogpulib # Do not include any GPU vendor libraries.
1414
-mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
1515
-emit-llvm # AMDGPU's intermediate object file format is bitcode.
16+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI.
1617
--target=${LIBC_GPU_TARGET_TRIPLE}
1718
NO_GPU_BUNDLE # Compile this file directly without special GPU handling.
1819
)
@@ -26,4 +27,5 @@ target_link_libraries(
2627
"--target=${LIBC_GPU_TARGET_TRIPLE}"
2728
"-flto"
2829
"-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0"
30+
"-Wl,-mllvm,-amdhsa-code-object-version=${LIBC_GPU_CODE_OBJECT_VERSION}"
2931
)

libc/test/IntegrationTest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
33
-mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
44
-emit-llvm # AMDGPU's intermediate object file format is bitcode.
55
--target=${LIBC_GPU_TARGET_TRIPLE}
6+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION} # Manually set the ABI.
67
)
78
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
89
set(TEST_COMPILE_FLAGS

0 commit comments

Comments
 (0)