1 //===---------- GPU implementation of a quick exit function -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
10 #define LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
12 #include "quick_exit.h"
14 #include "src/__support/RPC/rpc_client.h"
15 #include "src/__support/macros/properties/architectures.h"
17 namespace __llvm_libc
{
19 void quick_exit(int status
) {
20 // We want to first make sure the server is listening before we exit.
21 rpc::Client::Port port
= rpc::client
.open
<RPC_EXIT
>();
22 port
.send_and_recv([](rpc::Buffer
*) {}, [](rpc::Buffer
*) {});
23 port
.send([&](rpc::Buffer
*buffer
) {
24 reinterpret_cast<uint32_t *>(buffer
->data
)[0] = status
;
28 #if defined(LIBC_TARGET_ARCH_IS_NVPTX)
29 LIBC_INLINE_ASM("exit;" ::: "memory");
30 #elif defined(LIBC_TARGET_ARCH_IS_AMDGPU)
31 // This will terminate the entire wavefront, may not be valid with divergent
33 __builtin_amdgcn_endpgm();
35 __builtin_unreachable();
38 } // namespace __llvm_libc
40 #endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H