1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Runtime kind of the host program.
//!
//! Some backend decisions depend not on the device but on *how the host program itself is
//! being driven* — whether `main` runs on an asynchronous runtime, a synchronous
//! thread-based runtime, or a restricted no-std environment. This module stores that kind
//! in a process global so backends can read it and adapt their behavior.
//!
//! The canonical example is tensor readback (`into_data`): deferring the device→host copy
//! lazily is fine under a sync/threaded runtime (a later blocking read just parks a thread),
//! but under an async runtime the same blocking read parks an executor worker and starves
//! the runtime, so the read must materialize eagerly instead.
use ;
/// How the host program is being driven.
///
/// Set once near program start with [`set_runtime_kind`]; read anywhere with
/// [`runtime_kind`]. Defaults to [`RuntimeKind::Sync`].
static RUNTIME_KIND: AtomicU8 = new;
/// Declare the [kind](RuntimeKind) of runtime the host program is running on.
///
/// Intended to be called once near program start (e.g. when a remote server declares that
/// it hosts the backend on an async runtime). Backends read it via [`runtime_kind`].
/// Return the currently declared [kind](RuntimeKind) of runtime the host program runs on.
///
/// Defaults to [`RuntimeKind::Sync`] until [`set_runtime_kind`] is called.