[libc-commits] [libc] [libc] Implement the 'remove' function on the GPU (PR #97096)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Jun 28 11:43:46 PDT 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/97096
Summary:
Straightforward RPC implementation of the `remove` function for the GPU.
Copies over the string and calls `remove` on it, passing the result
back. This is required for building some `libc++` functionality.
>From 229609abe4330b3e050caedf1986c54aacf192b8 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 28 Jun 2024 13:39:59 -0500
Subject: [PATCH] [libc] Implement the 'remove' function on the GPU
Summary:
Straightforward RPC implementation of the `remove` function for the GPU.
Copies over the string and calls `remove` on it, passing the result
back. This is required for building some `libc++` functionality.
---
libc/config/gpu/entrypoints.txt | 1 +
libc/include/llvm-libc-types/rpc_opcodes_t.h | 1 +
libc/src/stdio/gpu/CMakeLists.txt | 11 +++++++++
libc/src/stdio/gpu/remove.cpp | 26 ++++++++++++++++++++
libc/utils/gpu/server/rpc_server.cpp | 11 +++++++++
5 files changed, 50 insertions(+)
create mode 100644 libc/src/stdio/gpu/remove.cpp
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 69f1bdb381e16..c8d68d61f3212 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -205,6 +205,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.putc
libc.src.stdio.putchar
libc.src.stdio.puts
+ libc.src.stdio.remove
libc.src.stdio.stderr
libc.src.stdio.stdin
libc.src.stdio.stdout
diff --git a/libc/include/llvm-libc-types/rpc_opcodes_t.h b/libc/include/llvm-libc-types/rpc_opcodes_t.h
index faed7b5f5ff46..fb3bc7b68f710 100644
--- a/libc/include/llvm-libc-types/rpc_opcodes_t.h
+++ b/libc/include/llvm-libc-types/rpc_opcodes_t.h
@@ -34,6 +34,7 @@ typedef enum {
RPC_PRINTF_TO_STDOUT,
RPC_PRINTF_TO_STDERR,
RPC_PRINTF_TO_STREAM,
+ RPC_REMOVE,
RPC_LAST = 0xFFFF,
} rpc_opcode_t;
diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt
index 1b1e2a903cc0b..8940843ea91b2 100644
--- a/libc/src/stdio/gpu/CMakeLists.txt
+++ b/libc/src/stdio/gpu/CMakeLists.txt
@@ -262,6 +262,17 @@ add_entrypoint_object(
.gpu_file
)
+add_entrypoint_object(
+ remove
+ SRCS
+ remove.cpp
+ HDRS
+ ../remove.h
+ DEPENDS
+ libc.include.stdio
+ .gpu_file
+)
+
add_entrypoint_object(
stdin
SRCS
diff --git a/libc/src/stdio/gpu/remove.cpp b/libc/src/stdio/gpu/remove.cpp
new file mode 100644
index 0000000000000..398be5f7ef436
--- /dev/null
+++ b/libc/src/stdio/gpu/remove.cpp
@@ -0,0 +1,26 @@
+//===-- Implementation of remove ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdio/remove.h"
+#include "file.h"
+
+#include <stdio.h>
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, remove, (const char *path)) {
+ int ret;
+ rpc::Client::Port port = rpc::client.open<RPC_REMOVE>();
+ port.send_n(path, internal::string_length(path) + 1);
+ port.recv(
+ [&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); });
+ port.close();
+ return ret;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/utils/gpu/server/rpc_server.cpp b/libc/utils/gpu/server/rpc_server.cpp
index 095f3fa13ffad..a05fc8457a9cb 100644
--- a/libc/utils/gpu/server/rpc_server.cpp
+++ b/libc/utils/gpu/server/rpc_server.cpp
@@ -343,6 +343,17 @@ rpc_status_t handle_server_impl(
handle_printf<lane_size>(*port);
break;
}
+ case RPC_REMOVE: {
+ uint64_t sizes[lane_size] = {0};
+ void *args[lane_size] = {nullptr};
+ port->recv_n(args, sizes, [&](uint64_t size) { return new char[size]; });
+ port->send([&](rpc::Buffer *buffer, uint32_t id) {
+ buffer->data[0] = static_cast<uint64_t>(
+ remove(reinterpret_cast<const char *>(args[id])));
+ delete[] reinterpret_cast<uint8_t *>(args[id]);
+ });
+ break;
+ }
case RPC_NOOP: {
port->recv([](rpc::Buffer *) {});
break;
More information about the libc-commits
mailing list