Commit Graph

2700 Commits

Author SHA1 Message Date
Joseph Huber
0cbbcf1ef0 [libc] Update GPU documentation pages (#84076)
Summary:
After the overhaul of the GPU build the documentation pages were a
little stale. This updates them with more in-depth information on
building the GPU runtimes and using them. Specifically using them goes
through the differences between the offloading and direct compilation
modes.
2024-03-06 10:58:39 -06:00
Joseph Huber
a30233f576 [libc] Fix standalone cross compiling build for the GPU (#84042)
Summary:
This patch fixes some issues with building the GPU target manually
without the runtimes bootstrapping build. This fixes the install
directory and sets the default namespace to something more sensible if
not set. Also I got rid of the check on `-mcpu=native`. it was a neat
trick, but CMake in its INFINITE wisdom does not allow you to set link
flags on the compiler flag check. So I just went with the old tool
usage.
2024-03-05 22:03:20 -06:00
Nick Desaulniers
041638c429 [libc][stdbit] implement stdc_bit_width (C23) (#83892) 2024-03-05 09:49:41 -08:00
Nick Desaulniers
2aa22ca2ca [libc] suppress readability-identifier-naming for std::numeric_limits interfaces (#83921)
These templates are made to match the ergonomics of std::numeric_limits.
Because our style for constexpr variables is ALL_CAPS, we must silence the
linter for these manually.

Link:
https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics
2024-03-05 08:17:27 -08:00
Nick Desaulniers
640c85748e [libc] fix readability-identifier-naming in memory_utils/utils.h (#83919)
Fixes:

    libc/src/string/memory_utils/utils.h:345:13: warning: invalid case style
    for member 'offset_' [readability-identifier-naming]

Having a trailing underscore for members is a google3 style, not LLVM style.
Removing the underscore is insufficient, as we would then have 2 members with
the same identifier which is not allowed (it is a compile time error). Remove
the getter, and just access the renamed member that's now made public.
2024-03-05 08:16:50 -08:00
Nick Desaulniers
88d82b747c [libc] fix more readability-identifier-naming lints (#83914)
Found via:

    $ ninja -k2000 libc-lint 2>&1 | grep readability-identifier-naming

Auto fixed via:

    $ clang-tidy -p build/compile_commands.json \
      -checks="-*,readability-identifier-naming" \
      <filename> --fix

This doesn't fix all instances, just the obvious simple cases where it makes
sense to change the identifier names.  Subsequent PRs will fix up the
stragglers.
2024-03-05 08:15:56 -08:00
Joseph Huber
90e97e7106 [libc] Disable verbose logging messages on hermetic tests (#83954)
Summary:
The other test locations only give these messages when we are in verbose
logging mode. The average user does not care about which tests are not
being built, and most platforms will have missing tests.
2024-03-05 06:29:22 -06:00
Petr Hosek
82cc2a6701 [libc] Include stdfix.h in baremetal targets (#83900)
Fixed-point arithmetic support is targeted towards baremetal targets.
2024-03-04 15:07:42 -08:00
Nick Desaulniers
eaa0d3b133 [libc][test][stdbit] fix has_single_bit test names (#83904)
This was copy+pasted from count_ones without updating the test name completely.
2024-03-04 13:57:13 -08:00
Nick Desaulniers
93e423f19f [libc][test] update constants used in stdbit test (#83893)
Either:
- I forgot my alphabet (that E comes before F).
- My juvenile inner brain finds unsigned literal constants with the sequence FU
  funny.

¿Por qué no los dos?
2024-03-04 12:35:57 -08:00
Joseph Huber
32e2294b8a [libc][NFC] Clean up GPU utilities directory after rework (#83692)
Summary:
This CMake can be cleaned up now that the AMDGPU and NVPTX builds do not
share a CMake invocation.
2024-03-04 12:23:52 -06:00
Joseph Huber
c996023f9a [libc] Provide an implementation of the 'stdint.h' header (#83353)
Summary:
I've noticed one problem is that the user includes `stdint.h` the
compiler will do `#include_next <stdint.h>` potentially into a
conflicting implementation on systems with multiple headers installed.
The `clang` header is standards compliant and works with `clang` and
`gcc` which are both of our targets, so I simply copied it here. This
has the effect of including `stdint.h` on clang / LLVM libc behaving the
same as `-ffreestanding`.
2024-03-04 12:23:11 -06:00
Guillaume Chatelet
07f8efa22e [libc][NFC] Don't expose how float16 and float128 types are provided (#83818)
Umbrella bug #83182
2024-03-04 15:55:01 +01:00
Guillaume Chatelet
d9ae4a63ca [libc][NFC] Fix typo in dyadic_float.h (#83846) 2024-03-04 14:51:26 +01:00
Guillaume Chatelet
f7d4236adf [libc][NFC] Rename LIBC_LONG_DOUBLE_IS_ macros (#83399)
Umbrella bug #83182
2024-03-04 11:17:36 +01:00
Joseph Huber
e4b15fc854 [libc] Fix '/gpu' directory not being made for the declarations
Summary:
We use this extra directory for offloading languages like CUDA or
OpenMP. We made the '/gpu' directory for the regular headers but not the
others. Fix that for now.
2024-03-01 22:26:42 -06:00
lntue
73dfc7bbad [libc] Fix a bug in fx_bits.h due to integer promotion of bitwise ops. (#83647) 2024-03-01 21:59:41 -05:00
Joseph Huber
06ac828dc1 [libc] Fix flipped AMDGPU kernel launch arguments (#83648)
Summary:
These values were incorrectly flipped, setting the size of the blocks to
the threads and vice-versa. When I originally wrote the thread utilities
it was using COV4 which used an implicit format. Then when I updated I
accidentally flipped them and never noticed because nothing depended on
the size of the threads until I checked it manually.
2024-03-01 20:56:07 -06:00
Joseph Huber
cb807ff3d3 [libc] Fix GPU include install directory 2024-03-01 19:28:59 -06:00
Joseph Huber
00570c36a3 [libc] Fix incorrectly enabled GPU math functions (#83594)
Summary:
These functions were implemented via builtins that aren't acually
supported. See https://godbolt.org/z/Wq6q6T1za. This caused the build to
crash if they were included. Remove these and replace with correct
implementations.
2024-03-01 13:02:27 -06:00
Joseph Huber
18d0d9b9b2 [libc] Update install directory for offloading versions of libraries (#83592)
Summary:
These currently go to `lib/`, but if the user has `lib/<triple>` they
should go there because it's always searched first.
2024-03-01 10:48:32 -06:00
jameshu15869
39c24c52f6 [libc] Allow libc to build on Red Hat (#83517)
Currently, `libc` fails when building on redhat because the triple
format uses `redhat` instead of `linux` (The same problem as openSUSE).
This PR changes `libc` to accept `redhat` as a valid Linux triple.

---------

Co-authored-by: Joseph Huber <huberjn@outlook.com>
2024-02-29 21:04:02 -06:00
lntue
cf68c0427d [libc] Ignore -Winclude-next-absolute-path warning in float-macros.h (#83513) 2024-02-29 21:08:17 -05:00
Guillaume Chatelet
75fb825bcc [libc][NFC] Rename LIBC_COMPILER_HAS_FLOAT128 to LIBC_TYPES_HAS_FLOAT128 (#83395)
Umbrella bug #83182
2024-02-29 21:59:58 +01:00
Guillaume Chatelet
22f5e30c17 [libc][NFC] Rename LIBC_COMPILER_HAS_C23_FLOAT16 to LIBC_TYPES_HAS_FLOAT16 (#83396)
Umbrella bug #83182
2024-02-29 21:19:42 +01:00
lntue
73aab2f697 [libc] Revert https://github.com/llvm/llvm-project/pull/83199 since it broke Fuchsia. (#83374)
With some header fix forward for GPU builds.
2024-02-29 14:43:53 -05:00
Joseph Huber
23f3651c7c [libc] Remove workaround for fmin / fmax after being fixed in LLVM (#83421)
Summary:
These hacks can be removed now that
https://github.com/llvm/llvm-project/pull/83376 fixed the underlying
problem.
2024-02-29 06:51:01 -06:00
Guillaume Chatelet
53bd411e51 [libc][NFC] rename float.h macro file to types.h (#83190) 2024-02-29 10:28:53 +01:00
Nick Desaulniers
27352e600a [libc] fix typo introduced in inline_bcmp_byte_per_byte (#83356)
My global find+replace was overzealous and broke post submit unit tests.

Link: #83345
2024-02-28 19:13:05 -06:00
Nick Desaulniers
6f8d826b74 [libc] fix readability-identifier-naming.ConstexprFunctionCase (#83345)
Codify that we use lower_case for
readability-identifier-naming.ConstexprFunctionCase and then fix the 11
violations (rather than codify UPPER_CASE and have to fix the 170 violations).
2024-02-28 14:52:02 -08:00
Petr Hosek
68f0edfa35 [libc] Include assert.h on baremetal targets (#83324)
Many baremetal applications use asserts.
2024-02-28 13:53:51 -08:00
Nick Desaulniers
4df364bc93 [libc] remove header guard for assert.h (#83334)
It's meant to be included multiple times! Maybe use a NOLINT rule to
suppress
clang-tidy's llvm-header-guard lint warning.
2024-02-28 13:19:40 -08:00
Nick Desaulniers
330793c91d [libc] fix clang-tidy llvm-header-guard warnings (#82679)
Towards the goal of getting `ninja libc-lint` back to green, fix the numerous
instances of:

    warning: header guard does not follow preferred style [llvm-header-guard]

This is because many of our header guards start with `__LLVM` rather than
`LLVM`.

To filter just these warnings:

    $ ninja -k2000 libc-lint 2>&1 | grep llvm-header-guard

To automatically apply fixits:

    $ find libc/src libc/include libc/test -name \*.h | \
        xargs -n1 -I {} clang-tidy {} -p build/compile_commands.json \
        -checks='-*,llvm-header-guard' --fix --quiet

Some manual cleanup is still necessary as headers that were missing header
guards outright will have them inserted before the license block (we prefer
them after).
2024-02-28 12:53:56 -08:00
Michael Jones
9da9b5f867 [libc][docs] Document policy for non-standard func (#83212)
As encountered with <sys/queue.h>, we need a policy for how to handle
implementing functions that users need, but has no specific standard. In
that case, we should treat existing implementations as the standard and
try to match their behavior as best as possible.
2024-02-28 09:43:44 -08:00
Joseph Huber
04e8653f18 [libc] Add "include/" to the LLVM include directories (#83199)
Summary:
Recent changes added an include path in the float128 type that used the
internal `libc` path to find the macro. This doesn't work once it's
installed because we need to search from the root of the install dir.
This patch adds "include/" to the include path so that our inclusion
of installed headers always match the internal use.
2024-02-27 17:45:15 -06:00
Nick Desaulniers
06bcd9da16 [libc][stdbit] implement stdc_has_single_bit (C23) (#83168) 2024-02-27 13:45:37 -08:00
Joseph Huber
c6fa71cdd0 [libc][NFC] Add -Wno-multi-gpu everywhere for the GPU build (#83173)
Summary:
This warning is intended to indicate if `-march=native` returns
different values in a single compilation sense. As it stands we don't
care and it absolutely spams the test output if you run it on a machine
with more than one GPU like any cluster machine. Disable these warnings
everywhere we compile.
2024-02-27 15:14:01 -06:00
Joseph Huber
fd42044649 [libc] Re-Enable GPU tests and fix math exception handling (#83172)
Summary:
A lot of these tests failed previously and were disabled. However we
have fixed some things since then and many of these seem to pass.
Additionally, the last remaining math tests that failed seemed to be due
to the exception handling. For now we just set it to be 'errno'.

These pass locally when tested on a gfx1030, gfx90a, and sm_89
architecture. Hopefully these pass correctly on the sm_60 bot as I've
had things fail on that one only before.
2024-02-27 13:51:01 -06:00
Michael Jones
8e3b60540c [libc] Add fixed point support to printf (#82707)
This patch adds the r, R, k, and K conversion specifiers to printf, with
accompanying tests. They are guarded behind the
LIBC_COPT_PRINTF_DISABLE_FIXED_POINT flag as well as automatic fixed
point support detection.
2024-02-27 11:03:20 -08:00
Joseph Huber
770694539b [libc] Work around incorrect fmin/fmax results for +/-x (#83158)
Summary:
The IEEE 754 standard as of the 2019 revision states that for fmin -0.0
is always less than 0.0 and for fmax 0.0 is always greater than 0.0.
These are currently not respected by the builtin value and thus cause
the tests to fail. This patch works around it in the implementation for
now by explicitly modifying the sign bit.
2024-02-27 11:57:47 -06:00
Joseph Huber
d29261074c [libc] Clean up GPU math implementations (#83133)
Summary:
The math directory likes to do architecture specific implementations of
these math functions. For the GPU case it was complicated by the fact
that both NVPTX and AMDGPU had to go through the same code paths. Since
reworking the GPU target this is no longer the case and we can simply
use the same scheme. This patch moves all the old code into two separate
directories. This likely results in a net increase in code, but it's
easier to reason with.
2024-02-27 11:39:13 -06:00
lntue
aa95aa69b9 [libc][math][c23] Add C23 math functions ilogbf128, logbf128, and llogb(f|l|f128). (#82144) 2024-02-27 12:23:19 -05:00
Joseph Huber
a6b4e29c77 [libc] Re-enable several GPU math smoke tests (#83147)
Summary:
These were originally disabled after some changes caused them to
regress. It seems that whatever broke them the first time a few months
ago has been fixed elsewhere and they now work again. Re-enable all the
ones that work. There are still a few that we need to look into, but
this is a good start.
2024-02-27 10:59:45 -06:00
lntue
ded4ea9752 [libc][stdfix] Add sqrt for fixed point types. (#83042) 2024-02-26 19:36:30 -05:00
Joseph Huber
7789fb6604 [libc][NFC] Move 'sleep_briefly' function to common header (#83074)
Summary:
The https://github.com/llvm/llvm-project/pull/83026 patch has another
use for this function. Additionally add support for the Arm instruction
barrier if this is ever used by other targets.
2024-02-26 16:42:25 -06:00
Schrodinger ZHU Yifan
3aec947b67 [libc][__support/memory_size] fix missing branch and add related tests (#83016)
fix #82644.
2024-02-26 13:21:27 -05:00
Nick Desaulniers
d8406d48a8 [libc][stdbit] implement stdc_count_ones (C23) (#82444) 2024-02-26 09:25:24 -08:00
Nick Desaulniers
f70d5c0bc8 [libc][stdbit] implement stdc_count_zeros (C23) (#82437) 2024-02-26 09:23:15 -08:00
Joseph Huber
69c0b2febe [libc][NFC] Remove all trailing spaces from libc (#82831)
Summary:
There are a lot of random training spaces on various lines. This patch
just got rid of all of them with `sed 's/\ \+$//g'.
2024-02-23 16:34:00 -06:00
Joseph Huber
b43dd08aa3 [libc] Install a single LLVM-IR version of the GPU library (#82791)
Summary:
Recent patches have allowed us to treat these libraries as direct
builds. This makes it easier to simply build them to a single LLVM-IR
file. This matches the way these files are presented by the ROCm and
CUDA toolchains and makes it easier to work with.
2024-02-23 14:11:43 -06:00