157 Commits

Author SHA1 Message Date
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
d2e0a98391 [libc][NFC] Compile tests also with -fpie.
The libc runtime code is already compiled with -fpie.
2023-03-09 07:45:39 +00:00
Mikhail R. Gadelha
0ffea21893 [libc] Small improvements to libc cmake
This patch includes:
1. Better error message when cmake finds incompatible triple
2. Added missing header dependencies libc/include/CMakeLists.txt as per
   app.td
3. Removed unused $LLVM_LIBC_INCLUDE_DIRS cmake variable

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145496
2023-03-08 09:02:02 -03:00
Siva Chandra
f7e91f2b82 [libc] Add riscv64 config.
Memory functions get the basic implementation. They can be tuned
as a follow up.

Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D145433
2023-03-06 23:03:43 +00: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
a048df8707 [libc][Obvious] Add back CMake logic which was mistakenly deleted earlier. 2023-03-06 00:26:07 -08:00
Siva Chandra Reddy
a7d869aabb [libc] Simplify integration tests by eliminating the artificial sysroot.
The test binaries are built like any other executable but with two
additional linker options -static and -nostdlib.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D145298
2023-03-06 07:37:48 +00:00
Siva Chandra Reddy
4052bc8674 [libc] Make errno an entrypoint.
The entrypoint has been added to the various entrypoint lists. The libc
code style doc has been updated with information on how errno should be
set from the libc runtime code.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145179
2023-03-03 06:59:19 +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
Siva Chandra Reddy
17a2434bd6 [libc] Introduce a target named libc-unit-tests to run just the unit tests.
The target "check-libc" now runs all enabled tests which, depending on
the build mode, includes the unit tests, the integration tests and the api
test.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D144663
2023-02-24 02:53:36 +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
Guillaume Chatelet
c3228714cc [libc][NFC] Make tuning macros start with LIBC_COPT_
Rename preprocessor definitions that control tuning of llvm libc.

Differential Revision: https://reviews.llvm.org/D143913
2023-02-15 10:00:16 +00:00
Joseph Huber
5fde2d9951 [libc] Write stub files to a new directory to avoid conflicts
Summary:
This hack with stub files is used to make the final object archive
have human-understandable names. We currently output these into the
current binary directory, which sometimes interferes with the actual
source file. Put these in their own directory to be certain they don't
conflict.
2023-02-13 16:39:59 -06:00
Tue Ly
e9e43e31d3 [libc] Fix the regex detecting architecture triplet for macOS.
Summary: See https://github.com/llvm/llvm-project/issues/60666

Reviewers:

