Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions libc/include/llvm-libc-types/test_rpc_opcodes_t.h

This file was deleted.

7 changes: 6 additions & 1 deletion libc/shared/rpc_opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "rpc.h"

#define LLVM_LIBC_RPC_BASE 'c'
#define LLVM_LIBC_OPCODE(n) (LLVM_LIBC_RPC_BASE << 24 | n)
#define LLVM_LIBC_OPCODE(n) (((LLVM_LIBC_RPC_BASE << 24) | n))

typedef enum {
LIBC_NOOP = LLVM_LIBC_OPCODE(0),
Expand Down Expand Up @@ -45,6 +45,11 @@ typedef enum {
LIBC_REMOVE = LLVM_LIBC_OPCODE(27),
LIBC_RENAME = LLVM_LIBC_OPCODE(28),
LIBC_SYSTEM = LLVM_LIBC_OPCODE(29),

// Internal opcodes for testing.
LIBC_TEST_INCREMENT = LLVM_LIBC_OPCODE(1 << 15),
LIBC_TEST_INTERFACE = LLVM_LIBC_OPCODE((1 << 15) + 1),
LIBC_TEST_STREAM = LLVM_LIBC_OPCODE((1 << 15) + 2),
LIBC_LAST = 0xFFFFFFFF,
} rpc_opcode_t;

Expand Down
49 changes: 49 additions & 0 deletions libc/src/__support/RPC/rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,55 @@ LIBC_INLINE static rpc::Status handle_port_impl(rpc::Server::Port &port) {
});
break;
}
case LIBC_TEST_INCREMENT: {
port.recv_and_send([](rpc::Buffer *buffer, uint32_t) {
reinterpret_cast<uint64_t *>(buffer->data)[0] += 1;
});
break;
}
case LIBC_TEST_INTERFACE: {
bool end_with_recv;
uint64_t cnt;
port.recv([&](rpc::Buffer *buffer, uint32_t) {
end_with_recv = buffer->data[0];
});
port.recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port.send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port.recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port.send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port.recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port.recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port.send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port.send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
if (end_with_recv)
port.recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
else
port.send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});

