Skip to content

Commit ec0e6ef

Browse files
authored
[libc] Implement the 'remove' function on the GPU (#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.
1 parent d32d20f commit ec0e6ef

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ set(TARGET_LIBC_ENTRYPOINTS
205205
libc.src.stdio.putc
206206
libc.src.stdio.putchar
207207
libc.src.stdio.puts
208+
libc.src.stdio.remove
208209
libc.src.stdio.stderr
209210
libc.src.stdio.stdin
210211
libc.src.stdio.stdout

libc/docs/gpu/support.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ puts |check| |check|
227227
fputs |check| |check|
228228
fputc |check| |check|
229229
fwrite |check| |check|
230+
remove |check| |check|
230231
putc |check| |check|
231232
putchar |check| |check|
232233
fclose |check| |check|

libc/include/llvm-libc-types/rpc_opcodes_t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef enum {
3434
RPC_PRINTF_TO_STDOUT,
3535
RPC_PRINTF_TO_STDERR,
3636
RPC_PRINTF_TO_STREAM,
37+
RPC_REMOVE,
3738
RPC_LAST = 0xFFFF,
3839
} rpc_opcode_t;
3940

libc/src/stdio/gpu/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ add_entrypoint_object(
262262
.gpu_file
263263
)
264264

265+
add_entrypoint_object(
266+
remove
267+
SRCS
268+
remove.cpp
269+
HDRS
270+
../remove.h
271+
DEPENDS
272+
libc.include.stdio
273+
.gpu_file
274+
)
275+
265276
add_entrypoint_object(
266277
stdin
267278
SRCS

libc/src/stdio/gpu/remove.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation of remove ------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/stdio/remove.h"
10+
#include "file.h"
11+
12+
#include <stdio.h>
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
LLVM_LIBC_FUNCTION(int, remove, (const char *path)) {
17+
int ret;
18+
rpc::Client::Port port = rpc::client.open<RPC_REMOVE>();
19+
port.send_n(path, internal::string_length(path) + 1);
20+
port.recv(
21+
[&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); });
22+
port.close();
23+
return ret;
24+
}
25+
26+
} // namespace LIBC_NAMESPACE

libc/utils/gpu/server/rpc_server.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ rpc_status_t handle_server_impl(
343343
handle_printf<lane_size>(*port);
344344
break;
345345
}
346+
case RPC_REMOVE: {
347+
uint64_t sizes[lane_size] = {0};
348+
void *args[lane_size] = {nullptr};
349+
port->recv_n(args, sizes, [&](uint64_t size) { return new char[size]; });
350+
port->send([&](rpc::Buffer *buffer, uint32_t id) {
351+
buffer->data[0] = static_cast<uint64_t>(
352+
remove(reinterpret_cast<const char *>(args[id])));
353+
delete[] reinterpret_cast<uint8_t *>(args[id]);
354+
});
355+
break;
356+
}
346357
case RPC_NOOP: {
347358
port->recv([](rpc::Buffer *) {});
348359
break;

0 commit comments

Comments
 (0)