diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2023-08-30 10:20:03 -0500 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2023-08-31 08:40:15 -0500 |
commit | 07102a11941d9287b58063e3d764694974205d53 (patch) | |
tree | 2f823040cec6c1120e4c19774a3b7cae0ded7964 /libc/src/stdlib | |
parent | 8f469bfedc907a391da7207ba248afdb7e8c555d (diff) | |
download | llvm-07102a11941d9287b58063e3d764694974205d53.zip llvm-07102a11941d9287b58063e3d764694974205d53.tar.gz llvm-07102a11941d9287b58063e3d764694974205d53.tar.bz2 |
[libc] Implement the 'abort' function on the GPU
This function implements the `abort` function on the GPU. The
implementation here closely mirros the `exit` call where we first
synchornize with the RPC server to make sure it's listening and then we
exit on the GPU.
I was unsure if this should be a simple `__builtin_assert` on the GPU. I
elected to go with an RPC approach to make this a more "true" `abort`
call. That is, it should invoke some signal handlers and exit with the
proper code according to the implemented C library on the server.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D159210
Diffstat (limited to 'libc/src/stdlib')
-rw-r--r-- | libc/src/stdlib/gpu/CMakeLists.txt | 11 | ||||
-rw-r--r-- | libc/src/stdlib/gpu/abort.cpp | 31 |
2 files changed, 42 insertions, 0 deletions
diff --git a/libc/src/stdlib/gpu/CMakeLists.txt b/libc/src/stdlib/gpu/CMakeLists.txt index 6a5d576..71ae106 100644 --- a/libc/src/stdlib/gpu/CMakeLists.txt +++ b/libc/src/stdlib/gpu/CMakeLists.txt @@ -19,3 +19,14 @@ add_entrypoint_object( libc.include.stdlib libc.src.__support.RPC.rpc_client ) + +add_entrypoint_object( + abort + SRCS + abort.cpp + HDRS + ../abort.h + DEPENDS + libc.include.stdlib + libc.src.__support.RPC.rpc_client +) diff --git a/libc/src/stdlib/gpu/abort.cpp b/libc/src/stdlib/gpu/abort.cpp new file mode 100644 index 0000000..5e208db --- /dev/null +++ b/libc/src/stdlib/gpu/abort.cpp @@ -0,0 +1,31 @@ +//===-- GPU implementation of abort ---------------------------------------===// +// +// 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/__support/RPC/rpc_client.h" +#include "src/__support/common.h" + +#include "src/stdlib/abort.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(void, abort, ()) { + // We want to first make sure the server is listening before we abort. + rpc::Client::Port port = rpc::client.open<RPC_ABORT>(); + port.send_and_recv([](rpc::Buffer *) {}, [](rpc::Buffer *) {}); + port.send([&](rpc::Buffer *) {}); + port.close(); + +#if defined(LIBC_TARGET_ARCH_IS_NVPTX) + LIBC_INLINE_ASM("exit;" ::: "memory"); +#elif defined(LIBC_TARGET_ARCH_IS_AMDGPU) + __builtin_amdgcn_endpgm(); +#endif + __builtin_unreachable(); +} + +} // namespace __llvm_libc |