Skip to content

Commit d1aef6d

Browse files
committed
[libcxx] Add testing configuration for GPU targets
Summary: The GPU runs these tests using the files built from the `libc` project. These will be placed in `include/<triple>` and `lib/<triple>`. We use the `amdhsa-loader` and `nvptx-loader` tools, which are also provided by `libc`. These launch a kernel called `_start` which calls `main` so we can pretend like GPU programs are normal terminal applications. We force serial exeuction here, because `llvm-lit` runs way too many processes in parallel, which has a bad habit of making the GPU drivers hang or run out of resources. This allows the compilation to be run in parallel while the jobs themselves are serialized via a file lock. In the future this can likely be refined to accept user specified architectures, or better handle including the root directory by exposing that instead of just `include/<triple>/c++/v1/`. This currently fails ~1% of the tests on AMDGPU and ~3% of the tests on NVPTX. This will hopefully be reduced further, and later patches can XFAIL a lot of them once it's down to a reasonable number. Future support will likely want to allow passing in a custom architecture instead of simply relying on `-mcpu=native`.
1 parent b16e694 commit d1aef6d

File tree

9 files changed

+93
-0
lines changed

9 files changed

+93
-0
lines changed

libcxx/cmake/Modules/HandleLibC.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
2222
if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
2323
target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
2424
endif()
25+
get_target_property(libcxx-libc-dir libc-headers INTERFACE_INCLUDE_DIRECTORIES)
26+
set(LIBCXX_LIBC_INCLUDE_DIR ${libcxx-libc-dir})
2527

2628
add_library(libcxx-libc-static INTERFACE)
2729
if (TARGET libc)
2830
target_link_libraries(libcxx-libc-static INTERFACE libc)
31+
get_target_property(libcxx-libc-dir libc ARCHIVE_OUTPUT_DIRECTORY)
32+
set(LIBCXX_LIBC_LIBRARY_DIR ${libcxx-libc-dir})
2933
endif()
3034
if (TARGET libm)
3135
target_link_libraries(libcxx-libc-static INTERFACE libm)

libcxx/cmake/caches/AMDGPU.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
2727
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
2828
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
2929

30+
# Test configuration.
31+
set(LIBCXX_TEST_CONFIG "amdgpu-libc++-shared.cfg.in" CACHE STRING "")
32+
set(LIBCXX_TEST_PARAMS "optimization=none;long_tests=False;executor=amdhsa-loader" CACHE STRING "")
33+
3034
# Necessary compile flags for AMDGPU.
3135
set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
3236
"-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")

libcxx/cmake/caches/NVPTX.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
2727
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
2828
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
2929

30+
# Test configuration.
31+
set(LIBCXX_TEST_CONFIG "nvptx-libc++-shared.cfg.in" CACHE STRING "")
32+
set(LIBCXX_TEST_PARAMS "optimization=none;long_tests=False;executor=nvptx-loader" CACHE STRING "")
33+
3034
# Necessary compile flags for NVPTX.
3135
set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
3236
"-nogpulib;-flto;-fconvergent-functions;--cuda-feature=+ptx63" CACHE STRING "")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
2+
3+
config.substitutions.append(('%{flags}',
4+
f'--target={config.target_triple} -Wno-multi-gpu -flto -mcpu=native'))
5+
config.substitutions.append(('%{compile_flags}',
6+
'-nogpulib -fno-builtin-printf -nogpuinc -nostdlibinc '
7+
'-I %{include-dir} -I %{libc-include-dir} '
8+
'-I %{target-include-dir} -I %{libcxx-dir}/test/support'
9+
))
10+
config.substitutions.append(('%{link_flags}',
11+
'-nostdlib++ -L %{libc-dir} %{libc-dir}/crt1.o -lc -lm '
12+
'-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0 '
13+
'-L %{lib-dir} -L %{libc-dir} -lc++ -lc++abi -lclang_rt.builtins '
14+
))
15+
16+
config.substitutions.append(('%{exec}',
17+
'%{executor} --no-parallelism'
18+
))
19+
20+
config.stdlib = 'llvm-libc++'
21+
22+
import os, site
23+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
24+
import libcxx.test.params, libcxx.test.config
25+
libcxx.test.config.configure(
26+
libcxx.test.params.DEFAULT_PARAMETERS,
27+
libcxx.test.features.DEFAULT_FEATURES,
28+
config,
29+
lit_config
30+
)

