aboutsummaryrefslogtreecommitdiff
path: root/libc/startup
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2023-03-24 15:53:05 -0500
committerJoseph Huber <jhuber6@vols.utk.edu>2023-03-24 20:04:43 -0500
commit58f5e5e6b00e5dd674d6e37ed651bc996a397cc3 (patch)
treeb4a9e09df973542c773062319560eab31a7655d8 /libc/startup
parent2bef46d2ad872794c83a49f1da12b1b20835f75d (diff)
downloadllvm-58f5e5e6b00e5dd674d6e37ed651bc996a397cc3.zip
llvm-58f5e5e6b00e5dd674d6e37ed651bc996a397cc3.tar.gz
llvm-58f5e5e6b00e5dd674d6e37ed651bc996a397cc3.tar.bz2
[libc] Implement the RPC client / server for NVPTX
This patch adds the necessary code to impelement the existing RPC client / server interface when targeting NVPTX GPUs. This follows closely to the implementation in the AMDGPU version. This does not yet enable unit testing as the `nvlink` linker does not support static libraries. So that will need to be worked around. I am ignoring the RPC duplication between the AMDGPU and NVPTX loaders. This will be changed completely later so there's no point unifying the code at this stage. The implementation was tested manually with the following file and compilation flags. ``` namespace __llvm_libc { void write_to_stderr(const char *msg); void quick_exit(int); } // namespace __llvm_libc using namespace __llvm_libc; int main(int argc, char **argv, char **envp) { for (int i = 0; i < argc; ++i) { write_to_stderr(argv[i]); write_to_stderr("\n"); } quick_exit(255); } ``` ``` $ clang++ crt1.o rpc_client.o quick_exit.o io.o main.cpp --target=nvptx64-nvidia-cuda -march=sm_70 -o image $ ./nvptx_loader image 1 2 3 image 1 2 3 $ echo $? 255 ``` Depends on D146681 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D146846
Diffstat (limited to 'libc/startup')
-rw-r--r--libc/startup/gpu/nvptx/CMakeLists.txt2
-rw-r--r--libc/startup/gpu/nvptx/start.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/libc/startup/gpu/nvptx/CMakeLists.txt b/libc/startup/gpu/nvptx/CMakeLists.txt
index 1ee2108..0fe0b2d 100644
--- a/libc/startup/gpu/nvptx/CMakeLists.txt
+++ b/libc/startup/gpu/nvptx/CMakeLists.txt
@@ -2,6 +2,8 @@ add_startup_object(
crt1
SRC
start.cpp
+ DEPENDS
+ libc.src.__support.RPC.rpc_client
COMPILE_OPTIONS
-ffreestanding # To avoid compiler warnings about calling the main function.
-fno-builtin
diff --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp
index 1e7f4ca..b09d6f6 100644
--- a/libc/startup/gpu/nvptx/start.cpp
+++ b/libc/startup/gpu/nvptx/start.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation of crt for amdgpu ----------------------------------===//
+//===-- Implementation of crt for nvptx -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,14 @@
//
//===----------------------------------------------------------------------===//
+#include "src/__support/RPC/rpc_client.h"
+
extern "C" int main(int argc, char **argv, char **envp);
extern "C" [[gnu::visibility("protected")]] __attribute__((nvptx_kernel)) void
_start(int argc, char **argv, char **envp, int *ret, void *in, void *out,
void *buffer) {
+ __llvm_libc::rpc::client.reset(in, out, buffer);
+
__atomic_fetch_or(ret, main(argc, argv, envp), __ATOMIC_RELAXED);
}