This is an archive of the discontinued LLVM Phabricator instance.

[libc] Support fopen / fclose on the GPU
ClosedPublic

Authored by jhuber6 on Jul 5 2023, 9:12 AM.

Details

Summary

This patch adds the necessary support for the fopen and fclose functions
to work on the GPU via RPC. I added a new test that enables testing this
with the minimal features we have on the GPU. I will update it once we
have fread and fwrite to actually check the outputted strings. For
now I just relied on checking manually via the outpuot temp file.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 5 2023, 9:12 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 5 2023, 9:12 AM
jhuber6 requested review of this revision.Jul 5 2023, 9:12 AM
sivachandra accepted this revision.Jul 5 2023, 3:47 PM

OK for the non-GPU parts.

This revision is now accepted and ready to land.Jul 5 2023, 3:47 PM
JonChesterfield accepted this revision.Jul 5 2023, 4:06 PM

There's a design question in here I think. Specifically whether FILE* is some handle to a host only thing or something that lives on the GPU. I can see arguments both ways, this LGTM too.

There's a design question in here I think. Specifically whether FILE* is some handle to a host only thing or something that lives on the GPU. I can see arguments both ways, this LGTM too.

So that's something I was wondering about, because as it stands the following will not work if we're doing an offloading language

int main() {
  FILE *fp = fopen("foo.txt", "w");
#pragma omp target
  { fputs("foo", fp); }
}

This is because these both represent fundamentally different structs. We could potentially make the interface just a uintptr_t to a host FILE *, but this would necessitate bypassing completely the file abstractions in libc and implementing each entrypoint separate on the GPU, versus what we do now where we more or less treat RPC as the syscall. We could potentially detect if a FILE * came from us or the host via pointer tagging in the LSB, that would allow us to wrap it in a new file if needed, but going from the GPU to the CPU then still wouldn't work. Alternatively we can just be like "Don't mix the two they're not the same libc" and call it a day.

This revision was automatically updated to reflect the committed changes.