Commit Graph

92 Commits

Author SHA1 Message Date
Nick Desaulniers
6886a52d6d Revert "[libc] build with -Werror (#73966)"
This reverts commit 606653091d.

Post submit buildbots are now red. We can use these explicit errors to better
clean up existing warnings, then reland this.

Link: #73966
2023-12-04 11:31:59 -08:00
Nick Desaulniers
606653091d [libc] build with -Werror (#73966)
A recent commit introduced warnings observable when building unit tests.
If the
unit tests don't fail when warnings are introduced into the build, then
we
might fail to notice them in the stream of output from check-libc.

Link: https://github.com/llvm/llvm-project/pull/72763/files#r1410932348
2023-12-04 11:08:59 -08:00
Schrodinger ZHU Yifan
1886b1a580 [libc] add PREFER_GENERIC flag (#73744)
There are some basic vectorization features in standard architecture
specifications. Such as SSE/SSE2 for x86-64, or NEON for aarch64. Even
though such features are almost always available, we still need some
methods to test fallback routines without any vectorization.

Previous attempt in hsearch adds a DISABLE_SSE2_OPT flag that tries to
compile the code with -mno-sse2 in order to test specific table scanning
routines. However, it turns out that such flag may have some unwanted
side effects hindering portability.

This PR introduces PREFER_GENERIC as an alternative. When a target is
built with PREFER_GENERIC, cmake will define a macro
__LIBC_PREFER_GENERIC such that developers can selectively choose the
fallback routine based on the macro.
2023-11-28 23:47:48 -05:00
Schrodinger ZHU Yifan
81e3e7e5d4 [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (#73469)
This patch implements `hcreate(_r)/hsearch(_r)/hdestroy(_r)` as
specified in https://man7.org/linux/man-pages/man3/hsearch.3.html.

Notice that `neon/asimd` extension is not yet added in this patch. 

- The implementation is largely simplified from rust's
[`hashbrown`](https://github.com/rust-lang/hashbrown/blob/master/src/raw/mod.rs)
as we only consider fix-sized insertion-only hashtables. Technical
details are provided in code comments.

- This patch also contains a portable string hash function, which is
derived from [`aHash`](https://github.com/tkaitchuck/aHash)'s fallback
routine. Not using any SIMD acceleration, it has a good enough quality
(passing all SMHasher tests) and is not too bad in speed.

- Some general functionalities are added, such as `memory_size`,
`offset_to`(alignment), `next_power_of_two`, `is_power_of_two`.
`ctz/clz` are extended to support shorter integers.
2023-11-28 21:02:25 -05:00
Joseph Huber
9a6517e63a [libc][NFC] Do not emit init / fini kernels in NVPTX libc
Summray:
A recent patch upgrades the NVPTX ctor / dtor lowering pass to emit
kernels so other languages can call them. We do this manually in `libc`
so we do not need this. Use the provided flag to disable this step to
keep the created kernels cleaner.
2023-11-13 09:24:02 -06:00
Joseph Huber
e3d2a7d0a5 [libc] Compile the GPU functions with '-fconvergent-functions' (#70229)
Summary:
This patch simply adds the `-fconvergent-functions` flag to the GPU
compilation. This is in relation to the behaviour of SIMT
architectures under divergence. With the flag, we assume every function
is convergent by default and rely on the compiler's divergence analysis
to transform it if possible.

Fixes: https://github.com/llvm/llvm-project/issues/63853
2023-10-25 14:13:21 -05:00
Siva Chandra
599eadec28 [libc] Propagate printf config options from a single config header library. (#66979)
printf_core.parser is not yet updated to use the printf config options. It
does not use them currently anyway and the corresponding parser_test
should be updated to respect the config options.
2023-09-26 08:16:31 -07:00
Guillaume Chatelet
467077796a [reland][libc][cmake] Tidy compiler includes (#66783) (#66878)
This is a reland of #66783 a35a3b75b2
fixing the benchmark breakage.
2023-09-20 11:21:46 +02:00
Guillaume Chatelet
9feb0c9b6e Revert "[libc][cmake] Tidy compiler includes (#66783)" (#66822)
This reverts commit a35a3b75b2. This broke
libc benchmarks.
2023-09-19 23:18:08 +02:00
Guillaume Chatelet
a35a3b75b2 [libc][cmake] Tidy compiler includes (#66783)
We want to activate `llvm-header-guard` (#66477) but the current CMake
configuration includes paths that should be `isystem`. This PR restricts
the number of `-I` passed to the clang command line and correctly marks
the llvm libc include path as `isystem`.
2023-09-19 23:08:29 +02:00
Joseph Huber
c354ee8d18 [libc][GPU] Fix dependencies for externally installed stub files (#66653)
Summary:
The GPU build has a lot of magic around how we package the output.
Generally, the GPU needs to exist as a secondary fatbinary image for
offloading languages. This is because offloading languages pretend like
offloading to an accelerator is a single file. This then needs to be put
into a single file to make it mesh with the existing build
infrastructure. To work with this, the `libc` makes an installed version
of the library that simply embeds the GPU code into an empty stub file.

This wasn't being updated correctly, which lead to the installed `libc`
static library not being updated correctly when the underlying file was
changed. The previous behaviour only updated when the entrypoint itself
was modified, but not any of its headers. By adding a dependcy on the
actual *object* file we should now capture the regular CMake semantics.
2023-09-18 10:15:02 -05:00
Siva Chandra
17114f8b19 [libc] Remove common_libc_tuners.cmake and move options into config.json. (#66226)
The name has been changed to adhere to the config option naming format.
The necessary build changes to use the new option have also been made.
2023-09-13 22:17:00 -07:00
Siva Chandra
d25b4fae93 [libc][NFC] Make entrypoint alias targets real library targets. (#66044)
This is part of a libc wide CMake cleanup which aims to eliminate
certain explicitly duplicated logic which is available in CMake-3.20.
This change in particular makes the entrypoint aliases real library
targets so that they can be treated as normal library targets by other
libc build rules.
2023-09-13 08:35:23 -07:00
Joseph Huber
76af6e77c0 [libc] Manually set the AMDGPU code object version (#65986)
Summary:
There is currently effort to change over the default AMDGPU code object
version https://github.com/llvm/llvm-project/pull/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.
2023-09-11 13:07:56 -05:00
Joseph Huber
71168f6889 [libc] Build the libc objects using a generic AMDGPU ABI (#65782)
Summary:
AMDGPU binaries use a "code object" as the ABI indicator. We are
currently trying to move over to a newer code object. We want these
library functions to use the "generic" or default ABI such that it is
specified when linked into the user application. Currently this will
default to v4 as the startup code will use whatever the current default
is.
2023-09-08 13:17:00 -05:00
Joseph Huber
ead92ae5fe [libc] Prevent system headers from being included for the GPU build
It's very important that the GPU build does not include any system
directories. We currently use `-ffreestanding` to disable a lot of these
features, but we can still accidentally include them if they are not
provided by `libc` yet. This patch changes this to use `-nostdinc` to
disable all standard search paths. Then we use the compiler's resource
directory to pick up the provided headers like `stdint.h`.

Differential Revision: https://reviews.llvm.org/D159445
2023-09-05 08:43:07 -05:00
Joseph Huber
65642c7308 [libc][NFC] Support sm_89 and sm_90 NVIDIA GPUs
Summary:
These architectures were left out from the list and should be supported.
2023-09-02 16:23:41 -05:00
Petr Hosek
15b5ac38cf [libc] Add missing ${LIBC_INCLUDE_DIR} to object rule
This is breaking the runtimes build with llvm libc enabled.

Differential Revision: https://reviews.llvm.org/D158894
2023-08-29 05:22:14 +00:00
Tue Ly
5e3ec418ff [libc] Only add -ffreestanding flag in full build mode.
Only add -ffreestanding flag in full build mode.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D158652
2023-08-24 10:15:42 -04:00
Joseph Huber
b20a385422 [libc] Do not run tests on vendor implemented math
We currently remap vendor implementations of math functions to provide a
temporarily functional `libm.a` for the GPU. However, we should not run
tests on any files that depend on these vendor implementations as they
are not under our control and are not always present.

The goal in the future is to remove the need for this by replacing all
the vendor functionality, but for now this is a workaround.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D158213
2023-08-17 17:22:55 -05:00
Roland McGrath
5207451dd0 [libc] Compile with -Wconversion -Wno-sign-conversion
This more closely matches the stricter warnings used for
this same code in the Fuchsia build.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156630
2023-08-09 12:46:20 -07:00
Joseph Huber
26a1849cca [libc] Warn on use of global constructors in libc
Clang supports the `-Wglobal-constructors` flag which will indicate if a
global constructor is being used. The current goal in `libc` is to make
the constructors `constexpr` to prevent this from happening with
straight construction. However, there are many other cases where we can
emit a constructor that this won't catch. This should give warning if
someone accidentally introduces a global constructor.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D155721
2023-07-20 11:29:58 -05:00
Joseph Huber
a4f553fcde [libc] Fix using the libcgpu.a for NVPTX in non-LTO builds
CUDA requires a PTX feature to be compiled generally, because the
`libcgpu.a` archive contains LLVM-IR we need to have one present to
compile it. Currently, the wrapper fatbinary format we use to
incorporate these into single-source offloading languages has a special
option to provide this. Since this was not present in the builds, if the
user did not specify it via `-foffload-lto` it would not compile from
CUDA or OpenMP due to the missing PTX features. Fix this by passing it
to the packager invocation.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D154864
2023-07-10 13:54:47 -05:00
Petr Hosek
36c15be20b [libc] Use LIBC_INCLUDE_DIR in CMake rules
D152592 introduced LIBC_INCLUDE_DIR for the location of the include
directory, use it in relevant CMake rules.

Differential Revision: https://reviews.llvm.org/D154278
2023-07-10 07:32:24 +00:00
Petr Hosek
bf171aaa7a Revert "[libc] Use LIBC_INCLUDE_DIR in CMake rules"
This reverts commit 6e821f0b3a since
it broke the libc-aarch64-ubuntu-fullbuild-dbg bot.
2023-07-07 20:52:54 +00:00
Petr Hosek
6e821f0b3a [libc] Use LIBC_INCLUDE_DIR in CMake rules
D152592 introduced LIBC_INCLUDE_DIR for the location of the include
directory, use it in relevant CMake rules.

Differential Revision: https://reviews.llvm.org/D154278
2023-07-07 20:42:25 +00:00
Petr Hosek
e1cb5924cb Revert "[libc] Use LIBC_INCLUDE_DIR in CMake rules"
This reverts commit 046deabd93 since
it broke libc-aarch64-ubuntu-fullbuild-dbg.
2023-07-05 17:20:11 +00:00
Petr Hosek
046deabd93 [libc] Use LIBC_INCLUDE_DIR in CMake rules
D152592 introduced LIBC_INCLUDE_DIR for the location of the include
directory, use it in relevant CMake rules.

Differential Revision: https://reviews.llvm.org/D154278
2023-07-05 17:16:19 +00:00
Tue Ly
f9753ef189 [libc][Obvious] Fix a typo in setting FMA control option for RISCV64. 2023-06-02 11:15:29 -04:00
Joseph Huber
e7735a57b9 [libc] Correctly pass 'CXX_STANDARD' to the packaged GPU build
We need to perform the GPU build separately. The `CXX_STANDARD` option
was not being passed properly.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149225
2023-04-26 16:52:31 -05:00
Joseph Huber
1c968f7a1f [libc] Ignore unknown CUDA versions for libc targeting NVPTX
Summary:
We generally need a CUDA toolchain to build the tests for the GPU `libc`
targeting NVPTX. However, clang will commonly emit warnings on versions
that are too new. We can ignore these in `libc` since we are manually
specifying the `+ptx` version to use whenever we compile. So we do not
need to worry about unexpected changes and we do not depend on any newer
features. So this should not be problematic.
2023-04-21 13:27:45 -05:00
Joseph Huber
a73cd00d87 [libc] Bump up sm_60's CUDA feature to +ptx63
Summary:
The sm_60 GPU is the oldest model that's supported for using the RPC
features of the `libc` GPU runtime. This also requires at least `+ptx63`
to enable use of the active mask. So, this patch sets that as the
minimum.
2023-04-21 13:27:45 -05:00
Joseph Huber
8704c3a31f [libc] Set minimum CUDA PTX feature to +ptx60
Summary:
The `+ptx` features correspond to the related CUDA version. We require a
certain set of features from the `ptxas` assembler, which is tied to the
CUDA version. Some of the ones set here were insufficient, so I am
simply setting a cutoff to the CUDA 9.0 release as the minimum. This
roughly corresponds to what should be required for sm_60 to be compiled
with the source.
2023-04-20 18:01:01 -05:00
Joseph Huber
24214832fd [libc] Fix nvptx_options variable not being reset in CMake
Summary:
This variable was not being reset, which caused the options to be
compounded when building multiple architectures. This was very
problematic as the architectures are not compatible.
2023-04-19 15:28:26 -05:00
Joseph Huber
e2356fb07e [libc] Add special handling for CUDA PTX features
The NVIDIA compilation path requires some special options. This is
mostly because compilation is dependent on having a valid CUDA
toolchain. We don't actually need the CUDA toolchain to create the
exported `libcgpu.a` library because it's pure LLVM-IR. However, for
some language features we need the PTX version to be set. This is
normally set by checking the CUDA version, but without one installed it
will fail to build. We instead choose a minimum set of features on the
desired target, inferred from
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#release-notes
and the PTX refernece for functions like `nanosleep`.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D148532
2023-04-17 11:51:34 -05:00
Tue Ly
6edad0c8f0 [libc][RISCV] Let RISCV64 targets test implementations with and without FMA.
Let RISCV64 targets math implementations with and without FMA
automatically.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D146730
2023-04-06 09:23:48 -04:00
Joseph Huber
9f5c6dcf59 [libc] Search for the CUDA patch explicitly when testing
The packaged version of the `libc` library does not depend on the CUDA
installation because it only uses `clang` and emits LLVM-IR. However,
for testing we directly need the CUDA toolkit to emit and execute the
files. This patch explicitly passes `--cuda-path` to the relevant
compilations for NVPTX testing.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D147653
2023-04-05 15:14:47 -05:00
Joseph Huber
2dc60b4ea4 [libc] Use LTO for AMDGPU compilation and linking
Summary:
The AMDGPU ABI isn't stable or well defined. For that reson we prefer to
rely on LTO to ensure that multiple files get linked correctly.
Currently the internal targets used for testing mix LLVM-IR and
assembly. We should be consistent here.
2023-03-29 14:20:44 -05:00
Joseph Huber
dab75a4378 [libc] Remove leftover debug prints 2023-03-14 15:14:12 -05:00
Joseph Huber
ab107b3fac [libc] Fix CMake deduplication -Xclang arguments
Summary:
We use `-Xclang` to pass the GPU binary to be embedded. In the case of
multi-source objects this will be passed more than once, but CMake
implicitly deduplicates arguments. Use the special generator to prevent
this from happening.
2023-03-14 15:04:37 -05:00
Joseph Huber
597cef4486 [libc] Fix GPU fatbinary dependencies for multi-source object libraries
Summary:
Multi-source object libraries require some additional handling, this
logic wasn't correctly settending the dependency on each filename
individually and was instead using the last one. This meant that only
the last file was built for multi-object libraries.
2023-03-14 15:04:37 -05:00
Joseph Huber
c2a17bff24 [libc] Set the stub filename to the target name instead of the source
The GPU target requires some weird special case handling to create fat
binaries. CMake offers no way to set the name of an object library. The
only way to do this is to create a file with the desired name and use
that. Currently we name it after the source filename. However, this
breaks if there is more than a single source. This patch changes the
logic to instead look up the object target name and use that. E.g.
`src.__support.OSUtil.osutil` will be `osutil.cpp`.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145912
2023-03-14 10:31:04 -05:00
Joseph Huber
a031f72187 [libc] Correctly pass the compile options to the internal GPU compilation
Summary:
We use an internal option to create the GPU binary used for testing.
This wasn't getting the proper flags passed to it due to a missing
variable name.
2023-03-14 08:19:13 -05:00
Joseph Huber
8a712bf7c4 [libc] Fix common compile options not getting passed to GPU object
Summary:
This variable was named incorrectly. We weren't getting needed flags
passed to object library builds.
2023-03-10 16:54:20 -06:00
Siva Chandra Reddy
772e37f893 [libc] Add ALIAS option to add_object_library rule.
This ALIAS option is now used with threads/callonce target.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145409
2023-03-06 22:11:33 +00:00
Siva Chandra Reddy
bfeef8b794 [libc] Add a linting target named "libc-lint".
Lint targets for individual entrypoints have also been cleaned up. The
target "libc-lint" depends on the individual lint targets.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D144705
2023-02-24 19:55:43 +00:00
Joseph Huber
98697f4764 [libc] Fix LIBC_GPU_ARCHITECTURES not being used
Summary:
This variable is supposed to control the architectures to build for. At
some point this was changes out for testing and never fixed.
2023-02-21 13:00:16 -06:00
Joseph Huber
eb71ecfa10 [libc] Fix GPU include directories not being set properly
Summary:
For some reason, this variable was set after where it was used. Causing
weird behaviour with including the standard headers. Fix it.
2023-02-20 15:43:16 -06:00
Joseph Huber
4a872412d8 [libc] Fix dependencies for generating the GPU binary file
This patch adjusts the way dependencies are handled in the packaed
version of the GPU libc runtime. Previously the files were not getting
updated properly in the install when they changed.

Depends on D144214

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D144280
2023-02-20 09:37:19 -06:00
Joseph Huber
d51d2b5909 [libc] Support add_object_library for the GPU build
This patch unifies the handling of generating the GPU build targets
between the `add_entrypoint_library` and the `add_object_library`
functions. The `_build_gpu_objects` function will create two targets.
One contains a single object file with several GPU binaries embedded in
it, a so-called fatbinary. The other is a direct compile of the
supported target to be used internally only. This patch pulls out some
of the properties logic so that we can handle both more easily. This
patch also required adding an ovverride  `NO_GPU_BUILD` for cases when
we only want to build the source file as normal.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144214
2023-02-20 09:37:18 -06:00