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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! Generated MLX-C wrappers for the binary math family.
//!
//! Each wrapper maps one MLX-C operation onto the runtime GPU stream
//! with the crate's owned-handle and captured-error semantics. The
//! coverage contract keeps this family in lockstep with the pinned
//! upstream headers.
use crate::raw;
use crate::{MlxArray, MlxArrayVector, MlxBindingsContext, MlxCError};
impl MlxBindingsContext {
/// Applies MLX-C `mlx_allclose` on the runtime GPU stream.
pub fn allclose(
&self,
a: &MlxArray,
b: &MlxArray,
rtol: f64,
atol: f64,
equal_nan: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX allclose", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_allclose(output, a.raw(), b.raw(), rtol, atol, equal_nan, stream) }
})
}
/// Applies MLX-C `mlx_arctan2` on the runtime GPU stream.
pub fn arctan2(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX arctan2", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_arctan2(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_bitwise_and` on the runtime GPU stream.
pub fn bitwise_and(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX bitwise_and", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_bitwise_and(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_bitwise_invert` on the runtime GPU stream.
pub fn bitwise_invert(&self, a: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX bitwise_invert", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_bitwise_invert(output, a.raw(), stream) }
})
}
/// Applies MLX-C `mlx_bitwise_or` on the runtime GPU stream.
pub fn bitwise_or(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX bitwise_or", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_bitwise_or(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_bitwise_xor` on the runtime GPU stream.
pub fn bitwise_xor(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX bitwise_xor", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_bitwise_xor(output, a.raw(), b.raw(), stream) }
})
}
/// Builds the MLX-C `mlx_divmod` outputs on the runtime GPU stream.
pub fn divmod(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArrayVector, MlxCError> {
self.output_vector_array("apply MLX divmod", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_divmod(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_equal` on the runtime GPU stream.
pub fn equal(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX equal", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_equal(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_inner` on the runtime GPU stream.
pub fn inner(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX inner", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_inner(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_isclose` on the runtime GPU stream.
pub fn isclose(
&self,
a: &MlxArray,
b: &MlxArray,
rtol: f64,
atol: f64,
equal_nan: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX isclose", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_isclose(output, a.raw(), b.raw(), rtol, atol, equal_nan, stream) }
})
}
/// Applies MLX-C `mlx_kron` on the runtime GPU stream.
pub fn kron(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX kron", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_kron(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_less_equal` on the runtime GPU stream.
pub fn less_equal(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX less_equal", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_less_equal(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_logical_and` on the runtime GPU stream.
pub fn logical_and(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logical_and", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logical_and(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_logical_not` on the runtime GPU stream.
pub fn logical_not(&self, a: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logical_not", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logical_not(output, a.raw(), stream) }
})
}
/// Applies MLX-C `mlx_logical_or` on the runtime GPU stream.
pub fn logical_or(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logical_or", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logical_or(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_logical_xor` on the runtime GPU stream.
pub fn logical_xor(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logical_xor", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logical_xor(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_maximum` on the runtime GPU stream.
pub fn maximum(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX maximum", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_maximum(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_minimum` on the runtime GPU stream.
pub fn minimum(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX minimum", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_minimum(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_outer` on the runtime GPU stream.
pub fn outer(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX outer", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_outer(output, a.raw(), b.raw(), stream) }
})
}
/// Applies MLX-C `mlx_remainder` on the runtime GPU stream.
pub fn remainder(&self, a: &MlxArray, b: &MlxArray) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX remainder", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_remainder(output, a.raw(), b.raw(), stream) }
})
}
}