[libc-commits] [PATCH] D154112: [libc] Fix the implementation of exit on the GPU

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Jun 29 10:09:49 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, jdoerfert, sivachandra, lntue, michaelrj.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
jhuber6 requested review of this revision.

The RPC calls all have delays associated with them. Currently the `exit`
function does an async send and immediately exits the GPU. This can have
the effect that the RPC server never sees the exit call and we continue.
This patch changes that to first sync with the server before continuing
to perform its exit. There is still a hazard here, where the kernel can
complete before the RPC call reads back its response, but this is simply
multi-threaded hazards. This change ensures that the server *will*
always exit some time after the GPU exits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154112

Files:
  libc/docs/gpu/support.rst
  libc/src/__support/OSUtil/gpu/quick_exit.cpp
  libc/utils/gpu/server/rpc_server.cpp


Index: libc/utils/gpu/server/rpc_server.cpp
===================================================================
--- libc/utils/gpu/server/rpc_server.cpp
+++ libc/utils/gpu/server/rpc_server.cpp
@@ -102,6 +102,8 @@
       break;
     }
     case RPC_EXIT: {
+      // Send an empty response to sync with the client prior to exiting.
+      port->recv_and_send([](rpc::Buffer *) {});
       port->recv([](rpc::Buffer *buffer) {
         int status = 0;
         std::memcpy(&status, buffer->data, sizeof(int));
Index: libc/src/__support/OSUtil/gpu/quick_exit.cpp
===================================================================
--- libc/src/__support/OSUtil/gpu/quick_exit.cpp
+++ libc/src/__support/OSUtil/gpu/quick_exit.cpp
@@ -18,6 +18,7 @@
 
 void quick_exit(int status) {
   rpc::Client::Port port = rpc::client.open<RPC_EXIT>();
+  port.send_and_recv([](rpc::Buffer *) {}, [](rpc::Buffer *) {});
   port.send([&](rpc::Buffer *buffer) {
     reinterpret_cast<uint32_t *>(buffer->data)[0] = status;
   });
Index: libc/docs/gpu/support.rst
===================================================================
--- libc/docs/gpu/support.rst
+++ libc/docs/gpu/support.rst
@@ -89,6 +89,7 @@
 atof           |check|
 atol           |check|
 atoll          |check|
+exit           |check|    |check|
 labs           |check|
 llabs          |check|
 strtod         |check|
@@ -98,6 +99,7 @@
 strtoll        |check|
 strtoul        |check|
 strtoull       |check|
+strtoull       |check|
 =============  =========  ============
 
 stdio.h


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154112.535870.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230629/7ac88942/attachment-0001.bin>


More information about the libc-commits mailing list