1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-metal")]
#[cfg(not(target_os = "watchos"))]
use objc2_metal::*;
use crate::*;
/// [Apple's documentation](https://developer.apple.com/documentation/coreml/mlcomputeunits?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MLComputeUnits(pub NSInteger);
impl MLComputeUnits {
#[doc(alias = "MLComputeUnitsCPUOnly")]
pub const CPUOnly: Self = Self(0);
#[doc(alias = "MLComputeUnitsCPUAndGPU")]
pub const CPUAndGPU: Self = Self(1);
#[doc(alias = "MLComputeUnitsAll")]
pub const All: Self = Self(2);
#[doc(alias = "MLComputeUnitsCPUAndNeuralEngine")]
pub const CPUAndNeuralEngine: Self = Self(3);
}
unsafe impl Encode for MLComputeUnits {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for MLComputeUnits {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// An object to hold options for loading a model.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodelconfiguration?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MLModelConfiguration;
);
extern_conformance!(
unsafe impl NSCoding for MLModelConfiguration {}
);
extern_conformance!(
unsafe impl NSCopying for MLModelConfiguration {}
);
unsafe impl CopyingHelper for MLModelConfiguration {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MLModelConfiguration {}
);
extern_conformance!(
unsafe impl NSSecureCoding for MLModelConfiguration {}
);
impl MLModelConfiguration {
extern_methods!(
/// A human readable name of a MLModel instance for display purposes.
///
/// Use this property to set a name of a model instance so that runtime analysis tools (e.g. Instruments and os_log)
/// can display that name in the user interface.
///
/// CoreML framework doesn't parse nor filter the text. It is the client's responsibility to use appropriate text,
/// which may involve localization and privacy considerations.
///
/// When the property is nil, CoreML framework provides a default.
#[unsafe(method(modelDisplayName))]
#[unsafe(method_family = none)]
pub unsafe fn modelDisplayName(&self) -> Option<Retained<NSString>>;
/// Setter for [`modelDisplayName`][Self::modelDisplayName].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setModelDisplayName:))]
#[unsafe(method_family = none)]
pub unsafe fn setModelDisplayName(&self, model_display_name: Option<&NSString>);
#[unsafe(method(computeUnits))]
#[unsafe(method_family = none)]
pub unsafe fn computeUnits(&self) -> MLComputeUnits;
/// Setter for [`computeUnits`][Self::computeUnits].
#[unsafe(method(setComputeUnits:))]
#[unsafe(method_family = none)]
pub unsafe fn setComputeUnits(&self, compute_units: MLComputeUnits);
#[cfg(feature = "MLOptimizationHints")]
/// A group of hints for CoreML to optimize
#[unsafe(method(optimizationHints))]
#[unsafe(method_family = none)]
pub unsafe fn optimizationHints(&self) -> Retained<MLOptimizationHints>;
#[cfg(feature = "MLOptimizationHints")]
/// Setter for [`optimizationHints`][Self::optimizationHints].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setOptimizationHints:))]
#[unsafe(method_family = none)]
pub unsafe fn setOptimizationHints(&self, optimization_hints: &MLOptimizationHints);
);
}
/// Methods declared on superclass `NSObject`.
impl MLModelConfiguration {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}
/// MLGPUConfigurationOptions.
///
/// Allows app to specify GPU configuration options
impl MLModelConfiguration {
extern_methods!(
/// Set to YES to allow low precision accumulation on GPU when available. Defaults to NO
#[unsafe(method(allowLowPrecisionAccumulationOnGPU))]
#[unsafe(method_family = none)]
pub unsafe fn allowLowPrecisionAccumulationOnGPU(&self) -> bool;
/// Setter for [`allowLowPrecisionAccumulationOnGPU`][Self::allowLowPrecisionAccumulationOnGPU].
#[unsafe(method(setAllowLowPrecisionAccumulationOnGPU:))]
#[unsafe(method_family = none)]
pub unsafe fn setAllowLowPrecisionAccumulationOnGPU(
&self,
allow_low_precision_accumulation_on_gpu: bool,
);
#[cfg(feature = "objc2-metal")]
#[cfg(not(target_os = "watchos"))]
/// Set to specify a preferred Metal device. Defaults to nil which indicates automatic selection
#[unsafe(method(preferredMetalDevice))]
#[unsafe(method_family = none)]
pub unsafe fn preferredMetalDevice(
&self,
) -> Option<Retained<ProtocolObject<dyn MTLDevice>>>;
#[cfg(feature = "objc2-metal")]
#[cfg(not(target_os = "watchos"))]
/// Setter for [`preferredMetalDevice`][Self::preferredMetalDevice].
#[unsafe(method(setPreferredMetalDevice:))]
#[unsafe(method_family = none)]
pub unsafe fn setPreferredMetalDevice(
&self,
preferred_metal_device: Option<&ProtocolObject<dyn MTLDevice>>,
);
);
}
/// MLModelParameterAdditions.
///
/// Allows app to set model or update parameters as a dictionary.
impl MLModelConfiguration {
extern_methods!(
#[cfg(all(feature = "MLKey", feature = "MLParameterKey"))]
#[unsafe(method(parameters))]
#[unsafe(method_family = none)]
pub unsafe fn parameters(
&self,
) -> Option<Retained<NSDictionary<MLParameterKey, AnyObject>>>;
#[cfg(all(feature = "MLKey", feature = "MLParameterKey"))]
/// Setter for [`parameters`][Self::parameters].
///
/// # Safety
///
/// `parameters` generic should be of the correct type.
#[unsafe(method(setParameters:))]
#[unsafe(method_family = none)]
pub unsafe fn setParameters(
&self,
parameters: Option<&NSDictionary<MLParameterKey, AnyObject>>,
);
);
}
/// MultiFunctions.
impl MLModelConfiguration {
extern_methods!(
/// Function name that `MLModel` will use.
///
/// Some model types (e.g. ML Program) supports multiple functions in a model asset, where each `MLModel` instance is associated with a particular function.
///
/// Use `MLModelAsset` to get the list of available functions. Use `nil` to use a default function.
///
/// ```swift
/// let configuration = MLModelConfiguration()
/// configuration.functionName = "my_function"
/// ```
#[unsafe(method(functionName))]
#[unsafe(method_family = none)]
pub unsafe fn functionName(&self) -> Option<Retained<NSString>>;
/// Setter for [`functionName`][Self::functionName].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setFunctionName:))]
#[unsafe(method_family = none)]
pub unsafe fn setFunctionName(&self, function_name: Option<&NSString>);
);
}