objc2_metal_performance_shaders_graph/generated/MPSGraphExecutable.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7use objc2_metal::*;
8#[cfg(feature = "objc2-metal-performance-shaders")]
9use objc2_metal_performance_shaders::*;
10
11use crate::*;
12
13/// A notification when graph executable execution finishes.
14///
15/// - Parameters:
16/// - results: If no error, the results produced by the graph operation. If Graph hasn't yet allocated the results, this will be `NSNull`.
17/// - error: If an error occurs, more information might be found here.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphexecutablecompletionhandler?language=objc)
20#[cfg(all(
21 feature = "MPSGraphCore",
22 feature = "MPSGraphTensorData",
23 feature = "block2"
24))]
25pub type MPSGraphExecutableCompletionHandler =
26 *mut block2::DynBlock<dyn Fn(NonNull<NSArray<MPSGraphTensorData>>, *mut NSError)>;
27
28/// A notification when graph executable execution schedules.
29///
30/// - Parameters:
31/// - results: If no error, the results produced by the graph operation.
32/// - error: If an error occurs, more information might be found here.
33///
34/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphexecutablescheduledhandler?language=objc)
35#[cfg(all(
36 feature = "MPSGraphCore",
37 feature = "MPSGraphTensorData",
38 feature = "block2"
39))]
40pub type MPSGraphExecutableScheduledHandler =
41 *mut block2::DynBlock<dyn Fn(NonNull<NSArray<MPSGraphTensorData>>, *mut NSError)>;
42
43extern_class!(
44 /// A class that consists of all the levers to synchronize and schedule executable execution.
45 ///
46 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphexecutableexecutiondescriptor?language=objc)
47 #[unsafe(super(MPSGraphObject, NSObject))]
48 #[derive(Debug, PartialEq, Eq, Hash)]
49 #[cfg(feature = "MPSGraphCore")]
50 pub struct MPSGraphExecutableExecutionDescriptor;
51);
52
53#[cfg(feature = "MPSGraphCore")]
54extern_conformance!(
55 unsafe impl NSCopying for MPSGraphExecutableExecutionDescriptor {}
56);
57
58#[cfg(feature = "MPSGraphCore")]
59unsafe impl CopyingHelper for MPSGraphExecutableExecutionDescriptor {
60 type Result = Self;
61}
62
63#[cfg(feature = "MPSGraphCore")]
64extern_conformance!(
65 unsafe impl NSObjectProtocol for MPSGraphExecutableExecutionDescriptor {}
66);
67
68#[cfg(feature = "MPSGraphCore")]
69impl MPSGraphExecutableExecutionDescriptor {
70 extern_methods!(
71 #[cfg(all(feature = "MPSGraphTensorData", feature = "block2"))]
72 /// A notification that appears when graph-executable execution is scheduled.
73 ///
74 /// Default value is nil.
75 ///
76 /// # Safety
77 ///
78 /// - The returned block's argument 1 must be a valid pointer.
79 /// - The returned block's argument 2 must be a valid pointer or null.
80 #[unsafe(method(scheduledHandler))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn scheduledHandler(&self) -> MPSGraphExecutableScheduledHandler;
83
84 #[cfg(all(feature = "MPSGraphTensorData", feature = "block2"))]
85 /// Setter for [`scheduledHandler`][Self::scheduledHandler].
86 ///
87 /// # Safety
88 ///
89 /// `scheduled_handler` must be a valid pointer.
90 #[unsafe(method(setScheduledHandler:))]
91 #[unsafe(method_family = none)]
92 pub unsafe fn setScheduledHandler(
93 &self,
94 scheduled_handler: MPSGraphExecutableScheduledHandler,
95 );
96
97 #[cfg(all(feature = "MPSGraphTensorData", feature = "block2"))]
98 /// A notification that appears when graph-executable execution is finished.
99 ///
100 /// Default value is nil.
101 ///
102 /// # Safety
103 ///
104 /// - The returned block's argument 1 must be a valid pointer.
105 /// - The returned block's argument 2 must be a valid pointer or null.
106 #[unsafe(method(completionHandler))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn completionHandler(&self) -> MPSGraphExecutableCompletionHandler;
109
110 #[cfg(all(feature = "MPSGraphTensorData", feature = "block2"))]
111 /// Setter for [`completionHandler`][Self::completionHandler].
112 ///
113 /// # Safety
114 ///
115 /// `completion_handler` must be a valid pointer.
116 #[unsafe(method(setCompletionHandler:))]
117 #[unsafe(method_family = none)]
118 pub unsafe fn setCompletionHandler(
119 &self,
120 completion_handler: MPSGraphExecutableCompletionHandler,
121 );
122
123 /// Flag for the graph executable to wait till the execution has completed.
124 ///
125 /// Default value is false.
126 #[unsafe(method(waitUntilCompleted))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn waitUntilCompleted(&self) -> bool;
129
130 /// Setter for [`waitUntilCompleted`][Self::waitUntilCompleted].
131 #[unsafe(method(setWaitUntilCompleted:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn setWaitUntilCompleted(&self, wait_until_completed: bool);
134
135 /// Waits on these shared events before scheduling execution on the HW.
136 ///
137 /// This does not include encoding which can still continue.
138 ///
139 /// - Parameters:
140 /// - event: Shared event to wait on.
141 /// - value: Value for shared event to wait on.
142 #[unsafe(method(waitForEvent:value:))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn waitForEvent_value(
145 &self,
146 event: &ProtocolObject<dyn MTLSharedEvent>,
147 value: u64,
148 );
149
150 #[cfg(feature = "MPSGraph")]
151 /// Signals these shared events at execution stage and immediately proceeds.
152 ///
153 /// - Parameters:
154 /// - event: Shared event to signal.
155 /// - executionStage: Execution stage to signal event at.
156 /// - value: Value for shared event to wait on.
157 #[unsafe(method(signalEvent:atExecutionEvent:value:))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn signalEvent_atExecutionEvent_value(
160 &self,
161 event: &ProtocolObject<dyn MTLSharedEvent>,
162 execution_stage: MPSGraphExecutionStage,
163 value: u64,
164 );
165 );
166}
167
168/// Methods declared on superclass `NSObject`.
169#[cfg(feature = "MPSGraphCore")]
170impl MPSGraphExecutableExecutionDescriptor {
171 extern_methods!(
172 #[unsafe(method(init))]
173 #[unsafe(method_family = init)]
174 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
175
176 #[unsafe(method(new))]
177 #[unsafe(method_family = new)]
178 pub unsafe fn new() -> Retained<Self>;
179 );
180}
181
182/// The options available to a graph.
183///
184/// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphdeploymentplatform?language=objc)
185// NS_ENUM
186#[repr(transparent)]
187#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
188pub struct MPSGraphDeploymentPlatform(pub u64);
189impl MPSGraphDeploymentPlatform {
190 /// Deployment platofmr for macOS.
191 #[doc(alias = "MPSGraphDeploymentPlatformMacOS")]
192 pub const MacOS: Self = Self(0);
193 /// Deployment target for iOS.
194 #[doc(alias = "MPSGraphDeploymentPlatformIOS")]
195 pub const IOS: Self = Self(1);
196 /// Deployment target for tvOS.
197 #[doc(alias = "MPSGraphDeploymentPlatformTvOS")]
198 pub const TvOS: Self = Self(2);
199 /// Deployment target for visionOS.
200 #[doc(alias = "MPSGraphDeploymentPlatformVisionOS")]
201 pub const VisionOS: Self = Self(3);
202}
203
204unsafe impl Encode for MPSGraphDeploymentPlatform {
205 const ENCODING: Encoding = u64::ENCODING;
206}
207
208unsafe impl RefEncode for MPSGraphDeploymentPlatform {
209 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
210}
211
212extern_class!(
213 /// A class that consists of all the levers to serialize an executable.
214 ///
215 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphexecutableserializationdescriptor?language=objc)
216 #[unsafe(super(MPSGraphObject, NSObject))]
217 #[derive(Debug, PartialEq, Eq, Hash)]
218 #[cfg(feature = "MPSGraphCore")]
219 pub struct MPSGraphExecutableSerializationDescriptor;
220);
221
222#[cfg(feature = "MPSGraphCore")]
223extern_conformance!(
224 unsafe impl NSObjectProtocol for MPSGraphExecutableSerializationDescriptor {}
225);
226
227#[cfg(feature = "MPSGraphCore")]
228impl MPSGraphExecutableSerializationDescriptor {
229 extern_methods!(
230 /// Flag to append to an existing .mpsgraphpackage if found at provided url.
231 ///
232 /// If false, the exisiting .mpsgraphpackage will be overwritten.
233 #[unsafe(method(append))]
234 #[unsafe(method_family = none)]
235 pub unsafe fn append(&self) -> bool;
236
237 /// Setter for [`append`][Self::append].
238 #[unsafe(method(setAppend:))]
239 #[unsafe(method_family = none)]
240 pub unsafe fn setAppend(&self, append: bool);
241
242 /// The deployment platform used to serialize the executable.
243 ///
244 /// Defaults to the current platform.
245 #[unsafe(method(deploymentPlatform))]
246 #[unsafe(method_family = none)]
247 pub unsafe fn deploymentPlatform(&self) -> MPSGraphDeploymentPlatform;
248
249 /// Setter for [`deploymentPlatform`][Self::deploymentPlatform].
250 #[unsafe(method(setDeploymentPlatform:))]
251 #[unsafe(method_family = none)]
252 pub unsafe fn setDeploymentPlatform(&self, deployment_platform: MPSGraphDeploymentPlatform);
253
254 /// The minimum deployment target to serialize the executable.
255 ///
256 /// If not set, the package created will target the latest version of the `deploymentPlatform` set.
257 #[unsafe(method(minimumDeploymentTarget))]
258 #[unsafe(method_family = none)]
259 pub unsafe fn minimumDeploymentTarget(&self) -> Retained<NSString>;
260
261 /// Setter for [`minimumDeploymentTarget`][Self::minimumDeploymentTarget].
262 ///
263 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
264 #[unsafe(method(setMinimumDeploymentTarget:))]
265 #[unsafe(method_family = none)]
266 pub unsafe fn setMinimumDeploymentTarget(&self, minimum_deployment_target: &NSString);
267 );
268}
269
270/// Methods declared on superclass `NSObject`.
271#[cfg(feature = "MPSGraphCore")]
272impl MPSGraphExecutableSerializationDescriptor {
273 extern_methods!(
274 #[unsafe(method(init))]
275 #[unsafe(method_family = init)]
276 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
277
278 #[unsafe(method(new))]
279 #[unsafe(method_family = new)]
280 pub unsafe fn new() -> Retained<Self>;
281 );
282}
283
284extern_class!(
285 /// The compiled representation of a compute graph executable.
286 ///
287 /// An `MPSGraphExecutable` is a compiled graph for specific feeds for specific target tensors and target operations.
288 ///
289 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphexecutable?language=objc)
290 #[unsafe(super(MPSGraphObject, NSObject))]
291 #[derive(Debug, PartialEq, Eq, Hash)]
292 #[cfg(feature = "MPSGraphCore")]
293 pub struct MPSGraphExecutable;
294);
295
296#[cfg(feature = "MPSGraphCore")]
297unsafe impl Send for MPSGraphExecutable {}
298
299#[cfg(feature = "MPSGraphCore")]
300unsafe impl Sync for MPSGraphExecutable {}
301
302#[cfg(feature = "MPSGraphCore")]
303extern_conformance!(
304 unsafe impl NSObjectProtocol for MPSGraphExecutable {}
305);
306
307#[cfg(feature = "MPSGraphCore")]
308impl MPSGraphExecutable {
309 extern_methods!(
310 #[cfg(feature = "MPSGraph")]
311 /// Options for the graph executable.
312 ///
313 /// Default value is `MPSGraphOptionsDefault`.
314 #[unsafe(method(options))]
315 #[unsafe(method_family = none)]
316 pub unsafe fn options(&self) -> MPSGraphOptions;
317
318 #[cfg(feature = "MPSGraph")]
319 /// Setter for [`options`][Self::options].
320 #[unsafe(method(setOptions:))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn setOptions(&self, options: MPSGraphOptions);
323
324 #[cfg(feature = "MPSGraphTensor")]
325 /// Tensors fed to the graph, can be used to order the inputs when executable is created with a graph.
326 #[unsafe(method(feedTensors))]
327 #[unsafe(method_family = none)]
328 pub unsafe fn feedTensors(&self) -> Option<Retained<NSArray<MPSGraphTensor>>>;
329
330 #[cfg(feature = "MPSGraphTensor")]
331 /// Tensors targeted by the graph, can be used to order the outputs when executable was created with a graph.
332 #[unsafe(method(targetTensors))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn targetTensors(&self) -> Option<Retained<NSArray<MPSGraphTensor>>>;
335
336 #[cfg(all(feature = "MPSGraph", feature = "MPSGraphDevice"))]
337 /// Specialize the executable and optimize it.
338 ///
339 /// Use this method to choose when specialization happens, else it occurs at encode time automatically.
340 ///
341 /// - Parameters:
342 /// - device:Ooptional MPSGraph device to compile with.
343 /// - inputTypes: Input types expected to be passed to the executable.
344 /// - compilationDescriptor: Compilation descriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can.
345 #[unsafe(method(specializeWithDevice:inputTypes:compilationDescriptor:))]
346 #[unsafe(method_family = none)]
347 pub unsafe fn specializeWithDevice_inputTypes_compilationDescriptor(
348 &self,
349 device: Option<&MPSGraphDevice>,
350 input_types: &NSArray<MPSGraphType>,
351 compilation_descriptor: Option<&MPSGraphCompilationDescriptor>,
352 );
353
354 #[cfg(all(feature = "MPSGraph", feature = "MPSGraphDevice"))]
355 /// Get output shapes for a specialized executable.
356 ///
357 /// In case specialization has not been done yet then calling this function will specialize for the given input shapes.
358 ///
359 /// - Parameters:
360 /// - device: Optional MPSGraph device to compile with
361 /// - inputTypes: Input types expected to be passed to the executable.
362 /// - compilationDescriptor: CompilationDescriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can.
363 #[unsafe(method(getOutputTypesWithDevice:inputTypes:compilationDescriptor:))]
364 #[unsafe(method_family = none)]
365 pub unsafe fn getOutputTypesWithDevice_inputTypes_compilationDescriptor(
366 &self,
367 device: Option<&MPSGraphDevice>,
368 input_types: &NSArray<MPSGraphType>,
369 compilation_descriptor: Option<&MPSGraphCompilationDescriptor>,
370 ) -> Option<Retained<NSArray<MPSGraphShapedType>>>;
371
372 #[cfg(feature = "MPSGraphTensorData")]
373 /// Runs the graph for the given feeds and returns the target tensor values, ensuring all target operations also executed.
374 ///
375 /// This call is synchronous and will return on completion of execution.
376 ///
377 /// - Parameters:
378 /// - commandQueue: CommandQueue passed to exectute the graph on.
379 /// - inputsArray: Feeds tensorData for the placeholder tensors, same order as arguments of main function.
380 /// - resultsArray: Results tensorData for which the caller wishes MPSGraphTensorData to be returned.
381 /// - Returns: A valid MPSGraphTensorData array with results synchronized to the CPU memory if MPSGraphOptionsSynchronizeResults set.
382 #[unsafe(method(runWithMTLCommandQueue:inputsArray:resultsArray:executionDescriptor:))]
383 #[unsafe(method_family = none)]
384 pub unsafe fn runWithMTLCommandQueue_inputsArray_resultsArray_executionDescriptor(
385 &self,
386 command_queue: &ProtocolObject<dyn MTLCommandQueue>,
387 inputs_array: &NSArray<MPSGraphTensorData>,
388 results_array: Option<&NSArray<MPSGraphTensorData>>,
389 execution_descriptor: Option<&MPSGraphExecutableExecutionDescriptor>,
390 ) -> Retained<NSArray<MPSGraphTensorData>>;
391
392 #[cfg(feature = "MPSGraphTensorData")]
393 /// Runs the graph for the given feeds and returns the target tensor values, ensuring all target operations also executed.
394 /// This call is asynchronous and will return immediately.
395 ///
396 /// - Parameters:
397 /// - commandQueue: CommandQueue passed to exectute the graph on.
398 /// - inputsArray: Feeds tensorData for the placeholder tensors, same order as arguments of main function.
399 /// - resultsArray: Tensors for which the caller wishes MPSGraphTensorData to be returned.
400 /// - executionDescriptor: ExecutionDescriptor to be passed in and used.
401 /// - Returns: A valid MPSGraphTensorData array with results synchronized to the CPU memory if MPSGraphOptionsSynchronizeResults set.
402 #[unsafe(method(runAsyncWithMTLCommandQueue:inputsArray:resultsArray:executionDescriptor:))]
403 #[unsafe(method_family = none)]
404 pub unsafe fn runAsyncWithMTLCommandQueue_inputsArray_resultsArray_executionDescriptor(
405 &self,
406 command_queue: &ProtocolObject<dyn MTLCommandQueue>,
407 inputs_array: &NSArray<MPSGraphTensorData>,
408 results_array: Option<&NSArray<MPSGraphTensorData>>,
409 execution_descriptor: Option<&MPSGraphExecutableExecutionDescriptor>,
410 ) -> Retained<NSArray<MPSGraphTensorData>>;
411
412 #[cfg(all(
413 feature = "MPSGraphTensorData",
414 feature = "objc2-metal-performance-shaders"
415 ))]
416 /// Runs the graph for the given feeds and returns the target tensor values, ensuring all target operations also executed.
417 /// This call is asynchronous and will return immediately after finishing encoding.
418 ///
419 /// - Parameters:
420 /// - commandBuffer: CommandBuffer passed to exectute the graph on, commitAndContinue might be called, please don't rely on underlying MTLCommandBuffer to remain uncommitted
421 /// - inputsArray: Feeds tensorData for the placeholder tensors, same order as arguments of main function
422 /// - resultsArray: Tensors for which the caller wishes MPSGraphTensorData to be returned
423 /// - executionDescriptor: ExecutionDescriptor to be passed in and used,
424 /// - Returns: A valid MPSGraphTensorData array with results synchronized to the CPU memory if MPSGraphOptionsSynchronizeResults set.
425 #[unsafe(method(encodeToCommandBuffer:inputsArray:resultsArray:executionDescriptor:))]
426 #[unsafe(method_family = none)]
427 pub unsafe fn encodeToCommandBuffer_inputsArray_resultsArray_executionDescriptor(
428 &self,
429 command_buffer: &MPSCommandBuffer,
430 inputs_array: &NSArray<MPSGraphTensorData>,
431 results_array: Option<&NSArray<MPSGraphTensorData>>,
432 execution_descriptor: Option<&MPSGraphExecutableExecutionDescriptor>,
433 ) -> Retained<NSArray<MPSGraphTensorData>>;
434
435 /// Serialize the MPSGraph executable at the provided url.
436 ///
437 /// - Parameters:
438 /// - url: The URL where to serialize the MPSGraph executable.
439 /// - descriptor: The descriptor to be used to serialize the graph.
440 #[unsafe(method(serializeToMPSGraphPackageAtURL:descriptor:))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn serializeToMPSGraphPackageAtURL_descriptor(
443 &self,
444 url: &NSURL,
445 descriptor: Option<&MPSGraphExecutableSerializationDescriptor>,
446 );
447
448 #[cfg(feature = "MPSGraph")]
449 /// Initialize the executable with the Metal Performance Shaders Graph package at the provided URL.
450 ///
451 /// - Parameters:
452 /// - mpsgraphPackageURL: The URL where to read the serialized MPSGraphExecutable.
453 /// - compilationDescriptor: Compilation descriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can.
454 #[unsafe(method(initWithMPSGraphPackageAtURL:compilationDescriptor:))]
455 #[unsafe(method_family = init)]
456 pub unsafe fn initWithMPSGraphPackageAtURL_compilationDescriptor(
457 this: Allocated<Self>,
458 mpsgraph_package_url: &NSURL,
459 compilation_descriptor: Option<&MPSGraphCompilationDescriptor>,
460 ) -> Retained<Self>;
461
462 #[cfg(feature = "MPSGraph")]
463 /// Initialize the executable with the Core ML model package at the provided URL.
464 ///
465 /// - Parameters:
466 /// - coreMLPackageURL: The URL where to read the Core ML model package.
467 /// - compilationDescriptor: Compilation descriptor to be used to specialize, since the executable was created with a compilationDescriptor already this one overrides those settings to the extent it can.
468 #[unsafe(method(initWithCoreMLPackageAtURL:compilationDescriptor:))]
469 #[unsafe(method_family = init)]
470 pub unsafe fn initWithCoreMLPackageAtURL_compilationDescriptor(
471 this: Allocated<Self>,
472 core_ml_package_url: &NSURL,
473 compilation_descriptor: Option<&MPSGraphCompilationDescriptor>,
474 ) -> Retained<Self>;
475 );
476}
477
478/// Methods declared on superclass `NSObject`.
479#[cfg(feature = "MPSGraphCore")]
480impl MPSGraphExecutable {
481 extern_methods!(
482 #[unsafe(method(init))]
483 #[unsafe(method_family = init)]
484 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
485
486 #[unsafe(method(new))]
487 #[unsafe(method_family = new)]
488 pub unsafe fn new() -> Retained<Self>;
489 );
490}