Skip to content

Commit e73d8f8

Browse files
authored
[compiler-rt] Support unit tests for the GPU build (llvm#187895)
Summary: This PR enables the basic unit tests for builtins to be run on the GPU architectures. Other targets like profiling are supported, but the host-device natures will make it more difficult to adequately unit test. It may be be possible to do basic tests there, to simply verify that counters are present and in the proper format for when they are copied to the host.
1 parent 4eedd51 commit e73d8f8

6 files changed

Lines changed: 31 additions & 3 deletions

File tree

compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@ macro(construct_compiler_rt_default_triple)
424424
endif()
425425
endif()
426426

427+
# Try to locate the GPU loader utility for GPU unit tests.
428+
if(COMPILER_RT_GPU_BUILD AND NOT COMPILER_RT_EMULATOR)
429+
get_filename_component(_compiler_path "${CMAKE_C_COMPILER}" DIRECTORY)
430+
find_program(COMPILER_RT_EMULATOR
431+
NAMES llvm-gpu-loader NO_DEFAULT_PATH
432+
PATHS ${LLVM_BINARY_DIR}/bin ${_compiler_path})
433+
if(COMPILER_RT_EMULATOR)
434+
message(STATUS "Found GPU loader for testing: ${COMPILER_RT_EMULATOR}")
435+
endif()
436+
unset(_compiler_path)
437+
endif()
438+
427439
# Determine if test target triple is specified explicitly, and doesn't match the
428440
# default.
429441
if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL LLVM_TARGET_TRIPLE)

compiler-rt/cmake/caches/GPU.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file sets up a CMakeCache for GPU builds of compiler-rt. This supports
22
# amdgcn and nvptx builds targeting the builtins and profile libraries.
33

4-
set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
4+
set(COMPILER_RT_INCLUDE_TESTS ON CACHE BOOL "")
55
set(COMPILER_RT_HAS_SAFESTACK OFF CACHE BOOL "")
66
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
77

compiler-rt/test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS)
9898
compiler_rt_test_runtime(${sanitizer})
9999
endforeach()
100100
endif()
101-
if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
101+
if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE
102+
AND NOT COMPILER_RT_GPU_BUILD)
102103
compiler_rt_test_runtime(profile)
103104
endif()
104105
if(COMPILER_RT_BUILD_CTX_PROFILE)

compiler-rt/test/builtins/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ foreach(arch ${BUILTIN_TEST_ARCH})
4949
set(BUILTINS_TEST_TARGET_ARCH ${arch})
5050
string(TOLOWER "-${arch}-${OS_NAME}" BUILTINS_TEST_CONFIG_SUFFIX)
5151
get_test_cc_for_arch(${arch} BUILTINS_TEST_TARGET_CC BUILTINS_TEST_TARGET_CFLAGS)
52+
53+
if(COMPILER_RT_GPU_BUILD)
54+
if("${arch}" MATCHES "amdgcn")
55+
list(APPEND BUILTINS_TEST_TARGET_CFLAGS
56+
-Wno-multi-gpu -flto -mcpu=native -nogpulib -startfiles -stdlib)
57+
elseif("${arch}" MATCHES "nvptx")
58+
list(APPEND BUILTINS_TEST_TARGET_CFLAGS
59+
-Wno-multi-gpu -flto -march=native -nogpulib -startfiles -stdlib)
60+
endif()
61+
list(APPEND BUILTINS_TEST_TARGET_CFLAGS --target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
62+
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
63+
endif()
64+
5265
if (${arch} STREQUAL "armhf")
5366
list(APPEND BUILTINS_TEST_TARGET_CFLAGS -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET)
5467
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")

compiler-rt/test/builtins/Unit/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def get_libgcc_file_name():
158158

159159
# FIXME: Right now we don't compile the C99 complex builtins when using
160160
# clang-cl. Fix that.
161-
if not is_msvc:
161+
if not is_msvc and config.target_arch not in ("amdgcn", "nvptx64"):
162162
config.available_features.add("c99-complex")
163163

164164
builtins_is_msvc = get_required_attr(config, "builtins_is_msvc")

compiler-rt/test/lit.common.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,8 @@ def is_windows_lto_supported():
987987

988988

989989
def target_page_size():
990+
if config.target_arch in ("amdgcn", "nvptx64"):
991+
return 4096
990992
try:
991993
proc = subprocess.Popen(
992994
f"{emulator or ''} python3",

0 commit comments

Comments
 (0)