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
//! Generated MLX-C wrappers for the general convolution 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::bindings::support::optional_i32_slice;
use crate::raw;
use crate::{MlxArray, MlxBindingsContext, MlxCError};
impl MlxBindingsContext {
/// Applies MLX-C `mlx_conv_general` on the runtime GPU stream.
/// The wide signature mirrors the MLX-C declaration one-to-one; grouping
/// the parameters would hide which C argument each one feeds.
#[allow(clippy::too_many_arguments)]
pub fn conv_general(
&self,
input: &MlxArray,
weight: &MlxArray,
stride: &[i32],
padding_lo: &[i32],
padding_hi: &[i32],
kernel_dilation: &[i32],
input_dilation: &[i32],
groups: i32,
flip: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX conv_general", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_conv_general(
output,
input.raw(),
weight.raw(),
optional_i32_slice(stride),
stride.len(),
optional_i32_slice(padding_lo),
padding_lo.len(),
optional_i32_slice(padding_hi),
padding_hi.len(),
optional_i32_slice(kernel_dilation),
kernel_dilation.len(),
optional_i32_slice(input_dilation),
input_dilation.len(),
groups,
flip,
stream,
)
}
})
}
/// Applies MLX-C `mlx_conv_transpose1d` on the runtime GPU stream.
/// The wide signature mirrors the MLX-C declaration one-to-one; grouping
/// the parameters would hide which C argument each one feeds.
#[allow(clippy::too_many_arguments)]
pub fn conv_transpose1d(
&self,
input: &MlxArray,
weight: &MlxArray,
stride: i32,
padding: i32,
dilation: i32,
output_padding: i32,
groups: i32,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX conv_transpose1d", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_conv_transpose1d(
output,
input.raw(),
weight.raw(),
stride,
padding,
dilation,
output_padding,
groups,
stream,
)
}
})
}
/// Applies MLX-C `mlx_conv_transpose2d` on the runtime GPU stream.
/// The wide signature mirrors the MLX-C declaration one-to-one; grouping
/// the parameters would hide which C argument each one feeds.
#[allow(clippy::too_many_arguments)]
pub fn conv_transpose2d(
&self,
input: &MlxArray,
weight: &MlxArray,
stride_0: i32,
stride_1: i32,
padding_0: i32,
padding_1: i32,
dilation_0: i32,
dilation_1: i32,
output_padding_0: i32,
output_padding_1: i32,
groups: i32,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX conv_transpose2d", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_conv_transpose2d(
output,
input.raw(),
weight.raw(),
stride_0,
stride_1,
padding_0,
padding_1,
dilation_0,
dilation_1,
output_padding_0,
output_padding_1,
groups,
stream,
)
}
})
}
/// Applies MLX-C `mlx_conv_transpose3d` on the runtime GPU stream.
/// The wide signature mirrors the MLX-C declaration one-to-one; grouping
/// the parameters would hide which C argument each one feeds.
#[allow(clippy::too_many_arguments)]
pub fn conv_transpose3d(
&self,
input: &MlxArray,
weight: &MlxArray,
stride_0: i32,
stride_1: i32,
stride_2: i32,
padding_0: i32,
padding_1: i32,
padding_2: i32,
dilation_0: i32,
dilation_1: i32,
dilation_2: i32,
output_padding_0: i32,
output_padding_1: i32,
output_padding_2: i32,
groups: i32,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX conv_transpose3d", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_conv_transpose3d(
output,
input.raw(),
weight.raw(),
stride_0,
stride_1,
stride_2,
padding_0,
padding_1,
padding_2,
dilation_0,
dilation_1,
dilation_2,
output_padding_0,
output_padding_1,
output_padding_2,
groups,
stream,
)
}
})
}
}