objc2_metal_performance_shaders_graph/generated/MPSGraphControlFlowOps.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
9/// The scope where all the operations defined in this block get control-dependency operations.
10///
11/// - Returns: A valid tensor with the results forwarded to the return of `controlDependency` call.
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphcontrolflowdependencyblock?language=objc)
14#[cfg(all(
15 feature = "MPSGraphCore",
16 feature = "MPSGraphTensor",
17 feature = "block2"
18))]
19pub type MPSGraphControlFlowDependencyBlock =
20 *mut block2::DynBlock<dyn Fn() -> NonNull<NSArray<MPSGraphTensor>>>;
21
22/// A block of operations executed under either the if or else condition.
23///
24/// - Returns: Tensors returned by user. If not empty, the user must define both the then and else blocks,
25/// both should have the same number of arguments, and each corresponding argument should have the same element types.
26///
27/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphifthenelseblock?language=objc)
28#[cfg(all(
29 feature = "MPSGraphCore",
30 feature = "MPSGraphTensor",
31 feature = "block2"
32))]
33pub type MPSGraphIfThenElseBlock =
34 *mut block2::DynBlock<dyn Fn() -> NonNull<NSArray<MPSGraphTensor>>>;
35
36/// The block that executes before the condition evaluates for each iteration.
37///
38/// - Parameters:
39/// - inputTensors: Input tensors to the `whileConditionBlock`, for the first iteration will be same as initialInputs passed to the while loop.
40/// - resultTensors: A valid `MPSGraphTensor` array with results forwarded to after block or returned from the while loop depending on the predicate tensor. It will be empty and the caller block should fill it up before returning.
41/// - Returns: Tensor MUST be set and have a single scalar value, used to decide between executing the body block or returning from the while loop.
42///
43/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphwhilebeforeblock?language=objc)
44#[cfg(all(
45 feature = "MPSGraphCore",
46 feature = "MPSGraphTensor",
47 feature = "block2"
48))]
49pub type MPSGraphWhileBeforeBlock = *mut block2::DynBlock<
50 dyn Fn(
51 NonNull<NSArray<MPSGraphTensor>>,
52 NonNull<NSMutableArray<MPSGraphTensor>>,
53 ) -> NonNull<MPSGraphTensor>,
54>;
55
56/// The block that executes after the condition evaluates for each iteration.
57///
58/// - Parameters:
59/// - bodyBlockArguments: Inputs to the body of the while loop passed by the condition block return, and should be the same element types as the return of the while loop.
60/// - Returns: A valid `MPSGraphTensor` array with results forwarded to the condition block.
61///
62/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphwhileafterblock?language=objc)
63#[cfg(all(
64 feature = "MPSGraphCore",
65 feature = "MPSGraphTensor",
66 feature = "block2"
67))]
68pub type MPSGraphWhileAfterBlock = *mut block2::DynBlock<
69 dyn Fn(NonNull<NSArray<MPSGraphTensor>>) -> NonNull<NSArray<MPSGraphTensor>>,
70>;
71
72/// A block for the body in the for loop.
73///
74/// - Parameters:
75/// - index: The for loop index per iteration, it is a scalar tensor.
76/// - iterationArguments: Arguments for this iteration, with the same count and corresponding element types as `initialIterationArguments` and return types of the `for` loop.
77/// - Returns: A valid MPSGraphTensor array with same count and corresponding element types as `initialIterationArguments` and return types of the `for` loop.
78///
79/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphforloopbodyblock?language=objc)
80#[cfg(all(
81 feature = "MPSGraphCore",
82 feature = "MPSGraphTensor",
83 feature = "block2"
84))]
85pub type MPSGraphForLoopBodyBlock = *mut block2::DynBlock<
86 dyn Fn(
87 NonNull<MPSGraphTensor>,
88 NonNull<NSArray<MPSGraphTensor>>,
89 ) -> NonNull<NSArray<MPSGraphTensor>>,
90>;
91
92/// MPSGraphControlFlowOps.
93#[cfg(all(feature = "MPSGraph", feature = "MPSGraphCore"))]
94impl MPSGraph {
95 extern_methods!(
96 #[cfg(all(
97 feature = "MPSGraphOperation",
98 feature = "MPSGraphTensor",
99 feature = "block2"
100 ))]
101 /// Runs the graph for the given feeds and returns the target tensor values, ensuring all target operations also executed.
102 ///
103 /// This call blocks until execution has completed.
104 ///
105 /// - Parameters:
106 /// - operations: Operations maked as control dependency for all ops created inside the dependent block
107 /// - dependentBlock: MPSGraphControlFlowDependencyBlock which is provided by caller to create dependent ops
108 /// - name: name of scope
109 /// - Returns: A valid MPSGraphTensor array with results returned from dependentBlock forwarded
110 ///
111 /// # Safety
112 ///
113 /// `dependent_block` must be a valid pointer.
114 #[unsafe(method(controlDependencyWithOperations:dependentBlock:name:))]
115 #[unsafe(method_family = none)]
116 pub unsafe fn controlDependencyWithOperations_dependentBlock_name(
117 &self,
118 operations: &NSArray<MPSGraphOperation>,
119 dependent_block: MPSGraphControlFlowDependencyBlock,
120 name: Option<&NSString>,
121 ) -> Retained<NSArray<MPSGraphTensor>>;
122
123 #[cfg(all(feature = "MPSGraphTensor", feature = "block2"))]
124 /// Adds an if-then-else operation to the graph.
125 ///
126 /// - Parameters:
127 /// - predicateTensor: Tensor must have a single scalar value, used to decide between then/else branches
128 /// - thenBlock: If predicate is true operations in this block are executed
129 /// - elseBlock: If predicate is false operations in this block are executed
130 /// - name: name of operation
131 /// - Returns: results If no error, the tensors returned by user. If not empty, user must define both then/else block,
132 /// both should have same number of arguments and each corresponding argument should have same elementTypes.
133 ///
134 /// # Safety
135 ///
136 /// - `then_block` must be a valid pointer.
137 /// - `else_block` must be a valid pointer or null.
138 #[unsafe(method(ifWithPredicateTensor:thenBlock:elseBlock:name:))]
139 #[unsafe(method_family = none)]
140 pub unsafe fn ifWithPredicateTensor_thenBlock_elseBlock_name(
141 &self,
142 predicate_tensor: &MPSGraphTensor,
143 then_block: MPSGraphIfThenElseBlock,
144 else_block: MPSGraphIfThenElseBlock,
145 name: Option<&NSString>,
146 ) -> Retained<NSArray<MPSGraphTensor>>;
147
148 #[cfg(all(feature = "MPSGraphTensor", feature = "block2"))]
149 /// Adds a while loop operation.
150 ///
151 /// - Parameters:
152 /// - initialInputs: inputTensors to the `beforeBlock`, for the 1st iteration will be same as initialInputs passed to the while loop.
153 /// - before: `beforeBlock`, this will be run first and then call the `afterBlock` with results or return results from the loop.
154 /// - after: `afterBlock`, this will execute after the condition evaluation.
155 /// - name: name of operation.
156 /// - Returns: A valid MPSGraphTensor array with results returned from the conditionBlock depending on the predicate tensor.
157 ///
158 /// # Safety
159 ///
160 /// - `before` must be a valid pointer.
161 /// - `after` must be a valid pointer.
162 #[unsafe(method(whileWithInitialInputs:before:after:name:))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn whileWithInitialInputs_before_after_name(
165 &self,
166 initial_inputs: &NSArray<MPSGraphTensor>,
167 before: MPSGraphWhileBeforeBlock,
168 after: MPSGraphWhileAfterBlock,
169 name: Option<&NSString>,
170 ) -> Retained<NSArray<MPSGraphTensor>>;
171
172 #[cfg(all(feature = "MPSGraphTensor", feature = "block2"))]
173 /// Adds a for loop operation, The lower and upper bounds specify a half-open range: the range includes the lower bound but does not include the upper bound.
174 ///
175 /// - Parameters:
176 /// - lowerBound: Lower bound value of the loop, this is a scalar tensor, this is the index the loop will start with.
177 /// - upperBound: Upper bound value of the loop, this is a scalar tensor.
178 /// - step: Step value of the loop, this is a scalar tensor and must be positive.
179 /// - initialBodyArguments: initial set of iteration arguments passed to the bodyBlock of the for loop.
180 /// - body: This block will execute the body of the for loop.
181 /// - name: name of operation.
182 /// - Returns: A valid `MPSGraphTensor` array with same count and corresponding element types as `initialIterationArguments` and return types of the for loop.
183 ///
184 /// # Safety
185 ///
186 /// `body` must be a valid pointer.
187 #[unsafe(method(forLoopWithLowerBound:upperBound:step:initialBodyArguments:body:name:))]
188 #[unsafe(method_family = none)]
189 pub unsafe fn forLoopWithLowerBound_upperBound_step_initialBodyArguments_body_name(
190 &self,
191 lower_bound: &MPSGraphTensor,
192 upper_bound: &MPSGraphTensor,
193 step: &MPSGraphTensor,
194 initial_body_arguments: &NSArray<MPSGraphTensor>,
195 body: MPSGraphForLoopBodyBlock,
196 name: Option<&NSString>,
197 ) -> Retained<NSArray<MPSGraphTensor>>;
198
199 #[cfg(all(feature = "MPSGraphTensor", feature = "block2"))]
200 /// Adds a for loop operation, with a specific number of iterations.
201 ///
202 /// - Parameters:
203 /// - numberOfIterations: tensor with number of iterations the loop will execute
204 /// - initialBodyArguments: initial set of iteration arguments passed to the bodyBlock of the for loop
205 /// - body: bodyBlock, this will execute the body of the for loop, index will go from 0 to numberOfIterations-1
206 /// - name: name of operation
207 /// - Returns: A valid MPSGraphTensor array with same count and corresponding elementTypes as initialIterationArguments and return types of the for loop
208 ///
209 /// # Safety
210 ///
211 /// `body` must be a valid pointer.
212 #[unsafe(method(forLoopWithNumberOfIterations:initialBodyArguments:body:name:))]
213 #[unsafe(method_family = none)]
214 pub unsafe fn forLoopWithNumberOfIterations_initialBodyArguments_body_name(
215 &self,
216 number_of_iterations: &MPSGraphTensor,
217 initial_body_arguments: &NSArray<MPSGraphTensor>,
218 body: MPSGraphForLoopBodyBlock,
219 name: Option<&NSString>,
220 ) -> Retained<NSArray<MPSGraphTensor>>;
221 );
222}