apple-mpsgraph 0.2.7

Safe Rust bindings for Apple's MetalPerformanceShadersGraph framework on macOS, backed by a Swift bridge
Documentation
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
use core::ffi::{c_char, c_void};

unsafe extern "C" {
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_object_retain`.
    pub fn mpsgraph_object_retain(handle: *mut c_void) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_operation_as_variable`.
    pub fn mpsgraph_operation_as_variable(handle: *mut c_void) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_variable_op_shape_len`.
    pub fn mpsgraph_variable_op_shape_len(handle: *mut c_void) -> usize;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_variable_op_copy_shape`.
    pub fn mpsgraph_variable_op_copy_shape(handle: *mut c_void, out_shape: *mut isize);
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_variable_op_data_type`.
    pub fn mpsgraph_variable_op_data_type(handle: *mut c_void) -> u32;

/// Calls the `MPSGraph` framework counterpart for `mpsgraph_convolution3d_descriptor_new`.
    pub fn mpsgraph_convolution3d_descriptor_new(
        stride_in_x: usize,
        stride_in_y: usize,
        stride_in_z: usize,
        dilation_rate_in_x: usize,
        dilation_rate_in_y: usize,
        dilation_rate_in_z: usize,
        groups: usize,
        padding_left: usize,
        padding_right: usize,
        padding_top: usize,
        padding_bottom: usize,
        padding_front: usize,
        padding_back: usize,
        padding_style: usize,
        data_layout: usize,
        weights_layout: usize,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_depthwise_convolution2d_descriptor_new`.
    pub fn mpsgraph_depthwise_convolution2d_descriptor_new(
        stride_in_x: usize,
        stride_in_y: usize,
        dilation_rate_in_x: usize,
        dilation_rate_in_y: usize,
        padding_left: usize,
        padding_right: usize,
        padding_top: usize,
        padding_bottom: usize,
        padding_style: usize,
        data_layout: usize,
        weights_layout: usize,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_depthwise_convolution3d_descriptor_new`.
    pub fn mpsgraph_depthwise_convolution3d_descriptor_new(
        strides: *const usize,
        strides_len: usize,
        dilation_rates: *const usize,
        dilation_rates_len: usize,
        padding_values: *const usize,
        padding_values_len: usize,
        padding_style: usize,
        channel_dimension_index: isize,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_fft_descriptor_new`.
    pub fn mpsgraph_fft_descriptor_new(
        inverse: bool,
        scaling_mode: usize,
        round_to_odd_hermitean: bool,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_im_to_col_descriptor_new`.
    pub fn mpsgraph_im_to_col_descriptor_new(
        kernel_width: usize,
        kernel_height: usize,
        stride_in_x: usize,
        stride_in_y: usize,
        dilation_rate_in_x: usize,
        dilation_rate_in_y: usize,
        padding_left: usize,
        padding_right: usize,
        padding_top: usize,
        padding_bottom: usize,
        data_layout: usize,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_pooling4d_descriptor_new`.
    pub fn mpsgraph_pooling4d_descriptor_new(
        kernel_sizes: *const usize,
        kernel_sizes_len: usize,
        strides: *const usize,
        strides_len: usize,
        dilation_rates: *const usize,
        dilation_rates_len: usize,
        padding_values: *const usize,
        padding_values_len: usize,
        padding_style: usize,
        ceil_mode: bool,
        include_zero_pad_to_average: bool,
        return_indices_mode: usize,
        return_indices_data_type: u32,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_sparse_descriptor_new`.
    pub fn mpsgraph_sparse_descriptor_new(storage_type: u64, data_type: u32) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_stencil_descriptor_new`.
    pub fn mpsgraph_stencil_descriptor_new(
        reduction_mode: usize,
        offsets: *const isize,
        offsets_len: usize,
        strides: *const usize,
        strides_len: usize,
        dilation_rates: *const usize,
        dilation_rates_len: usize,
        explicit_padding: *const usize,
        explicit_padding_len: usize,
        boundary_mode: isize,
        padding_style: usize,
        padding_constant: f32,
    ) -> *mut c_void;

/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_convolution3d`.
    pub fn mpsgraph_graph_convolution3d(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        weights_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_convolution_transpose2d`.
    pub fn mpsgraph_graph_convolution_transpose2d(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        weights_tensor: *mut c_void,
        output_shape: *const usize,
        output_shape_len: usize,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_cumulative_sum`.
    pub fn mpsgraph_graph_cumulative_sum(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        axis: isize,
        exclusive: bool,
        reverse: bool,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_depthwise_convolution2d`.
    pub fn mpsgraph_graph_depthwise_convolution2d(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        weights_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_depthwise_convolution3d`.
    pub fn mpsgraph_graph_depthwise_convolution3d(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        weights_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_fast_fourier_transform`.
    pub fn mpsgraph_graph_fast_fourier_transform(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        axes: *const usize,
        axes_len: usize,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_im_to_col`.
    pub fn mpsgraph_graph_im_to_col(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_band_part`.
    pub fn mpsgraph_graph_band_part(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        num_lower: isize,
        num_upper: isize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_softmax_cross_entropy`.
    pub fn mpsgraph_graph_softmax_cross_entropy(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        labels_tensor: *mut c_void,
        axis: isize,
        reduction_type: u64,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_matrix_inverse`.
    pub fn mpsgraph_graph_matrix_inverse(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_variable_data`.
    pub fn mpsgraph_graph_variable_data(
        graph_handle: *mut c_void,
        bytes: *const c_void,
        byte_len: usize,
        shape: *const usize,
        shape_len: usize,
        data_type: u32,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_read_variable`.
    pub fn mpsgraph_graph_read_variable(
        graph_handle: *mut c_void,
        variable_tensor: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_assign_variable`.
    pub fn mpsgraph_graph_assign_variable(
        graph_handle: *mut c_void,
        variable_tensor: *mut c_void,
        value_tensor: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_non_maximum_suppression`.
    pub fn mpsgraph_graph_non_maximum_suppression(
        graph_handle: *mut c_void,
        boxes_tensor: *mut c_void,
        scores_tensor: *mut c_void,
        iou_threshold: f32,
        score_threshold: f32,
        per_class_suppression: bool,
        coordinate_mode: usize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_non_zero_indices`.
    pub fn mpsgraph_graph_non_zero_indices(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_one_hot`.
    pub fn mpsgraph_graph_one_hot(
        graph_handle: *mut c_void,
        indices_tensor: *mut c_void,
        depth: usize,
        data_type: u32,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_stochastic_gradient_descent`.
    pub fn mpsgraph_graph_stochastic_gradient_descent(
        graph_handle: *mut c_void,
        learning_rate_tensor: *mut c_void,
        values_tensor: *mut c_void,
        gradient_tensor: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_max_pooling4d`.
    pub fn mpsgraph_graph_max_pooling4d(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_max_pooling4d_return_indices`.
    pub fn mpsgraph_graph_max_pooling4d_return_indices(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_quantize`.
    pub fn mpsgraph_graph_quantize(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        scale: f64,
        zero_point: f64,
        data_type: u32,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_dequantize`.
    pub fn mpsgraph_graph_dequantize(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        scale: f64,
        zero_point: f64,
        data_type: u32,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_resize`.
    pub fn mpsgraph_graph_resize(
        graph_handle: *mut c_void,
        images_tensor: *mut c_void,
        size: *const usize,
        size_len: usize,
        mode: usize,
        center_result: bool,
        align_corners: bool,
        layout: usize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_resize_nearest`.
    pub fn mpsgraph_graph_resize_nearest(
        graph_handle: *mut c_void,
        images_tensor: *mut c_void,
        size_tensor: *mut c_void,
        nearest_rounding_mode: usize,
        center_result: bool,
        align_corners: bool,
        layout: usize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_sample_grid`.
    pub fn mpsgraph_graph_sample_grid(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        coordinate_tensor: *mut c_void,
        layout: usize,
        normalize_coordinates: bool,
        relative_coordinates: bool,
        align_corners: bool,
        padding_mode: isize,
        sampling_mode: usize,
        constant_value: f64,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_scatter_nd`.
    pub fn mpsgraph_graph_scatter_nd(
        graph_handle: *mut c_void,
        updates_tensor: *mut c_void,
        indices_tensor: *mut c_void,
        shape: *const usize,
        shape_len: usize,
        batch_dimensions: usize,
        mode: isize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_scatter`.
    pub fn mpsgraph_graph_scatter(
        graph_handle: *mut c_void,
        updates_tensor: *mut c_void,
        indices_tensor: *mut c_void,
        shape: *const usize,
        shape_len: usize,
        axis: isize,
        mode: isize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_scatter_along_axis`.
    pub fn mpsgraph_graph_scatter_along_axis(
        graph_handle: *mut c_void,
        axis: isize,
        updates_tensor: *mut c_void,
        indices_tensor: *mut c_void,
        shape: *const usize,
        shape_len: usize,
        mode: isize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_sort`.
    pub fn mpsgraph_graph_sort(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        axis: isize,
        descending: bool,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_arg_sort`.
    pub fn mpsgraph_graph_arg_sort(
        graph_handle: *mut c_void,
        tensor: *mut c_void,
        axis: isize,
        descending: bool,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_sparse_tensor_with_descriptor`.
    pub fn mpsgraph_graph_sparse_tensor_with_descriptor(
        graph_handle: *mut c_void,
        descriptor_handle: *mut c_void,
        tensor_handles: *const *mut c_void,
        tensor_count: usize,
        shape: *const usize,
        shape_len: usize,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_stencil`.
    pub fn mpsgraph_graph_stencil(
        graph_handle: *mut c_void,
        source_tensor: *mut c_void,
        weights_tensor: *mut c_void,
        descriptor_handle: *mut c_void,
        name: *const c_char,
    ) -> *mut c_void;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_graph_topk_gradient`.
    pub fn mpsgraph_graph_topk_gradient(
        graph_handle: *mut c_void,
        gradient_tensor: *mut c_void,
        source_tensor: *mut c_void,
        k: usize,
        name: *const c_char,
    ) -> *mut c_void;

/// Calls the `MPSGraph` framework counterpart for `mpsgraph_execution_descriptor_wait_for_event`.
    pub fn mpsgraph_execution_descriptor_wait_for_event(
        handle: *mut c_void,
        event_handle: *mut c_void,
        value: u64,
    ) -> bool;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_execution_descriptor_signal_event`.
    pub fn mpsgraph_execution_descriptor_signal_event(
        handle: *mut c_void,
        event_handle: *mut c_void,
        execution_stage: u64,
        value: u64,
    ) -> bool;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_executable_execution_descriptor_wait_for_event`.
    pub fn mpsgraph_executable_execution_descriptor_wait_for_event(
        handle: *mut c_void,
        event_handle: *mut c_void,
        value: u64,
    ) -> bool;
/// Calls the `MPSGraph` framework counterpart for `mpsgraph_executable_execution_descriptor_signal_event`.
    pub fn mpsgraph_executable_execution_descriptor_signal_event(
        handle: *mut c_void,
        event_handle: *mut c_void,
        execution_stage: u64,
        value: u64,
    ) -> bool;
}