Skip to main content

apple_mpsgraph/ffi/
mod.rs

1use core::ffi::{c_char, c_void};
2
3unsafe extern "C" {
4    pub fn mpsgraph_object_release(handle: *mut c_void);
5
6    pub fn mpsgraph_tensor_data_new_with_bytes(
7        device_handle: *mut c_void,
8        bytes: *const c_void,
9        byte_len: usize,
10        shape: *const usize,
11        shape_len: usize,
12        data_type: u32,
13    ) -> *mut c_void;
14    pub fn mpsgraph_tensor_data_new_with_buffer(
15        buffer_handle: *mut c_void,
16        shape: *const usize,
17        shape_len: usize,
18        data_type: u32,
19    ) -> *mut c_void;
20    pub fn mpsgraph_tensor_data_data_type(handle: *mut c_void) -> u32;
21    pub fn mpsgraph_tensor_data_shape_len(handle: *mut c_void) -> usize;
22    pub fn mpsgraph_tensor_data_copy_shape(handle: *mut c_void, out_shape: *mut usize);
23    pub fn mpsgraph_tensor_data_read_bytes(
24        handle: *mut c_void,
25        dst: *mut c_void,
26        dst_len: usize,
27    ) -> bool;
28
29    pub fn mpsgraph_graph_new() -> *mut c_void;
30    pub fn mpsgraph_graph_placeholder(
31        graph_handle: *mut c_void,
32        shape: *const usize,
33        shape_len: usize,
34        data_type: u32,
35        name: *const c_char,
36    ) -> *mut c_void;
37    pub fn mpsgraph_graph_constant_data(
38        graph_handle: *mut c_void,
39        bytes: *const c_void,
40        byte_len: usize,
41        shape: *const usize,
42        shape_len: usize,
43        data_type: u32,
44    ) -> *mut c_void;
45    pub fn mpsgraph_graph_constant_scalar(
46        graph_handle: *mut c_void,
47        scalar: f64,
48        data_type: u32,
49    ) -> *mut c_void;
50    pub fn mpsgraph_graph_constant_scalar_shaped(
51        graph_handle: *mut c_void,
52        scalar: f64,
53        shape: *const usize,
54        shape_len: usize,
55        data_type: u32,
56    ) -> *mut c_void;
57
58    pub fn mpsgraph_graph_addition(
59        graph_handle: *mut c_void,
60        primary_tensor: *mut c_void,
61        secondary_tensor: *mut c_void,
62        name: *const c_char,
63    ) -> *mut c_void;
64    pub fn mpsgraph_graph_subtraction(
65        graph_handle: *mut c_void,
66        primary_tensor: *mut c_void,
67        secondary_tensor: *mut c_void,
68        name: *const c_char,
69    ) -> *mut c_void;
70    pub fn mpsgraph_graph_multiplication(
71        graph_handle: *mut c_void,
72        primary_tensor: *mut c_void,
73        secondary_tensor: *mut c_void,
74        name: *const c_char,
75    ) -> *mut c_void;
76    pub fn mpsgraph_graph_division(
77        graph_handle: *mut c_void,
78        primary_tensor: *mut c_void,
79        secondary_tensor: *mut c_void,
80        name: *const c_char,
81    ) -> *mut c_void;
82    pub fn mpsgraph_graph_matrix_multiplication(
83        graph_handle: *mut c_void,
84        primary_tensor: *mut c_void,
85        secondary_tensor: *mut c_void,
86        name: *const c_char,
87    ) -> *mut c_void;
88    pub fn mpsgraph_graph_relu(
89        graph_handle: *mut c_void,
90        tensor: *mut c_void,
91        name: *const c_char,
92    ) -> *mut c_void;
93    pub fn mpsgraph_graph_sigmoid(
94        graph_handle: *mut c_void,
95        tensor: *mut c_void,
96        name: *const c_char,
97    ) -> *mut c_void;
98    pub fn mpsgraph_graph_softmax(
99        graph_handle: *mut c_void,
100        tensor: *mut c_void,
101        axis: isize,
102        name: *const c_char,
103    ) -> *mut c_void;
104    pub fn mpsgraph_graph_reshape(
105        graph_handle: *mut c_void,
106        tensor: *mut c_void,
107        shape: *const usize,
108        shape_len: usize,
109        name: *const c_char,
110    ) -> *mut c_void;
111    pub fn mpsgraph_graph_transpose(
112        graph_handle: *mut c_void,
113        tensor: *mut c_void,
114        permutation: *const usize,
115        permutation_len: usize,
116        name: *const c_char,
117    ) -> *mut c_void;
118    pub fn mpsgraph_graph_slice(
119        graph_handle: *mut c_void,
120        tensor: *mut c_void,
121        dimension: usize,
122        start: isize,
123        length: isize,
124        name: *const c_char,
125    ) -> *mut c_void;
126    pub fn mpsgraph_graph_broadcast(
127        graph_handle: *mut c_void,
128        tensor: *mut c_void,
129        shape: *const usize,
130        shape_len: usize,
131        name: *const c_char,
132    ) -> *mut c_void;
133    pub fn mpsgraph_graph_reduction_sum(
134        graph_handle: *mut c_void,
135        tensor: *mut c_void,
136        axes: *const usize,
137        axes_len: usize,
138        name: *const c_char,
139    ) -> *mut c_void;
140    pub fn mpsgraph_graph_reduction_maximum(
141        graph_handle: *mut c_void,
142        tensor: *mut c_void,
143        axes: *const usize,
144        axes_len: usize,
145        name: *const c_char,
146    ) -> *mut c_void;
147    pub fn mpsgraph_graph_reduction_minimum(
148        graph_handle: *mut c_void,
149        tensor: *mut c_void,
150        axes: *const usize,
151        axes_len: usize,
152        name: *const c_char,
153    ) -> *mut c_void;
154    pub fn mpsgraph_graph_mean(
155        graph_handle: *mut c_void,
156        tensor: *mut c_void,
157        axes: *const usize,
158        axes_len: usize,
159        name: *const c_char,
160    ) -> *mut c_void;
161
162    pub fn mpsgraph_convolution2d_descriptor_new(
163        stride_in_x: usize,
164        stride_in_y: usize,
165        dilation_rate_in_x: usize,
166        dilation_rate_in_y: usize,
167        groups: usize,
168        padding_left: usize,
169        padding_right: usize,
170        padding_top: usize,
171        padding_bottom: usize,
172        padding_style: usize,
173        data_layout: usize,
174        weights_layout: usize,
175    ) -> *mut c_void;
176    pub fn mpsgraph_pooling2d_descriptor_new(
177        kernel_width: usize,
178        kernel_height: usize,
179        stride_in_x: usize,
180        stride_in_y: usize,
181        dilation_rate_in_x: usize,
182        dilation_rate_in_y: usize,
183        padding_left: usize,
184        padding_right: usize,
185        padding_top: usize,
186        padding_bottom: usize,
187        padding_style: usize,
188        data_layout: usize,
189    ) -> *mut c_void;
190    pub fn mpsgraph_graph_convolution2d(
191        graph_handle: *mut c_void,
192        source_tensor: *mut c_void,
193        weights_tensor: *mut c_void,
194        descriptor_handle: *mut c_void,
195        name: *const c_char,
196    ) -> *mut c_void;
197    pub fn mpsgraph_graph_max_pooling2d(
198        graph_handle: *mut c_void,
199        source_tensor: *mut c_void,
200        descriptor_handle: *mut c_void,
201        name: *const c_char,
202    ) -> *mut c_void;
203    pub fn mpsgraph_graph_normalize(
204        graph_handle: *mut c_void,
205        tensor: *mut c_void,
206        mean_tensor: *mut c_void,
207        variance_tensor: *mut c_void,
208        gamma_tensor: *mut c_void,
209        beta_tensor: *mut c_void,
210        epsilon: f32,
211        name: *const c_char,
212    ) -> *mut c_void;
213
214    pub fn mpsgraph_graph_run(
215        graph_handle: *mut c_void,
216        feed_tensors: *const *mut c_void,
217        feed_data: *const *mut c_void,
218        feed_count: usize,
219        target_tensors: *const *mut c_void,
220        target_count: usize,
221        out_results: *mut *mut c_void,
222    ) -> bool;
223    pub fn mpsgraph_graph_run_with_command_queue(
224        graph_handle: *mut c_void,
225        command_queue_handle: *mut c_void,
226        feed_tensors: *const *mut c_void,
227        feed_data: *const *mut c_void,
228        feed_count: usize,
229        target_tensors: *const *mut c_void,
230        target_count: usize,
231        out_results: *mut *mut c_void,
232    ) -> bool;
233    pub fn mpsgraph_graph_compile(
234        graph_handle: *mut c_void,
235        device_handle: *mut c_void,
236        feed_tensors: *const *mut c_void,
237        feed_count: usize,
238        flat_shapes: *const usize,
239        shape_lengths: *const usize,
240        data_types: *const u32,
241        target_tensors: *const *mut c_void,
242        target_count: usize,
243    ) -> *mut c_void;
244    pub fn mpsgraph_executable_run(
245        executable_handle: *mut c_void,
246        command_queue_handle: *mut c_void,
247        input_data: *const *mut c_void,
248        input_count: usize,
249        output_count: usize,
250        out_results: *mut *mut c_void,
251    ) -> bool;
252}