break;
}
case LIBC_TEST_STREAM: {
uint64_t sizes[num_lanes] = {0};
void *dst[num_lanes] = {nullptr};
port.recv_n(dst, sizes,
[](uint64_t size) -> void * { return new char[size]; });
port.send_n(dst, sizes);
for (uint64_t i = 0; i < num_lanes; ++i) {
if (dst[i])
delete[] reinterpret_cast<uint8_t *>(dst[i]);
}
break;
}
case LIBC_NOOP: {
port.recv([](rpc::Buffer *, uint32_t) {});
break;
Expand Down
3 changes: 1 addition & 2 deletions libc/test/integration/startup/gpu/rpc_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "src/__support/GPU/utils.h"
#include "src/__support/RPC/rpc_client.h"
#include "test/IntegrationTest/test.h"
Expand All @@ -18,7 +17,7 @@ using namespace LIBC_NAMESPACE;
static void test_interface(bool end_with_send) {
uint64_t cnt = 0;
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INTERFACE>();
LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_INTERFACE>();
port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = end_with_send;
});
Expand Down
5 changes: 2 additions & 3 deletions libc/test/integration/startup/gpu/rpc_lane_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "src/__support/GPU/utils.h"
#include "src/__support/RPC/rpc_client.h"
#include "test/IntegrationTest/test.h"
Expand All @@ -16,7 +15,7 @@ using namespace LIBC_NAMESPACE;
static void test_add() {
uint64_t cnt = gpu::get_lane_id();
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INCREMENT>();
LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_INCREMENT>();
port.send_and_recv(
[=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {
reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt;
Expand All @@ -29,7 +28,7 @@ static void test_add() {
EXPECT_EQ(gpu::get_thread_id(), gpu::get_lane_id());
}

TEST_MAIN(int argc, char **argv, char **envp) {
TEST_MAIN(int, char **, char **) {
test_add();

return 0;
Expand Down
7 changes: 3 additions & 4 deletions libc/test/integration/startup/gpu/rpc_stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "src/__support/GPU/utils.h"
#include "src/__support/RPC/rpc_client.h"
#include "src/__support/integer_to_string.h"
Expand Down Expand Up @@ -36,7 +35,7 @@ static void test_stream() {
inline_memcpy(send_ptr, str, send_size);
ASSERT_TRUE(inline_memcmp(send_ptr, str, send_size) == 0 && "Data mismatch");
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_STREAM>();
LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_STREAM>();
port.send_n(send_ptr, send_size);
port.recv_n(&recv_ptr, &recv_size,
[](uint64_t size) { return malloc(size); });
Expand Down Expand Up @@ -80,7 +79,7 @@ static void test_divergent() {
ASSERT_TRUE(inline_memcmp(buffer, &data[offset], offset) == 0 &&
"Data mismatch");
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_STREAM>();
LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_STREAM>();
port.send_n(buffer, offset);
inline_memset(buffer, 0, offset);
port.recv_n(&recv_ptr, &recv_size, [&](uint64_t) { return buffer; });
Expand All @@ -91,7 +90,7 @@ static void test_divergent() {
ASSERT_TRUE(recv_size == offset && "Data size mismatch");
}

TEST_MAIN(int argc, char **argv, char **envp) {
TEST_MAIN(int, char **, char **) {
test_stream();
test_divergent();

Expand Down
3 changes: 1 addition & 2 deletions libc/test/integration/startup/gpu/rpc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "src/__support/GPU/utils.h"
#include "src/__support/RPC/rpc_client.h"
#include "test/IntegrationTest/test.h"
Expand All @@ -19,7 +18,7 @@ static void test_add_simple() {
uint64_t cnt = 0;
for (uint32_t i = 0; i < num_additions; ++i) {
LIBC_NAMESPACE::rpc::Client::Port port =
LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INCREMENT>();
LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_INCREMENT>();
port.send_and_recv(
[=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {
reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt;
Expand Down
55 changes: 0 additions & 55 deletions llvm/tools/llvm-gpu-loader/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <cstddef>
#include <cstdint>

#include "include/llvm-libc-types/test_rpc_opcodes_t.h"

#include "shared/rpc.h"
#include "shared/rpc_opcodes.h"
#include "shared/rpc_server.h"
Expand All @@ -28,59 +26,6 @@ inline uint32_t handle_server(rpc::Server &server, uint32_t index,

int status = rpc::RPC_SUCCESS;
switch (port->get_opcode()) {
case RPC_TEST_INCREMENT: {
port->recv_and_send([](rpc::Buffer *buffer, uint32_t) {
reinterpret_cast<uint64_t *>(buffer->data)[0] += 1;
});
break;
}
case RPC_TEST_INTERFACE: {
bool end_with_recv;
uint64_t cnt;
port->recv([&](rpc::Buffer *buffer, uint32_t) {
end_with_recv = buffer->data[0];
});
port->recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port->send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port->recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port->send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port->recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port->recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
port->send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
port->send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});
if (end_with_recv)
port->recv([&](rpc::Buffer *buffer, uint32_t) { cnt = buffer->data[0]; });
else
port->send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = cnt = cnt + 1;
});

break;
}
case RPC_TEST_STREAM: {
uint64_t sizes[num_lanes] = {0};
void *dst[num_lanes] = {nullptr};
port->recv_n(dst, sizes,
[](uint64_t size) -> void * { return new char[size]; });
port->send_n(dst, sizes);
for (uint64_t i = 0; i < num_lanes; ++i) {
if (dst[i])
delete[] reinterpret_cast<uint8_t *>(dst[i]);
}
break;
}
case RPC_TEST_NOOP: {
port->recv([&](rpc::Buffer *, uint32_t) {});
break;
}
case LIBC_MALLOC: {
port->recv_and_send([&](rpc::Buffer *buffer, uint32_t) {
buffer->data[0] = reinterpret_cast<uintptr_t>(alloc(buffer->data[0]));
Expand Down
Loading