[all-commits] [llvm/llvm-project] f548d1: [libc] Fix and simplify the implementation of 'fre...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Sep 21 12:28:20 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f548d19fc8256c134fc5d9edc177182e8a48e4fe
      https://github.com/llvm/llvm-project/commit/f548d19fc8256c134fc5d9edc177182e8a48e4fe
  Author: Joseph Huber <35342157+jhuber6 at users.noreply.github.com>
  Date:   2023-09-21 (Thu, 21 Sep 2023)

  Changed paths:
    M libc/include/llvm-libc-types/rpc_opcodes_t.h
    M libc/src/stdio/gpu/file.h
    M libc/utils/gpu/server/rpc_server.cpp

  Log Message:
  -----------
  [libc] Fix and simplify the implementation of 'fread' on the GPU (#66948)

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.




More information about the All-commits mailing list