objc2_ml_compute/generated/
MLCGraph.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6
7use crate::*;
8
9extern_class!(
10    /// A graph of layers that can be used to build a training or inference graph
11    ///
12    /// See also [Apple's documentation](https://developer.apple.com/documentation/mlcompute/mlcgraph?language=objc)
13    #[unsafe(super(NSObject))]
14    #[derive(Debug, PartialEq, Eq, Hash)]
15    #[deprecated]
16    pub struct MLCGraph;
17);
18
19extern_conformance!(
20    unsafe impl NSObjectProtocol for MLCGraph {}
21);
22
23impl MLCGraph {
24    extern_methods!(
25        #[cfg(feature = "MLCDevice")]
26        /// The device to be used when compiling and executing a graph
27        #[deprecated]
28        #[unsafe(method(device))]
29        #[unsafe(method_family = none)]
30        pub unsafe fn device(&self) -> Option<Retained<MLCDevice>>;
31
32        #[cfg(feature = "MLCLayer")]
33        /// Layers in the graph
34        #[deprecated]
35        #[unsafe(method(layers))]
36        #[unsafe(method_family = none)]
37        pub unsafe fn layers(&self) -> Retained<NSArray<MLCLayer>>;
38
39        /// Creates a new graph.
40        ///
41        /// Returns: A new graph.
42        #[deprecated]
43        #[unsafe(method(graph))]
44        #[unsafe(method_family = none)]
45        pub unsafe fn graph() -> Retained<Self>;
46
47        /// A DOT representation of the graph.
48        ///
49        /// For more info on the DOT language, refer to https://en.wikipedia.org/wiki/DOT_(graph_description_language).
50        /// Edges that have a dashed lines are those that have stop gradients, while those with solid lines don't.
51        #[deprecated]
52        #[unsafe(method(summarizedDOTDescription))]
53        #[unsafe(method_family = none)]
54        pub unsafe fn summarizedDOTDescription(&self) -> Retained<NSString>;
55
56        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
57        /// Add a layer to the graph
58        ///
59        /// Parameter `layer`: The layer
60        ///
61        /// Parameter `source`: The source tensor
62        ///
63        /// Returns: A result tensor
64        #[deprecated]
65        #[unsafe(method(nodeWithLayer:source:))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn nodeWithLayer_source(
68            &self,
69            layer: &MLCLayer,
70            source: &MLCTensor,
71        ) -> Option<Retained<MLCTensor>>;
72
73        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
74        /// Add a layer to the graph
75        ///
76        /// Parameter `layer`: The layer
77        ///
78        /// Parameter `sources`: A list of source tensors
79        ///
80        /// For variable length sequences of LSTMs/RNNs layers, create an MLCTensor of sortedSequenceLengths and pass it as the last index (i.e. index 2 or 4) of sources. This tensor must of be type MLCDataTypeInt32.
81        ///
82        /// Returns: A result tensor
83        #[deprecated]
84        #[unsafe(method(nodeWithLayer:sources:))]
85        #[unsafe(method_family = none)]
86        pub unsafe fn nodeWithLayer_sources(
87            &self,
88            layer: &MLCLayer,
89            sources: &NSArray<MLCTensor>,
90        ) -> Option<Retained<MLCTensor>>;
91
92        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
93        /// Add a layer to the graph
94        ///
95        /// Parameter `layer`: The layer
96        ///
97        /// Parameter `sources`: A list of source tensors
98        ///
99        /// Parameter `disableUpdate`: A flag to indicate if optimizer update should be disabled for this layer
100        ///
101        /// For variable length sequences of LSTMs/RNNs layers, create an MLCTensor of sortedSequenceLengths and pass it as the last index (i.e. index 2 or 4) of sources. This tensor must of be type MLCDataTypeInt32.
102        ///
103        /// Returns: A result tensor
104        #[deprecated]
105        #[unsafe(method(nodeWithLayer:sources:disableUpdate:))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn nodeWithLayer_sources_disableUpdate(
108            &self,
109            layer: &MLCLayer,
110            sources: &NSArray<MLCTensor>,
111            disable_update: bool,
112        ) -> Option<Retained<MLCTensor>>;
113
114        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
115        /// Add a loss layer to the graph
116        ///
117        /// Parameter `layer`: The loss layer
118        ///
119        /// Parameter `lossLabels`: The loss labels tensor
120        ///
121        /// For variable length sequences of LSTMs/RNNs layers, create an MLCTensor of sortedSequenceLengths and pass it as the last index (i.e. index 2 or 4) of sources. This tensor must of be type MLCDataTypeInt32.
122        ///
123        /// Returns: A result tensor
124        #[deprecated]
125        #[unsafe(method(nodeWithLayer:sources:lossLabels:))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn nodeWithLayer_sources_lossLabels(
128            &self,
129            layer: &MLCLayer,
130            sources: &NSArray<MLCTensor>,
131            loss_labels: &NSArray<MLCTensor>,
132        ) -> Option<Retained<MLCTensor>>;
133
134        #[cfg(feature = "MLCTensor")]
135        /// Add a split layer to the graph
136        ///
137        /// Parameter `source`: The source tensor
138        ///
139        /// Parameter `splitCount`: The number of splits
140        ///
141        /// Parameter `dimension`: The dimension to split the source tensor
142        ///
143        /// Returns: A result tensor
144        #[deprecated]
145        #[unsafe(method(splitWithSource:splitCount:dimension:))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn splitWithSource_splitCount_dimension(
148            &self,
149            source: &MLCTensor,
150            split_count: NSUInteger,
151            dimension: NSUInteger,
152        ) -> Option<Retained<NSArray<MLCTensor>>>;
153
154        #[cfg(feature = "MLCTensor")]
155        /// Add a split layer to the graph
156        ///
157        /// Parameter `source`: The source tensor
158        ///
159        /// Parameter `splitSectionLengths`: The lengths of each split section
160        ///
161        /// Parameter `dimension`: The dimension to split the source tensor
162        ///
163        /// Returns: A result tensor
164        #[deprecated]
165        #[unsafe(method(splitWithSource:splitSectionLengths:dimension:))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn splitWithSource_splitSectionLengths_dimension(
168            &self,
169            source: &MLCTensor,
170            split_section_lengths: &NSArray<NSNumber>,
171            dimension: NSUInteger,
172        ) -> Option<Retained<NSArray<MLCTensor>>>;
173
174        #[cfg(feature = "MLCTensor")]
175        /// Add a concat layer to the graph
176        ///
177        /// Parameter `sources`: The source tensors to concatenate
178        ///
179        /// Parameter `dimension`: The concatenation dimension
180        ///
181        /// Returns: A result tensor
182        #[deprecated]
183        #[unsafe(method(concatenateWithSources:dimension:))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn concatenateWithSources_dimension(
186            &self,
187            sources: &NSArray<MLCTensor>,
188            dimension: NSUInteger,
189        ) -> Option<Retained<MLCTensor>>;
190
191        #[cfg(feature = "MLCTensor")]
192        /// Add a reshape layer to the graph
193        ///
194        /// Parameter `shape`: An array representing the shape of result tensor
195        ///
196        /// Parameter `source`: The source tensor
197        ///
198        /// Returns: A result tensor
199        #[deprecated]
200        #[unsafe(method(reshapeWithShape:source:))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn reshapeWithShape_source(
203            &self,
204            shape: &NSArray<NSNumber>,
205            source: &MLCTensor,
206        ) -> Option<Retained<MLCTensor>>;
207
208        #[cfg(feature = "MLCTensor")]
209        /// Add a transpose layer to the graph
210        ///
211        /// Parameter `dimensions`: NSArray
212        /// <NSNumber
213        /// *> representing the desired ordering of dimensions
214        /// The dimensions array specifies the input axis source for each output axis, such that the
215        /// K'th element in the dimensions array specifies the input axis source for the K'th axis in the
216        /// output.  The batch dimension which is typically axis 0 cannot be transposed.
217        ///
218        /// Returns: A result tensor
219        #[deprecated]
220        #[unsafe(method(transposeWithDimensions:source:))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn transposeWithDimensions_source(
223            &self,
224            dimensions: &NSArray<NSNumber>,
225            source: &MLCTensor,
226        ) -> Option<Retained<MLCTensor>>;
227
228        #[cfg(feature = "MLCTensor")]
229        /// Add a select layer to the graph
230        ///
231        /// Parameter `sources`: The source tensors
232        ///
233        /// Parameter `condition`: The condition mask
234        ///
235        /// Returns: A result tensor
236        #[unsafe(method(selectWithSources:condition:))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn selectWithSources_condition(
239            &self,
240            sources: &NSArray<MLCTensor>,
241            condition: &MLCTensor,
242        ) -> Option<Retained<MLCTensor>>;
243
244        #[cfg(all(feature = "MLCTensor", feature = "MLCTypes"))]
245        /// Add a scatter layer to the graph
246        ///
247        /// Parameter `dimension`: The dimension along which to index
248        ///
249        /// Parameter `source`: The updates to use with scattering with index positions specified in indices to result tensor
250        ///
251        /// Parameter `indices`: The index of elements to scatter
252        ///
253        /// Parameter `copyFrom`: The source tensor whose data is  to be first copied to the result tensor
254        ///
255        /// Parameter `reductionType`: The reduction type applied for all values in source tensor that are scattered to a specific location in the result tensor.
256        /// Must be: MLCReductionTypeNone or MLCReductionTypeSum.
257        ///
258        /// Returns: A result tensor
259        #[unsafe(method(scatterWithDimension:source:indices:copyFrom:reductionType:))]
260        #[unsafe(method_family = none)]
261        pub unsafe fn scatterWithDimension_source_indices_copyFrom_reductionType(
262            &self,
263            dimension: NSUInteger,
264            source: &MLCTensor,
265            indices: &MLCTensor,
266            copy_from: &MLCTensor,
267            reduction_type: MLCReductionType,
268        ) -> Option<Retained<MLCTensor>>;
269
270        #[cfg(feature = "MLCTensor")]
271        /// Add a gather layer to the graph
272        ///
273        /// Parameter `dimension`: The dimension along which to index
274        ///
275        /// Parameter `source`: The source tensor
276        ///
277        /// Parameter `indices`: The index of elements to gather
278        ///
279        /// Returns: A result tensor
280        #[unsafe(method(gatherWithDimension:source:indices:))]
281        #[unsafe(method_family = none)]
282        pub unsafe fn gatherWithDimension_source_indices(
283            &self,
284            dimension: NSUInteger,
285            source: &MLCTensor,
286            indices: &MLCTensor,
287        ) -> Option<Retained<MLCTensor>>;
288
289        #[cfg(all(
290            feature = "MLCDevice",
291            feature = "MLCTensor",
292            feature = "MLCTensorData"
293        ))]
294        /// Associates data with input tensors. If the device is GPU, also copies the data to the device memory.
295        /// Returns true if the data is successfully associated with input tensors.
296        ///
297        /// This function should be used if you execute the forward, gradient and optimizer updates independently.
298        /// Before the forward pass is executed, the inputs should be written to device memory.  Similarly, before the
299        /// gradient pass is executed, the inputs (typically the initial gradient tensor) should be written to device
300        /// memory.  The caller must guarantee the lifetime of the underlying memory of each value of
301        /// `inputsData`for the entirety of each corresponding input tensor's lifetime.
302        ///
303        /// Parameter `inputsData`: The input data to use to write to device memory
304        ///
305        /// Parameter `inputTensors`: The list of tensors to perform writes on
306        ///
307        /// Parameter `device`: The device
308        ///
309        /// Parameter `batchSize`: The batch size.  This should be set to the actual batch size that may be used when we execute
310        /// the graph and can be a value less than or equal to the batch size specified in the tensor.
311        /// If set to 0, we use batch size specified in the tensor.
312        ///
313        /// Parameter `synchronous`: Whether to execute the copy to the device synchronously.  For performance, asynchronous
314        /// execution is recommended.
315        ///
316        /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor.
317        #[deprecated]
318        #[unsafe(method(bindAndWriteData:forInputs:toDevice:batchSize:synchronous:))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn bindAndWriteData_forInputs_toDevice_batchSize_synchronous(
321            &self,
322            inputs_data: &NSDictionary<NSString, MLCTensorData>,
323            input_tensors: &NSDictionary<NSString, MLCTensor>,
324            device: &MLCDevice,
325            batch_size: NSUInteger,
326            synchronous: bool,
327        ) -> bool;
328
329        #[cfg(all(
330            feature = "MLCDevice",
331            feature = "MLCTensor",
332            feature = "MLCTensorData"
333        ))]
334        /// Associates data with input tensors. If the device is GPU, also copies the data to the device memory.
335        /// Returns true if the data is successfully associated with input tensors.
336        ///
337        /// This function should be used if you execute the forward, gradient and optimizer updates independently.
338        /// Before the forward pass is executed, the inputs should be written to device memory.  Similarly, before the
339        /// gradient pass is executed, the inputs (typically the initial gradient tensor) should be written to device
340        /// memory.  The caller must guarantee the lifetime of the underlying memory of each value of
341        /// `inputsData`for the entirety of each corresponding input tensor's lifetime.
342        ///
343        /// Parameter `inputsData`: The input data to use to write to device memory
344        ///
345        /// Parameter `inputTensors`: The list of tensors to perform writes on
346        ///
347        /// Parameter `device`: The device
348        ///
349        /// Parameter `synchronous`: Whether to execute the copy to the device synchronously.  For performance, asynchronous
350        /// execution is recommended.
351        ///
352        /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor.
353        #[deprecated]
354        #[unsafe(method(bindAndWriteData:forInputs:toDevice:synchronous:))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn bindAndWriteData_forInputs_toDevice_synchronous(
357            &self,
358            inputs_data: &NSDictionary<NSString, MLCTensorData>,
359            input_tensors: &NSDictionary<NSString, MLCTensor>,
360            device: &MLCDevice,
361            synchronous: bool,
362        ) -> bool;
363
364        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
365        /// Get the source tensors for a layer in the training graph
366        ///
367        /// Parameter `layer`: A layer in the training graph
368        ///
369        /// Returns: A list of tensors
370        #[deprecated]
371        #[unsafe(method(sourceTensorsForLayer:))]
372        #[unsafe(method_family = none)]
373        pub unsafe fn sourceTensorsForLayer(
374            &self,
375            layer: &MLCLayer,
376        ) -> Retained<NSArray<MLCTensor>>;
377
378        #[cfg(all(feature = "MLCLayer", feature = "MLCTensor"))]
379        /// Get the result tensors for a layer in the training graph
380        ///
381        /// Parameter `layer`: A layer in the training graph
382        ///
383        /// Returns: A list of tensors
384        #[deprecated]
385        #[unsafe(method(resultTensorsForLayer:))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn resultTensorsForLayer(
388            &self,
389            layer: &MLCLayer,
390        ) -> Retained<NSArray<MLCTensor>>;
391    );
392}
393
394/// Methods declared on superclass `NSObject`.
395impl MLCGraph {
396    extern_methods!(
397        #[unsafe(method(init))]
398        #[unsafe(method_family = init)]
399        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
400
401        #[unsafe(method(new))]
402        #[unsafe(method_family = new)]
403        pub unsafe fn new() -> Retained<Self>;
404    );
405}