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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Compile-time target predicates (plan #78).
//!
//! Borrowed from MAX's `std.gpu.host.info` `is_cpu` / `is_valid_target`
//! pattern. Centralized const fns the optimizer / fusion patterns use
//! to prune backend-specific code paths at compile time instead of
//! branching at runtime.
//!
//! Why a module instead of inline `cfg!()`?
//! - One source of truth: changing a predicate (e.g. broadening
//! `has_amx` to include M-series Pro/Max) updates every call site.
//! - Documented contract: each predicate's docstring records what
//! the answer means and what kernels rely on it.
//! - `const fn`: can be used in const contexts (lookup tables,
//! static assertions).
/// True on Apple Silicon — M-series Macs and the A/M/S-series chips in
/// iPhones, iPads, Apple TVs, Apple Watches and Vision Pro (plus the
/// aarch64 simulators). They ship the AMX coprocessor (and, except the
/// Watch, a Metal GPU), so the same fast paths apply. The x86_64
/// simulators are deliberately excluded (they run on Intel Macs).
pub const
/// True on iOS (iPhone/iPad), device or simulator.
pub const
/// True on tvOS (Apple TV), device or simulator.
pub const
/// True on watchOS (Apple Watch), device or simulator. Note: watchOS has
/// no Metal — see [`has_metal`].
pub const
/// True on visionOS (Apple Vision Pro / "xrOS"), device or simulator.
pub const
/// True on any Apple platform that RLX builds native backends for —
/// macOS, iOS, tvOS, watchOS or visionOS. The Accelerate (AMX BLAS) and
/// CoreML/ANE backends compile on all of them; use this instead of
/// repeating the `target_vendor = "apple"` cfg inline. (Metal is the one
/// exception — it skips watchOS; see [`has_metal`].)
pub const
/// True on aarch64 broadly (Apple Silicon + Linux ARM + AWS Graviton).
pub const
/// True on x86_64 (Intel / AMD desktop and server).
pub const
/// True on macOS (any arch).
pub const
/// True if NEON intrinsics are available. On AArch64 NEON is
/// architectural (always present); on x86 we'd need explicit
/// runtime detection (not done here).
pub const
/// True if AVX2 is reasonably likely to be present at runtime.
/// This is a *static* prediction — explicit runtime detection
/// belongs in the dispatch path; this is for "should we even
/// compile the AVX2 code path?"
pub const
/// True when the target has access to the Apple AMX coprocessor —
/// i.e. through Accelerate's BLAS path. Not a direct AMX intrinsic
/// gate (those are unstable / undocumented); used by callers that
/// want to know "is there something matmul-grade besides NEON
/// available."
pub const
/// True on a Metal-capable Apple platform — macOS, iOS, tvOS and
/// visionOS. All ship Metal, MetalPerformanceShaders and MPSGraph, so the
/// native `rlx-metal` backend builds and runs on each. **watchOS is
/// excluded**: it has no public Metal API, so the Metal backend never
/// builds there (Accelerate + CoreML remain available via
/// [`is_apple_platform`]).
pub const