libcxx/test/configs/cmake-bridge.cfg.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ config.substitutions.append(('%{target-include-dir}', '@LIBCXX_TESTING_INSTALL_P
3030
config.substitutions.append(('%{lib-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_LIBRARY_DIR@'))
3131
config.substitutions.append(('%{module-dir}', '@LIBCXX_TESTING_INSTALL_PREFIX@/@LIBCXX_INSTALL_MODULES_DIR@'))
3232
config.substitutions.append(('%{test-tools-dir}', '@LIBCXX_TEST_TOOLS_PATH@'))
33+
34+
# Available if building libc++ on top of llvm-libc.
35+
config.substitutions.append(('%{libc-dir}', '@LIBCXX_LIBC_LIBRARY_DIR@'))
36+
config.substitutions.append(('%{libc-include-dir}', '@LIBCXX_LIBC_INCLUDE_DIR@'))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
2+
3+
config.substitutions.append(('%{flags}',
4+
f'--target={config.target_triple} -Wno-multi-gpu -flto -march=native'))
5+
config.substitutions.append(('%{compile_flags}',
6+
'-nogpulib -fno-builtin-printf -nogpuinc -nostdlibinc '
7+
'-I %{include-dir} -I %{libc-include-dir} '
8+
'-I %{target-include-dir} -I %{libcxx-dir}/test/support'
9+
))
10+
config.substitutions.append(('%{link_flags}',
11+
'-nostdlib++ -L %{libc-dir} %{libc-dir}/crt1.o -lc -lm '
12+
'-L %{lib-dir} -L %{libc-dir} -lc++ -lc++abi -lclang_rt.builtins '
13+
'-Wl,--suppress-stack-size-warning '
14+
'-Wl,-mllvm,-nvptx-lower-global-ctor-dtor=1 '
15+
'-Wl,-mllvm,-nvptx-emit-init-fini-kernel'
16+
))
17+
config.substitutions.append(('%{exec}',
18+
'%{executor} --no-parallelism'
19+
))
20+
21+
config.stdlib = 'llvm-libc++'
22+
23+
import os, site
24+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
25+
import libcxx.test.params, libcxx.test.config
26+
libcxx.test.config.configure(
27+
libcxx.test.params.DEFAULT_PARAMETERS,
28+
libcxx.test.features.DEFAULT_FEATURES,
29+
config,
30+
lit_config
31+
)

libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// FIXME: This takes over an hour to compile, disable for now.
10+
// UNSUPPORTED: LIBCXX-AMDGPU-FIXME
11+
// UNSUPPORTED: LIBCXX-NVPTX-FIXME
12+
913
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1014
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
1115

libcxx/test/std/strings/basic.string/string.modifiers/string_replace/replace_with_range.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// FIXME: This takes over an hour to compile, disable for now.
10+
// UNSUPPORTED: LIBCXX-AMDGPU-FIXME
11+
// UNSUPPORTED: LIBCXX-NVPTX-FIXME
12+
913
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1014
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=10000000
1115
// ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-ops-limit): -fconstexpr-ops-limit=70000000

libcxx/utils/libcxx/test/features.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ def _mingwSupportsModules(cfg):
496496
""",
497497
),
498498
),
499+
Feature(
500+
name="LIBCXX-AMDGPU-FIXME",
501+
when=lambda cfg: "__AMDGPU__" in compilerMacros(cfg),
502+
),
503+
Feature(
504+
name="LIBCXX-NVPTX-FIXME",
505+
when=lambda cfg: "__NVPTX__" in compilerMacros(cfg),
506+
),
499507
Feature(
500508
name="can-create-symlinks",
501509
when=lambda cfg: "_WIN32" not in compilerMacros(cfg)

0 commit comments

Comments
 (0)