Subscribers:
2023-02-11 01:13:43 -05:00
Siva Chandra Reddy
d9283e79d8 [libc] Run libc tests unconditionally, even if there are no source changes.
Before this change, the test binaries were executed only if the deps
changed. This change makes the test binaries run unconditionally. This
is more in line with the rest of LLVM. Future patches will print test
statistics etc., much like the rest of LLVM.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D143627
2023-02-10 08:47:20 +00:00
Guillaume Chatelet
a6db871e85 [libc][NFC] Move cpu_features.h to properties subfolder 2023-02-09 09:30:24 +00:00
Joseph Huber
22a5593b03 [libc] Don't try to use MPFR with the GPU build for now
Summary:
We don't have the infastructure to support MPFR on the GPU. We should
disable this categorically on GPU builds for now.
2023-02-08 08:51:47 -06:00
Guillaume Chatelet
a2569a76e0 [libc][NFC] Rename macros 2023-02-07 20:43:33 +00:00
Siva Chandra Reddy
af1315c28f [libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.
This part of the effort to make all test related pieces into the `test`
directory. This helps is excluding test related pieces in a straight
forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move
the MPFR wrapper and testutils into the 'test' directory.
2023-02-07 19:45:51 +00:00
Siva Chandra Reddy
9b4999cbea [libc] Cleanup the CMake infrastructure to add startup objects.
Instead of using a custom target to copy the startup object file to a
file with the desired name, a normal object library with a special
property is used.

Follow up patches will do more cleanup wrt how the startup objects are
used in integration tests.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D143464
2023-02-07 16:35:46 +00:00
Guillaume Chatelet
ced5a382a8 [libc][NFC] Move cpu_features to macros folder 2023-02-07 10:32:19 +00:00
Siva Chandra Reddy
c7880f52e4 [libc] Fix typo is processing LIBC_GPU_TEST_ARCHITECTURE.
Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D143444
2023-02-07 00:21:12 +00:00
Joseph Huber
f8563a2545 [libc] Add LIBC_GPU_TEST_ARCHITECTURE option to set architecture
Currently, the plan is to support testing on a single GPU architecture.
We query the supported architectures from the user's system. However,
there are times when the user would want to override this. This patch
adds the `LIBC_GPU_TEST_ARCHITECTURE` option, which allows users to
specify which GPU architecture to build for.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D143400
2023-02-06 11:02:07 -06:00
Joseph Huber
a0cb7bab42 [libc][NFC] Print the GPU architectures to build and fix the CMake list
Summary:
This list previously had empty members. Fix it and print out which
architectures we're building for as a status message.
2023-02-03 16:21:58 -06:00
Tue Ly
c1e252417e [libc] Add -mavx2 together with -mfma to allow clang pre-12 to generate fma
instructions.

For clang-11, having -mfma without -mavx2 does not generate fma
instructions, causing a build bot to fail on log10_test.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143234
2023-02-03 15:12:09 -05:00
Joseph Huber
6d0e137358 [libc] Remove OpenMP and build the GPU libc directly
The current `libcgpu.a` is actually an archive of fatbinaries. The host
file contains nothing but a section called `LLVM_OFFLOADING` that
contains embedded device code. This used to be handled implicitly by
borrowing the OpenMP toolchain, which did this packaging internally.
Passing the OpenMP flags causes problems with trying to move to testing.
This patch pulls this logic out into the CMake and handles it manually.

This patch is a lot of noise, but it fundamentally comes down to the
following changes.
1. Build the source for every GPU architecture (GPU architectures are
   generally not backwards compatible)
2. Combine all of these files into a single binary blob
3. Embed that binary blob into a host file
4. Package these host files into a `.a` archive.
5. The device code will be extracted and managed by the offloading
   linker.

Another important point. Right now we are maintaining an important
distinction with the GPU build. That is, when we build the exported
library we will build for many GPU architectures. However, the internal
version will only be built for a single GPU architecture, one that was
found on the user's system. This is intended to be used for internal
testing, very similar to the current path where `libc` is compiled for a
single target triple.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143089
2023-02-02 09:47:03 -06:00
Siva Chandra Reddy
23872aae12 [libc] Add an off-by-default option to silence "skipping" messages from CMake.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D142802
2023-01-30 16:39:41 +00:00
Siva Chandra Reddy
12b65a66fc [libc] Use a more general way to determine the compiler's target triple.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D142788
2023-01-30 16:34:21 +00:00
Joseph Huber
feedb4ad7d [libc] Add code for detecting NVIDIA GPUs as well
Recently the `nvptx-arch` tool was added to address the lack of a
similar tool for detecting locally installed NVIDIA GPUs. This patch
adds similar functionality for the already existing `amdgpu-arch` tool
in libc. These will be used to run tests on the user's system in the
future. On a system with both GPUs installed we will just go with the
first GPU detected. In the future we may want to configure the tests to
run on both of them.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D142776
2023-01-27 14:06:01 -06:00
Siva Chandra Reddy
5274a460da [libc] Use a prebuilt libc-hdrgen binary if available.
This feature will primarily by used by the runtimes build. In the
runtimes build, we build libc-hdrgen once for the host and use it
to build the libc for other targets. So, the host libc-hdrgen is
like a prebuilt passed to the target builds.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D141426
2023-01-27 19:52:55 +00:00
Tue Ly
a369bb8a3b [libc][cmake] Fix LIBC_TARGET_OS query from compiler triple for darwin.
Currently LIBC_TARGET_OS query from compiler triple returns `apple` for
macOS.  This change will fix it back to `darwin` as before.

Differential Revision: https://reviews.llvm.org/D141282
2023-01-27 10:14:48 -05:00
Guillaume Chatelet
fd64482e3d [libc][NFC] Detect host CPU features using try_compile instead of try_run.
This implements the same behavior as D141997 but makes sure that the same detection mechanism is used between CMake and source code.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D142108
2023-01-25 07:57:32 +00:00
Guillaume Chatelet
76f9a6a4e7 Revert D142108 "[reland][libc][NFC] Detect host CPU features using try_compile instead of try_run."
The build bots are failing.
This reverts commit c84d74f5bfe810744de1268eb0516a6622e4aa73.
2023-01-24 16:23:32 +00:00
Guillaume Chatelet
c84d74f5bf [reland][libc][NFC] Detect host CPU features using try_compile instead of try_run.
This implements the same behavior as D141997 but makes sure that the same detection mechanism is used between CMake and source code.

Differential Revision: https://reviews.llvm.org/D142108
2023-01-24 16:04:10 +00:00
Guillaume Chatelet
fcef706363 [libc][NFC] Reduce CMake configuration time
This patch reduces CMake configuration time drastically by removing a non-linear behavior.
Time to execute CMake configure step goes from 45s to 15s.

Differential Revision: https://reviews.llvm.org/D142374
2023-01-23 17:02:27 +00:00
Guillaume Chatelet
9c4c32a3d0 Revert D142108 "[libc][NFC] Detect host CPU features using try_compile instead of try_run."
Build bots are failing.
https://lab.llvm.org/buildbot/#/builders/90/builds/44634

This reverts commit 9acc2f37bdfce08ca0c2faec03392db10d1bb7a9.
2023-01-23 10:43:34 +00:00
Guillaume Chatelet
9acc2f37bd [libc][NFC] Detect host CPU features using try_compile instead of try_run.
This implements the same behavior as D141997 but makes sure that the same detection mechanism is used between CMake and source code.

Differential Revision: https://reviews.llvm.org/D142108
2023-01-23 09:05:53 +00:00
Siva Chandra Reddy
c68b9cc0aa [libc][NFC] Use C headers in host CPU sniffing code. 2023-01-13 07:43:32 +00:00
Siva Chandra Reddy
41c6c75333 [libc] Use the boostrap build's target triple if available.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D141428
2023-01-11 06:37:05 +00:00
Tue Ly
05727d94de [libc][Obvious] Fix typos in LLVMLibCArchitectures.cmake defining target architectures.
Fix typos in LLVMLibCArchitectures.cmake defining target architectures.

Differential Revision: https://reviews.llvm.org/D141314
2023-01-09 15:53:22 -05:00
Guillaume Chatelet
4e9ac30816 [reland][libc][NFC] Add -fno-lax-vector-conversions compilation flag
Now that a3d2c344773cc4fc95136fd67245880b34d8e335 has been submitted.
2022-12-27 10:32:41 +00:00
Guillaume Chatelet
d065472c9e Revert "[libc][NFC] Add -fno-lax-vector-conversions compilation flag"
This breaks aarch64 build.

This reverts commit 32f4c3f1033e32b7d2b7ba310c46c8c0d4013eb0.
2022-12-27 08:30:19 +00:00