Skip to content

Commit 95a2eb7

Browse files
authored
[libcxx] Add testing configuration for GPU targets (llvm#104515)
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 002a0a2 commit 95a2eb7

File tree

7 files changed

+83
-0
lines changed

7 files changed

+83
-0
lines changed

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;SHELL:-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 -I %{include-dir} '
7+
'-I %{target-include-dir} -I %{libcxx-dir}/test/support'
8+
))
9+
config.substitutions.append(('%{link_flags}',
10+
'-nostdlib++ -startfiles -stdlib '
11+
'-Wl,-mllvm,-amdgpu-lower-global-ctor-dtor=0 '
12+
'-L %{lib-dir} -lc++ -lc++abi -lclang_rt.builtins'
13+
))
14+
15+
config.substitutions.append(('%{exec}',
16+
'%{executor}'
17+
))
18+
19+
config.stdlib = 'llvm-libc++'
20+
21+
import os, site
22+
site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils'))
23+
import libcxx.test.params, libcxx.test.config
24+
libcxx.test.config.configure(
25+
libcxx.test.params.DEFAULT_PARAMETERS,
26+
libcxx.test.features.DEFAULT_FEATURES,
27+
config,
28+
lit_config
29+
)
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 -march=native'))
5+
config.substitutions.append(('%{compile_flags}',
6+
'-nogpulib -fno-builtin-printf -I %{include-dir} '
7+
'-I %{target-include-dir} -I %{libcxx-dir}/test/support'
8+
))
9+
config.substitutions.append(('%{link_flags}',
10+
'-nostdlib++ -startfiles -stdlib '
11+
'-L %{lib-dir} -lc++ -lc++abi '
12+
'-Wl,--suppress-stack-size-warning '
13+
'-Wl,-mllvm,-nvptx-lower-global-ctor-dtor=1 '
14+
'-Wl,-mllvm,-nvptx-emit-init-fini-kernel'
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/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)