summaryrefslogtreecommitdiff
path: root/libc
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert "[libc] Improve the add_libc_test rule."Siva Chandra Reddy2023-05-041-8/+0
| | | | | This reverts commit fb6faf4798b1cb327e719898e2ea6eff7f597c49 as the aarch64 builders are failing.
* [libc] Improve the add_libc_test rule.Siva Chandra Reddy2023-05-041-0/+8
| | | | | | | | | | A target for the test named ${fq_target_name} has been added. It depends on ${fq_target_name}.__unit__ and ${fq_target_name}.__hermetic__ as relevant. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149730
* [libc] Maintain proper alignment for the hermetic tests mallocJoseph Huber2023-05-042-12/+13
| | | | | | | | | | | | We use a bump pointer to implement malloc for the hermetic tests. Currently, we bump the pointer up by any amount. This means that calling `malloc(1)` will misalign the buffer so any following `malloc(8)` accesses will not be aligned. This causes problems in architectures which require alignment. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149863
* [libc][rpc] Pass lane_mask into lock functionsJon Chesterfield2023-05-041-11/+17
| | | | | | | | | | Will be necessary for correct locking on volta. API-only change to help with rebasing the rest of the stack on this. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149871
* [libc][Docs] Add warning about running GPU tests with parallelismJoseph Huber2023-05-041-0/+5
| | | | | | | | | Now that a large amount of GPU tests can be run in parallel, we should document spurious failures. It is a well-known issue that launching many GPU applications in parallel can lead to various problems, the worst of which being an indefinite hang. Differential Revision: https://reviews.llvm.org/D149857
* [libc] Enable running libc unit tests on NVPTXJoseph Huber2023-05-048-41/+69
| | | | | | | | | | | | | | | The previous patches added the necessary support for global constructors used to register tests. This patch enables the NVPTX target to build and run the unit tests on the GPU. Currently this only tests the ctype tests, but adding more should be straightforward from here on. This ran all the ctest unit tests when run on an sm_70. Depends on D149517 D149527 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149532
* [libc][rpc] Factor try_lock, unlock into functions on ProcessJon Chesterfield2023-05-041-8/+19
| | | | | | | | Reduces line noise and localises changes needed for volta Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149845
* [libc] Support global constructors and destructors on NVPTXJoseph Huber2023-05-049-23/+222
| | | | | | | | | | | | | | | | | | | | | | This patch adds the necessary hacks to support global constructors and destructors. This is an incredibly hacky process caused by the primary fact that Nvidia does not provide any binary tools and very little linker support. We first had to emit references to these functions and their priority in D149451. Then we dig them out of the module once it's loaded to manually create the list that the linker should have made for us. This patch also contains a few Nvidia specific hacks, but it passes the test, albeit with a stack size warning from `ptxas` for the callback. But this should be fine given the resource usage of a common test. This also adds a dependency on LLVM to the NVPTX loader, which hopefully doesn't cause problems with our CUDA buildbot. Depends on D149451 Reviewed By: tra Differential Revision: https://reviews.llvm.org/D149527
* [libc][rpc] Fold can send/recv into buffer_unavailableJon Chesterfield2023-05-041-13/+9
| | | | | | | | Left out of D149788 to simplify the diff Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149807
* [libc] Enable running libc unit tests on AMDGPUJoseph Huber2023-05-0412-45/+52
| | | | | | | | | | | The previous patches added the necessary support for global constructors used to register tests. This patch enables the AMDGPU target to build and run the unit tests on the GPU. Currently this only tests the `ctype` tests, but adding more should be straightforward from here on. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149517
* [libc][rpc] Treat pointers as arrays consistentlyJon Chesterfield2023-05-041-7/+7
| | | | | | | | Noticed in passing. Either way compiles. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149808
* [libc] Use proper flags for compiler version detectionGuillaume Chatelet2023-05-041-1/+1
| | | | | | | The `-v` flag means verbose and not version. With `clang` this flag prints the version and exits successfully. Under `GCC` this is not a valid command line so the binary exits with an error.
* [libc][rpc] Simplify mailbox state trackingJon Chesterfield2023-05-044-51/+70
| | | | | | | | | | | | | | | | | | | Removes the redundant Ack/Data bit manipulation. Represents the inbox/outbox state with one bit instead of two. This will be useful if we change to a packed representation and otherwise cuts the runtime state space from 16 to 4. Further simplification is possible, this patch is intentionally minimal. - can_{send,recv}_data are now in == out - {client,server}::try_open can be factored into Process:try_open This implements the state machine of D148191, modulo differences in atomic ordering and fences. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149788
* [libc][rpc] Fix the memory ordering in lock.Jon Chesterfield2023-05-031-0/+6
| | | | | | | | | | | | | | | | | | Prevent operation reordering with fence instead of a comment. The mailboxes are in shared memory and the locks structure in device memory. If the mailboxes are read and then the lock taken, the lock says nothing about the current or future state of those mail boxes. The relaxed atomic fetch_or can be reordered before the relaxed atomic loads of unrelated variables unless there is a fence preventing this. Patches both Client::try_open and Server::try_open, one of which is missing an optimisation and the other is missing the comment, but which otherwise could be Process::try_open followed by buffer->opcode = opcode in Client. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149790
* [libc] Make printf decimal long doubles use hexMichael Jones2023-05-032-3/+20
| | | | | | | | | | | Decimal long doubles are not commonly used, and aren't currently supported by the algorithm used for decimal float conversions. To avoid giving incorrect answers, this patch adds a temporary exception to print long doubles in hexadecimal even when decimal is requested. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D148179
* [libc] add socket functionMichael Jones2023-05-0318-14/+213
| | | | | | | | | | This patch adds the function "socket" from the header "sys/socket". It's a simple syscall wrapper, and I plan on adding the related functions in a followup patch. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149622
* [libc] Revert rounding mode changes for hermetic testsJoseph Huber2023-05-031-4/+4
| | | | | | | | | We got rid of the rounding mode here so that the hermetic tests wouldn't depend on the system fenv.h. But this seemed to cause some bots to break. Getting rid of this change for now, it should be fine for the CPU builds. Differential Revision: https://reviews.llvm.org/D149767
* [libc] Don't use '-nolibc' on the GPU buildJoseph Huber2023-05-031-1/+5
| | | | | | | | | | | We previously changed this to use `nolibc` to allow it to link in compiler builtins for the CPU build. However, these options are unused on the GPU and create a lot of noise. Furthermore, we want to use `nogpulib` to prevent the linking in of the vendor libraries. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149753
* [libc] Enable the '__support' unit tests to be hermeticJoseph Huber2023-05-037-52/+56
| | | | | | | | | | | | | This patch updates the `__support` unit tests to be built as hermetic tests. The only tests we needed to disable were because of the use of `realloc` which is not implemented correctly as it doesn't copy the memory. Depends on D149745 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149750
* [libc] Split out FPExceptMatcher from the FP utilsJoseph Huber2023-05-032-3/+17
| | | | | | | | | | | | The FPEceptMatcher.cpp file uses system utilities and includes C++ libraries. This patch pulls it out of the main `FPTestHelpers` target so we can exclude it from hermetic only tests. Depends on D149705 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149745
* [libc] Enable the 'stdlib' unit tests to be hermeticJoseph Huber2023-05-033-50/+66
| | | | | | | | | | | This changes the `stdlib` tests to the new `add_libc_test` framework. This applies to all but the exit tests. Depends on D149691 Reviewed By: sivachandra, michaelrj Differential Revision: https://reviews.llvm.org/D149705
* [libc] Use -nolibc -nostdlib++ -nostartfiles for hermetic test link.Siva Chandra Reddy2023-05-031-1/+1
| | | | | | | | | We previously used a more stricter -nostdlib option which was also removing compiler-rt/libgcc. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149683
* [libc] Add 'UNIT_TEST_ONLY' and 'HERMETIC_TEST_ONLY' to 'add_libc_test'Joseph Huber2023-05-022-6/+14
| | | | | | | | | | | | | | | | The `add_libc_test` option allows us to enable both kinds of tests in a single option. However, some tests cannot be made hermetic with the current approach. Such as tests that rely on system utilities or libraries. This patch adds two options `UNIT_TEST_ONLY` and `HERMETIC_TEST_ONLY` to offer more fine-grained control over which version gets built. This makes it explicit which version a test supports and why. Depends on D149662 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149691
* [libc] Enable the 'string' unit tests to be hermeticJoseph Huber2023-05-023-85/+86
| | | | | | | | | | | | This changes over the string unit tests to the new `add_libc_test` framework. The one test that wasn't changes was the memory utils because it overran the static buffer used for the hermetic test's bump pointer. Depends on D149656 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149662
* [libc] Remove use of 'assert' from the string testsJoseph Huber2023-05-023-16/+0
| | | | | | | | | | | | Currently we use `assert` as a stand-in for the typical test assertions. This is because these functions exist outside of the base test class so we can't use the typical assertion methods. The presence of these asserts makes it difficult to compile these tests in a standalone format. This patch removes all occurrences. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149656
* [libc] Fix some missing features from the hermetic test supportJoseph Huber2023-05-022-14/+15
| | | | | | | | | | | This patch addresses some of the flags and features that are currently missing from the hermetic test support. This mostly just fixes the `add_libc_test` option failing to find a few dependencies or missing arguments from the previous unit test support. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D149629
* [libc] Add support for global ctors / dtors for AMDGPUJoseph Huber2023-04-294-8/+135
| | | | | | | | | | | | | | | | This patch makes the necessary changes to support calling global constructors and destructors on the GPU. The patch in D149340 allows the `lld` linker to create the symbols pointing us to these globals. These should be executed by a single thread, which is more difficult on the GPU because all threads are active. I chose to use an atomic counter to sync every thread on the GPU. This is very slow if you use more than a few thousand threads, but for testing purposes it should be sufficient. Depends on D149340 D149363 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149398
* [libc] Fix printing on the GPU when given a `cpp::string_ref`Joseph Huber2023-04-282-5/+10
| | | | | | | | | | | | The implementation of the test printing currently expects a null terminated C-string. However, the `write_to_stderr` interface uses a string view, which doesn't need to be null terminated. This patch changes the printing interface to directly use `fwrite` instead rather than relying on a null terminator. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149493
* [libc][NFC] Start cleanup of time functionsMichael Jones2023-04-2815-38/+37
| | | | | | | | | | | The time functions have not yet been updated to match our new coding patterns. This patch removes some unnecessary includes, adjusts the names of the test targets, and adds several TODO comments. It is my intention to follow this patch up with additional cleanup. Reviewed By: sivachandra, rtenneti Differential Revision: https://reviews.llvm.org/D149487
* [libc] add exception to atof differential fuzzMichael Jones2023-04-282-1/+40
| | | | | | | | | | | The differential fuzzer for atof found a bug in glibc's handling of hexadecimal rounding. Since we can't easily update glibc and we want to avoid false positives when running the fuzzer, I've added an exception to skip all hexadecimal subnormal cases. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149359
* [libc] Implement `exit` for the GPU partiallyJoseph Huber2023-04-275-24/+18
| | | | | | | | | | | | This patch implements the `exit` function on the GPU. This required breaking the entrypoints calling eachother on `linux` since this doesn't work with a non-aliased target. This is only partial support because full support requires a malloc / free implementation for the exit callbacks array. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149363
* [libc] Support the `abs` functions in the GPU libc.Joseph Huber2023-04-272-1/+6
| | | | | | | | | This patch simply enables building the integer `abs` functions for the GPU. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149317
* [libc] Support the string conversion methods on the GPUJoseph Huber2023-04-276-2/+33
| | | | | | | | | | | | | | | This patch enables us to use the existing `libc` support for string conversion functions on the GPU. This required setting the `fenv_t` and long double configuration. As far as I am aware, long doubles are converted to doubles on the GPU and the floating point environment is just an `uint32_t`. This code is still untested as we are still working out how to run the unit tests on the GPU. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D149306
* [libc] Add more missing GPU utilitiesJoseph Huber2023-04-273-5/+31
| | | | | | | Summary: This patch adds a way to get the total number of blocks and implement the wave sync intrinsic for AMDGPU. This is a no-op, but that may change in the future so we might as well implement it right.
* [libc] Add a new target named LibcHermeticTestMain.Siva Chandra Reddy2023-04-262-23/+25
| | | | | | | | | | The existing LibcTestMain has been renamed to LibcUnitTestMain. Hermetic tests are linked to LibcHermeticTestMain and unit tests are linked to LibcUnitTestMain. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149303
* [libc][fix] Also remove the headers for the other flagsJoseph Huber2023-04-261-2/+2
| | | | | | | Summary: This patch makes this only apply to the GPU build. This should be handled more intelligently in the future so it's common between all of t hem.
* [libc][fix] Only add the hermetic test flags in GPU modeJoseph Huber2023-04-261-1/+1
| | | | | | | Summary: This is a little broken, what we really need is a separate target to use with the hermetic tests, but this is a stop-gap to get the bots green again.
* [libc] Partially implement `atexit` on the GPUJoseph Huber2023-04-265-1/+50
| | | | | | | | | | | | | | | The `atexit` function controls registering functions to call at the end of the program. This is difficult to do in general on the GPU because of the lack of a real mutex implementation. We primarily provide this for testing where we can explicitly restrict how the `atexit` registration functions are called. So we simply create a passthrough Mutex to get past the usage of it as per @sivachandra's suggestion. Depends on D149225 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149226
* [libc] Correctly pass 'CXX_STANDARD' to the packaged GPU buildJoseph Huber2023-04-261-0/+10
| | | | | | | | | 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
* [libc] Enable the GPU build to build the UnitTest libraryJoseph Huber2023-04-262-3/+6
| | | | | | | | | | | | | | | The previous patch in D149216 allows us to use the internal `<stdlib.h>` include for the GPU build. However, we currently don't provide the memory functions so the header wasn't resolving them. This patch adds these as entrypoints. They don't cause any entrypoints to be emitted because they are not implemented, but they provide it in the header so that we can rely on the test's implementation of them. Depends on D149216 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149217
* [libc] Add path to include generated headers for hermetic testsJoseph Huber2023-04-261-0/+8
| | | | | | | | | | The generated header files live in the build directory's include path. When targeting a hermetic build we want to make sure we only use headers generated by the project itself if availible. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149216
* [libc][bazel] add file printf targets and supportMichael Jones2023-04-269-6/+121
| | | | | | | | | | | This patch adds targets for printf and fprintf to the bazel build. Additionally, it adds support for the build system to specify where files should be written for testing purposes. This was necessary to enable the fprintf test under bazel. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D147008
* [libc][Docs] Begin improving documentation for the GPU libcJoseph Huber2023-04-267-170/+243
| | | | | | | | | | This patch updates some of the documentation for the GPU libc project. There is a lot of work still to be done, but this sets the general outline. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D149194
* [libc] Fix sched_get_priority_max() syscall invocationTal Zussman2023-04-252-3/+3
| | | | | | | | | | Previously used SYS_sched_get_priority_min. This also updates the tests for SCHED_RR and SCHED_FIFO to check max_priority > min_priority, rather than >= in order to catch future breakages. Reviewed By: michaelrj, goldstein.w.n Differential Revision: https://reviews.llvm.org/D149102
* [libc] Fix including 'libc_errno.h' incorrectlyJoseph Huber2023-04-251-1/+6
| | | | | | Summary: This causes problems when included. Fix this to hopefully get the bots working again.
* [libc][fix] Add missing 'errno' header for the GPU libcJoseph Huber2023-04-253-0/+5
| | | | | | | | Summary: The previous GPU `libc` patch added support for `atoi`. However, it didn't also enable generating the errno header. This caused including it to use the system's header which invariably will cause compiler problems.
* [libc] Ignore 'errno' on the GPU and support 'atoi'Joseph Huber2023-04-255-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'errno' value is most likely not useful on the GPU and it prevents us from providing certain functions on the GPU that depend on it, like `atoi`. This patch makes the necessary changes to support `errno` by simple replacing it with a consumer class. Supporting `errno` on the GPU is possible in some aspects. The first approach would be to use a buffer of shared memory that has enough space for all threads. Another option would be to change code generation to support `thread_local` using `address_space(5)` memory allocated at kernel launch. The former could look like the following, which could be implemented in a later patch: ``` template <typename T> using SharedBuffer = T[gpu::MAX_THREADS] [[clang::address_space(3)]]; template <typename T> struct ErrnoSetter { constexpr ErrnoSetter(SharedBuffer<T> &storage) : storage(storage) {} SharedBuffer<T> &storage; void operator=(const T &val) { storage[gpu::get_thread_id()] = val; } }; static SharedBuffer<int> thread_local_buffer [[clang::loader_uninitialized]]; ErrnoSetter<int> __llvmlibc_internal_errno(thread_local_buffer); ``` Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149107
* [libc] Fix typos in documentationKazu Hirata2023-04-247-13/+13
|
* [libc][Obvious] Add NO_RUN_POSTBUILD to sqrtf exhaustive test.Siva Chandra Reddy2023-04-241-0/+1
| | | | | | The bots are timing out because they are trying to run this test. Differential Revision: https://reviews.llvm.org/D149108
* [libc][Obvious] Enable hermetic tests only under full build.Siva Chandra Reddy2023-04-241-1/+1
| | | | | | Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D149105