summaryrefslogtreecommitdiff
path: root/libc/src/stdio/gpu
AgeCommit message (Collapse)Author
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-06-06[libc][GPU] clean up includes (#143203)Michael Jones
The GPU stdio functions were depending on indirect inclusion for some of their dependencies. This patch should fix all of that.
2025-06-06[libc] Fix missing includes after transitive dependency changedJoseph Huber
2024-12-02[libc][NFC] Rename RPC opcodes to better reflect their usageJoseph Huber
Summary: RPC_ is a generic prefix here, use LIBC_ to indicate that these are opcodes used to implement the C library
2024-11-19[libc] Increase RPC opcode to 32-bit and use a class byte (#116905)Joseph Huber
Summary: Currently, the RPC interface uses a basic opcode to communicate with the server. This currently is 16 bits. There's no reason for this to be 16 bits, because on the GPU a 32-bit write is the same as a 16-bit write performance wise. Additionally, I am now making all the `libc` based opcodes qualified with the 'c' type, mimiciing how Linux handles `ioctls` all coming from the same driver. This will make it easier to extend the interface when it's exported directly.
2024-11-19[libc] Replace usage of GPU helpers with ones from 'gpuintrin.h' (#116454)Joseph Huber
Summary: These are provided by a resource header now, cut these from the dependencies and only provide the ones we use for RPC.
2024-10-28[libc] Fix leftover `LIBC_NAMESPACE` after porting it (#113960)Joseph Huber
Summary: There are a few of these leftover, they should all use the `LIBC_NAMESPACE_DECL` version because that implies visibility.
2024-10-15[libc] Remove dependency on `cpp::function` in `rpc.h` (#112422)Joseph Huber
Summary: I'm going to attempt to move the `rpc.h` header to a separate folder that we can install and include outside of `libc`. Before doing this I'm going to try to trim up the file so there's not as many things I need to copy to make it work. This dependency on `cpp::functional` is a low hanging fruit. I only did it so that I could overload the argument of the work function so that passing the id was optional in the lambda, that's not a *huge* deal and it makes it more explicit I suppose.
2024-10-01[libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)lntue
https://github.com/llvm/llvm-project/issues/60481
2024-09-24[libc] Implement the 'rename' function on the GPU (#109814)Joseph Huber
Summary: Straightforward implementation like the other `stdio.h` functions.
2024-07-12[libc] Implement (v|f)printf on the GPU (#96369)Joseph Huber
Summary: This patch implements the `printf` family of functions on the GPU using the new variadic support. This patch adapts the old handling in the `rpc_fprintf` placeholder, but adds an extra RPC call to get the size of the buffer to copy. This prevents the GPU from needing to parse the string. While it's theoretically possible for the pass to know the size of the struct, it's prohibitively difficult to do while maintaining ABI compatibility with NVIDIA's varargs. Depends on https://github.com/llvm/llvm-project/pull/96015.
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-07-11Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)Michael Jones
reland of https://github.com/llvm/llvm-project/pull/98215 Additionally adds proxy headers for FILE and the fopencookie types The arm32 build has been failing due to redefinitions of the off_t type. This patch fixes this by moving off_t to a proper proxy header. To do this, it also moves stdio macros to a proxy header to hopefully avoid including this proxy header alongside this public stdio.h.
2024-07-01[libc] Implement the 'remove' function on the GPU (#97096)Joseph Huber
Summary: Straightforward RPC implementation of the `remove` function for the GPU. Copies over the string and calls `remove` on it, passing the result back. This is required for building some `libc++` functionality.
2023-10-19[libc] Rework the 'fgets' implementation on the GPU (#69635)Joseph Huber
Summary: The `fgets` function as implemented is not functional currently when called with multiple threads. This is because we rely on reapeatedly polling the character to detect EOF. This doesn't work when there are multiple threads that may with to poll the characters. this patch pulls out the logic into a standalone RPC call to handle this in a single operation such that calling it from multiple threads functions as expected. It also makes it less slow because we no longer make N RPC calls for N characters.
2023-10-17[libc] Implement the 'ungetc' function on the GPU (#69248)Joseph Huber
Summary: This function follows closely with the pattern of all the other functions. That is, making a new opcode and forwarding the call to the host. However, this also required modifying the test somewhat. It seems that not all `libc` implementations follow the same error rules as are tested here, and it is not explicit in the standard, so we simply disable these EOF checks when targeting the GPU.
2023-09-26[libc] Implement `fseek`, `fflush`, and `ftell` on the GPU (#67160)Joseph Huber
Summary: This patch adds the necessary entrypoints to handle the `fseek`, `fflush`, and `ftell` functions. These are all very straightfoward, we simply make RPC calls to the associated function on the other end. Implementing it this way allows us to more or less borrow the state of the stream from the server as we intentionally maintain no internal state on the GPU device. However, this does not implement the `errno` functinality so that must be ignored.
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-25[libc] Change the `puts` implementation on the GPU (#67189)Joseph Huber
Summary: Normally, the implementation of `puts` simply writes a second newline charcter after printing the first string. However, because the GPU does everything in batches of the SIMT group size, this will end up with very poor output where you get the strings printed and then 1-64 newline characters all in a row. Optimizations like to turn `printf` calls into `puts` so it's a good idea to make this produce the expected output. The least invasive way I could do this was to add a new opcode. It's a little bloated, but it avoids an unneccessary and slow send operation to configure this.
2023-09-21[libc] Fix and simplify the implementation of 'fread' on the GPU (#66948)Joseph Huber
Summary: Previously, the `fread` operation was wrong in cases when we read less data than was requested. That is, if we tried to read N bytes while the file was in EOF, it would still copy N bytes of garbage. This is fixed by only copying over the sizes we got from locally opening it rather than just using the provided size. Additionally, this patch simplifies the interface. The output functions have special variants for writing to stdout / stderr. This is primarily an optimization for these common cases so we can avoid sending the stream as an argument which has a high delay. Because for input, we already need to start with a `send` to tell the server how much data to read, it costs us nothing to send the file along with it so this is redundant. Re-use the file encoding scheme from the other implementations, the one that stores the stream type in the LSBs of the FILE pointer.
2023-09-20[libc][Obvious] Fix incorrect RPC opcode for `clearerr`Joseph Huber
Summary: This was mistakenly using the opcode for `ferror` which wasn't noticed because tests using this weren't yet activated. This patch fixes this mistake.
2023-09-14[libc] Implement more input functions on the GPU (#66288)Joseph Huber
Summary: This patch implements the `fgets`, `getc`, `fgetc`, and `getchar` functions on the GPU. Their implementations are straightforward enough. One thing worth noting is that the implementation of `fgets` will be extremely slow due to the high latency to read a single char. A faster solution would be to make a new RPC call to call `fgets` (due to the special rule that newline or null breaks the stream). But this is left out because performance isn't the primary concern here.
2023-09-09[libc] Implement stdio writing functions for the GPU port (#65809)Joseph Huber
Summary: This patch implements fwrite, putc, putchar, and fputc on the GPU. These are very straightforward, the main difference for the GPU implementation is that we are currently ignoring `errno`. This patch also introduces a minimal smoke test for `putc` that is an exact copy of the `puts` test except we print the string char by char. This also modifies the `fopen` test to use `fwrite` to mirror its use of `fread` so that it is tested as well.
2023-09-08[libc][NFC] Cleanup the GPU file I/O utility header (#65680)Joseph Huber
Summary: The GPU uses separate implementations to perform file IO. This is all done through the RPC interface and we kept it minimal such that we could treat a `stdin`, `stdout`, or `stderr` handle from the CPU correctly on the GPU. The RPC implementation uses different opcodes for whether or not we are using one of the standard streams. This is so we do not need to initialize anything to access the CPU's standard stream, because the server knows that it should print to `stdout` if it gets the `STDOUT` variant of the opcode. It also saves us an RPC call, which are expensive relatively speaking. This patch simply cleans up this interface to make them all use a common function. This is done in preparation to implement some more file IO functions like getc or putc.
2023-08-16[libc] Implement fopen, fclose, and fread on the GPUJoseph Huber
This patch implements the `fopen`, `fclose`, and `fread` functions on the GPU. These are pretty much re-implemented from what existed but using the new interface. Having this subset allows us to test the interface a bit more strenuously since we can write and read to a file. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D157622
2023-08-09[libc] Rework the file handling for the GPUJoseph Huber
The GPU has much tighter requirements for handling IO functions. Previously we attempted to define the GPU as one of the platform files. Using a common interface allowed us to easily define these functions without much extra work. However, it became more clear that this was a poor fit for the GPU. The file interface uses function pointers, which prevented inlining and caused bad perfromance and resource usage on the GPU. Further, using an actual `FILE` type rather than referring to it as a host stub prevented us from usin files coming from the host on the GPU device. After talking with @sivachandra, the approach now is to simply define GPU specific versions of the functions we intend to support. Also, we are ignoring `errno` for the time being as it is unlikely we will ever care about supporting it fully. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D157427