Skip to content

Commit a3a316e

Browse files
authored
[libc] Remove use of BlockStore for GPU atexit (#82823)
Summary: The GPU backends have restrictions on the kinds of initializers they can produce. The use of BlockStore here currently breaks the backends through the use of recursive initializers. This prevents it from actually being included in any builds. This patchs changes it to just use a fixed size of 64 slots .The chances of someone exceeding the 64 slots in practice is very, very low. However, this is primarily a bandaid solution as a real solution will need to use a lock free data structure to push work in parallel. Currently the mutexes on the GPU build do nothing, so they only work if the user guards the use themselves.
1 parent 6dd6d48 commit a3a316e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libc/src/stdlib/atexit.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ struct AtExitUnit {
2828
constexpr AtExitUnit(AtExitCallback *c, void *p) : callback(c), payload(p) {}
2929
};
3030

31-
#ifdef LIBC_COPT_PUBLIC_PACKAGING
31+
#if defined(LIBC_TARGET_ARCH_IS_GPU)
32+
// The GPU build cannot handle the potentially recursive definitions required by
33+
// the BlockStore class. Additionally, the liklihood that someone exceeds this
34+
// while executing on the GPU is extremely small.
35+
// FIXME: It is not generally safe to use 'atexit' on the GPU because the
36+
// mutexes simply passthrough. We will need a lock free stack.
37+
using ExitCallbackList = FixedVector<AtExitUnit, 64>;
38+
#elif defined(LIBC_COPT_PUBLIC_PACKAGING)
3239
using ExitCallbackList = cpp::ReverseOrderBlockStore<AtExitUnit, 32>;
3340
#else
3441
// BlockStore uses dynamic memory allocation. To avoid dynamic memory

0 commit comments

Comments
 (0)