This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add support for the 'fread' function on the GPU
ClosedPublic

Authored by jhuber6 on Jul 12 2023, 2:35 PM.

Details

Summary

This patch adds support for fread on the GPU via the RPC mechanism.
Here we simply pass the size of the read to the server and then copy it
back to the client via the RPC channel. This should allow us to do the
basic operations on files now. This will obviously be slow for large
sizes due ot the number of RPC calls involved, this could be optimized
further by having a special RPC call that can initiate a memcpy between
the two pointers.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 12 2023, 2:35 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 12 2023, 2:35 PM
jhuber6 requested review of this revision.Jul 12 2023, 2:35 PM
sivachandra added inline comments.Jul 14 2023, 11:02 AM
libc/test/src/stdio/fopen_test.cpp
23

UPPER_CASE.

33

Typo - new_file? Wonder how this is working at all because file is closed on line 27.

jdoerfert added inline comments.Jul 26 2023, 8:39 AM
libc/utils/gpu/server/rpc_server.cpp
115

To allow for partial fread. Technically, you should put in exactly what the user put in on the other side. It makes a difference after all.

117

What is this about, I don't get it.

120

I don't get this. We should always return rets[id], no?

jhuber6 added inline comments.Jul 26 2023, 8:46 AM
libc/utils/gpu/server/rpc_server.cpp
117

This is what streams the data read from the CPU buffer to the GPU.

120

I think this is a consequence of me not using the size argument instead of the nmemb argument. Since the return value is supposed to correspond to the size. I can fix it and test.

jhuber6 updated this revision to Diff 544391.Jul 26 2023, 9:01 AM

Fix test again

This is what confused me earlier:
If I read the fread definition properly, libc's implementation is wrong. The read is supposed to be quantized, but in libc it is not (or it is quantized with an element size of 1).

libc/utils/gpu/server/rpc_server.cpp
120

I mean, whatever host fread returns is what we should return. That said, we really need to pass size and nmemb from the device to the host.

This is what confused me earlier:
If I read the fread definition properly, libc's implementation is wrong. The read is supposed to be quantized, but in libc it is not (or it is quantized with an element size of 1).

Turns out, all libc impl. do this... anyway. With 1 as size on the host side this should do what the host would do, so we should be fine.

jdoerfert accepted this revision.Jul 26 2023, 10:15 AM
This revision is now accepted and ready to land.Jul 26 2023, 10:15 AM
This revision was automatically updated to reflect the committed changes.