objc2_core_ml/generated/
MLComputePlan.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::*;
7
8use crate::*;
9
10extern_class!(
11    /// A class describing the plan for executing a model.
12    ///
13    /// The application can use the plan to estimate the necessary cost and
14    /// resources of the model before running the predictions.
15    ///
16    /// ```text
17    /// // Load the compute plan of an ML Program model.
18    /// [MLComputePlan loadContentsOfURL:modelURL configuration:configuration completionHandler:^(MLComputePlan * _Nullable computePlan, NSError * _Nullable error) {
19    /// if (!computePlan) {
20    /// // Handle error.
21    /// return;
22    /// }
23    /// MLModelStructureProgram *program = computePlan.modelStructure.program;
24    /// if (!program) {
25    /// [NSException raise:NSInternalInconsistencyException format:
26    /// "
27    /// Unexpected model type."];
28    /// }
29    ///
30    /// MLModelStructureFunction *mainFunction = program.functions["main"];
31    /// if (!mainFunction) {
32    /// [NSException raise:NSInternalInconsistencyException format:
33    /// "
34    /// Missing main function."];
35    /// }
36    ///
37    /// NSArray
38    /// <MLModelStructureProgramOperation
39    /// *> *operations = mainFunction.block.operations;
40    /// for (MLModelStructureProgramOperation *operation in operations) {
41    /// // Get the compute device usage for the operation.
42    /// MLComputeDeviceUsage *computeDeviceUsage = [computePlan computeDeviceUsageForMLProgramOperation:operation];
43    /// // Get the estimated cost of executing the operation.
44    /// MLComputePlanCost *estimatedCost = [computePlan estimatedCostOfMLProgramOperation:operation];
45    ///
46    /// }
47    /// }];
48    /// ```
49    ///
50    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlcomputeplan?language=objc)
51    #[unsafe(super(NSObject))]
52    #[derive(Debug, PartialEq, Eq, Hash)]
53    pub struct MLComputePlan;
54);
55
56extern_conformance!(
57    unsafe impl NSObjectProtocol for MLComputePlan {}
58);
59
60impl MLComputePlan {
61    extern_methods!(
62        #[unsafe(method(init))]
63        #[unsafe(method_family = init)]
64        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
65
66        #[unsafe(method(new))]
67        #[unsafe(method_family = new)]
68        pub unsafe fn new() -> Retained<Self>;
69
70        #[cfg(all(feature = "MLModelConfiguration", feature = "block2"))]
71        /// Construct the compute plan of a model asynchronously given the location of its on-disk representation.
72        ///
73        ///
74        /// Parameter `url`: The location of its on-disk representation (.mlmodelc directory).
75        ///
76        /// Parameter `configuration`: The model configuration.
77        ///
78        /// Parameter `handler`: When the compute plan is constructed successfully or unsuccessfully, the completion handler is invoked with a valid MLComputePlan instance or NSError object.
79        #[unsafe(method(loadContentsOfURL:configuration:completionHandler:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn loadContentsOfURL_configuration_completionHandler(
82            url: &NSURL,
83            configuration: &MLModelConfiguration,
84            handler: &block2::DynBlock<dyn Fn(*mut MLComputePlan, *mut NSError)>,
85        );
86
87        #[cfg(all(
88            feature = "MLModelAsset",
89            feature = "MLModelConfiguration",
90            feature = "block2"
91        ))]
92        /// Construct the compute plan of a model asynchronously given the model asset.
93        ///
94        ///
95        /// Parameter `asset`: The model asset.
96        ///
97        /// Parameter `configuration`: The model configuration.
98        ///
99        /// Parameter `handler`: When the compute plan is constructed successfully or unsuccessfully, the completion handler is invoked with a valid MLComputePlan instance or NSError object.
100        #[unsafe(method(loadModelAsset:configuration:completionHandler:))]
101        #[unsafe(method_family = none)]
102        pub unsafe fn loadModelAsset_configuration_completionHandler(
103            asset: &MLModelAsset,
104            configuration: &MLModelConfiguration,
105            handler: &block2::DynBlock<dyn Fn(*mut MLComputePlan, *mut NSError)>,
106        );
107
108        #[cfg(all(
109            feature = "MLComputePlanCost",
110            feature = "MLModelStructureProgramOperation"
111        ))]
112        /// Returns the estimated cost of executing an ML Program operation.
113        ///
114        ///
115        /// Parameter `operation`: An ML Program operation.
116        ///
117        /// Returns: The estimated cost of executing the operation or nil if the cost couldn't be estimated.
118        #[unsafe(method(estimatedCostOfMLProgramOperation:))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn estimatedCostOfMLProgramOperation(
121            &self,
122            operation: &MLModelStructureProgramOperation,
123        ) -> Option<Retained<MLComputePlanCost>>;
124
125        #[cfg(all(
126            feature = "MLComputePlanDeviceUsage",
127            feature = "MLModelStructureNeuralNetworkLayer"
128        ))]
129        /// Returns the anticipated compute devices that would be used for executing a NeuralNetwork layer.
130        ///
131        ///
132        /// Parameter `layer`: A NeuralNetwork layer.
133        ///
134        /// Returns: The anticipated compute devices that would be used for executing the layer or `nil` if the usage couldn't be determined.
135        #[unsafe(method(computeDeviceUsageForNeuralNetworkLayer:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn computeDeviceUsageForNeuralNetworkLayer(
138            &self,
139            layer: &MLModelStructureNeuralNetworkLayer,
140        ) -> Option<Retained<MLComputePlanDeviceUsage>>;
141
142        #[cfg(all(
143            feature = "MLComputePlanDeviceUsage",
144            feature = "MLModelStructureProgramOperation"
145        ))]
146        /// Returns The anticipated compute devices that would be used for executing an ML Program operation.
147        ///
148        ///
149        /// Parameter `operation`: An ML Program operation.
150        ///
151        /// Returns: The anticipated compute devices that would be used for executing the operation or `nil`if the usage couldn't be determined.
152        #[unsafe(method(computeDeviceUsageForMLProgramOperation:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn computeDeviceUsageForMLProgramOperation(
155            &self,
156            operation: &MLModelStructureProgramOperation,
157        ) -> Option<Retained<MLComputePlanDeviceUsage>>;
158
159        #[cfg(feature = "MLModelStructure")]
160        /// The model structure.
161        #[unsafe(method(modelStructure))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn modelStructure(&self) -> Retained<MLModelStructure>;
164    );
165}