Skip to content

Commit f7b7c69

Browse files
committed
[libc] Partially implement 'quick_exit' for the GPU
This patch adds a partial implementation of `quick_exit` for the GPU target. This is mainly done to test object libraries for the GPU and will be expanded later. This will simply cause the threads to terminate on the GPU without returning an error code. This functionality will be added later to facilitate unit tests. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D144421
1 parent 2893d55 commit f7b7c69

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_object_library(
2+
gpu_util
3+
SRCS
4+
quick_exit.cpp
5+
HDRS
6+
quick_exit.h
7+
DEPENDS
8+
libc.src.__support.common
9+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===---------- GPU implementation of a quick exit function -----*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
11+
12+
#include "quick_exit.h"
13+
14+
#include "src/__support/macros/properties/architectures.h"
15+
16+
namespace __llvm_libc {
17+
18+
void quick_exit(int status) {
19+
#if defined(LIBC_TARGET_ARCH_IS_NVPTX)
20+
asm("exit" ::: "memory");
21+
#elif defined(LIBC_TARGET_ARCH_IS_AMDGPU)
22+
// This will terminate the entire wavefront, may not be valid with divergent
23+
// work items.
24+
asm("s_endpgm" ::: "memory");
25+
#endif
26+
__builtin_unreachable();
27+
}
28+
29+
} // namespace __llvm_libc
30+
31+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===---------- GPU implementation of a quick exit function -----*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H
11+
12+
namespace __llvm_libc {
13+
14+
void quick_exit(int status);
15+
16+
} // namespace __llvm_libc
17+
18+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_GPU_QUICK_EXIT_H

libc/src/__support/OSUtil/quick_exit.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_QUICK_EXIT_H
1010
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_QUICK_EXIT_H
1111

12-
#ifdef __unix__
12+
#include "src/__support/macros/properties/architectures.h"
13+
14+
#if defined(LIBC_TARGET_ARCH_IS_GPU)
15+
#include "gpu/quick_exit.h"
16+
#elif defined(__unix__)
1317
#include "linux/quick_exit.h"
1418
#endif
1519

0 commit comments

Comments
 (0)