This is an archive of the discontinued LLVM Phabricator instance.

[libc] Implement fopen, fclose, and fread on the GPU
ClosedPublic

Authored by jhuber6 on Aug 10 2023, 7:49 AM.

Details

Summary

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.

Diff Detail

Event Timeline

jhuber6 created this revision.Aug 10 2023, 7:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 10 2023, 7:49 AM
jhuber6 requested review of this revision.Aug 10 2023, 7:49 AM

Linux has in-memory files that would be a good fit for testing this. Memfd. Gives you a block of allocated memory that acts like a file.

Linux has in-memory files that would be a good fit for testing this. Memfd. Gives you a block of allocated memory that acts like a file.

That's neat, would save us the temporary file. But I think it's a little out of scope since the test already exists and this patch just uses it.

libc/src/stdio/gpu/fopen.cpp
25

I should probably make this max out at the buffer size in case someone does fopen("foo.txt", /*ReallyLongString=*/str).

sivachandra accepted this revision.Aug 16 2023, 7:05 AM

OK for non-GPU parts.

This revision is now accepted and ready to land.Aug 16 2023, 7:05 AM
This revision was automatically updated to reflect the committed changes.