objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSCNNGroupNormalization.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
9use crate::*;
10
11extern_class!(
12    /// Dependencies: This depends on Metal.framework
13    ///
14    /// A state to hold information necessary to execute a gradient
15    /// pass for MPSCNNGroupNormalization.  Gradient states should
16    /// be created by using the forward kernel's methods.  This will
17    /// ensure that the state captures all information necessary to
18    /// execute the corresponding gradient pass.
19    ///
20    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnngroupnormalizationgradientstate?language=objc)
21    #[unsafe(super(MPSNNGradientState, MPSState, NSObject))]
22    #[derive(Debug, PartialEq, Eq, Hash)]
23    #[cfg(all(
24        feature = "MPSCore",
25        feature = "MPSNNGradientState",
26        feature = "MPSState"
27    ))]
28    pub struct MPSCNNGroupNormalizationGradientState;
29);
30
31#[cfg(all(
32    feature = "MPSCore",
33    feature = "MPSNNGradientState",
34    feature = "MPSState"
35))]
36extern_conformance!(
37    unsafe impl NSObjectProtocol for MPSCNNGroupNormalizationGradientState {}
38);
39
40#[cfg(all(
41    feature = "MPSCore",
42    feature = "MPSNNGradientState",
43    feature = "MPSState"
44))]
45impl MPSCNNGroupNormalizationGradientState {
46    extern_methods!(
47        #[cfg(all(feature = "MPSCNNKernel", feature = "MPSKernel"))]
48        /// The MPSCNNGroupNormalization object that created this state object.
49        #[unsafe(method(groupNormalization))]
50        #[unsafe(method_family = none)]
51        pub unsafe fn groupNormalization(&self) -> Retained<MPSCNNGroupNormalization>;
52
53        /// Return an MTLBuffer object with the state's current gamma values.
54        #[unsafe(method(gamma))]
55        #[unsafe(method_family = none)]
56        pub unsafe fn gamma(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
57
58        /// Return an MTLBuffer object with the state's current beta values..
59        #[unsafe(method(beta))]
60        #[unsafe(method_family = none)]
61        pub unsafe fn beta(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
62
63        #[unsafe(method(gradientForGamma))]
64        #[unsafe(method_family = none)]
65        pub unsafe fn gradientForGamma(&self) -> Retained<ProtocolObject<dyn MTLBuffer>>;
66
67        #[unsafe(method(gradientForBeta))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn gradientForBeta(&self) -> Retained<ProtocolObject<dyn MTLBuffer>>;
70
71        /// Unavailable.  Use MPSCNNGroupNormalization state creation methods.
72        #[unsafe(method(temporaryStateWithCommandBuffer:textureDescriptor:))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn temporaryStateWithCommandBuffer_textureDescriptor(
75            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
76            descriptor: &MTLTextureDescriptor,
77        ) -> Retained<Self>;
78
79        #[unsafe(method(temporaryStateWithCommandBuffer:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn temporaryStateWithCommandBuffer(
82            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
83        ) -> Retained<Self>;
84
85        #[unsafe(method(temporaryStateWithCommandBuffer:bufferSize:))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn temporaryStateWithCommandBuffer_bufferSize(
88            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
89            buffer_size: usize,
90        ) -> Retained<Self>;
91
92        /// Unavailable.  Use MPSCNNGroupNormalization state creation methods.
93        #[unsafe(method(initWithDevice:textureDescriptor:))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn initWithDevice_textureDescriptor(
96            this: Allocated<Self>,
97            device: &ProtocolObject<dyn MTLDevice>,
98            descriptor: &MTLTextureDescriptor,
99        ) -> Retained<Self>;
100
101        /// Unavailable.  Use MPSCNNGroupNormalization state creation methods.
102        ///
103        /// # Safety
104        ///
105        /// - `resource` may need to be synchronized.
106        /// - `resource` may be unretained, you must ensure it is kept alive while in use.
107        #[unsafe(method(initWithResource:))]
108        #[unsafe(method_family = init)]
109        pub unsafe fn initWithResource(
110            this: Allocated<Self>,
111            resource: Option<&ProtocolObject<dyn MTLResource>>,
112        ) -> Retained<Self>;
113
114        #[unsafe(method(initWithDevice:bufferSize:))]
115        #[unsafe(method_family = init)]
116        pub unsafe fn initWithDevice_bufferSize(
117            this: Allocated<Self>,
118            device: &ProtocolObject<dyn MTLDevice>,
119            buffer_size: usize,
120        ) -> Retained<Self>;
121    );
122}
123
124/// Methods declared on superclass `MPSState`.
125#[cfg(all(
126    feature = "MPSCore",
127    feature = "MPSNNGradientState",
128    feature = "MPSState"
129))]
130impl MPSCNNGroupNormalizationGradientState {
131    extern_methods!(
132        #[unsafe(method(init))]
133        #[unsafe(method_family = init)]
134        pub unsafe fn init(this: Allocated<Self>) -> Option<Retained<Self>>;
135
136        /// Initialize a non-temporary state to hold a number of textures and buffers
137        ///
138        /// The allocation of each resource will be deferred  until it is needed.
139        /// This occurs when -resource or -resourceAtIndex: is called.
140        ///
141        /// Parameter `resourceList`: The list of resources to create.
142        #[unsafe(method(initWithDevice:resourceList:))]
143        #[unsafe(method_family = init)]
144        pub unsafe fn initWithDevice_resourceList(
145            this: Allocated<Self>,
146            device: &ProtocolObject<dyn MTLDevice>,
147            resource_list: &MPSStateResourceList,
148        ) -> Retained<Self>;
149
150        /// Initialize a temporary state to hold a number of textures and buffers
151        ///
152        /// The textures occur first in sequence
153        #[unsafe(method(temporaryStateWithCommandBuffer:resourceList:))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn temporaryStateWithCommandBuffer_resourceList(
156            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
157            resource_list: &MPSStateResourceList,
158        ) -> Retained<Self>;
159
160        /// Create a state object with a list of MTLResources
161        ///
162        /// Because MPS prefers deferred allocation of resources
163        /// your application should use -initWithTextures:bufferSizes:bufferCount:
164        /// whenever possible. This method is useful for cases when the
165        /// MTLResources must be initialized by the CPU.
166        ///
167        /// # Safety
168        ///
169        /// - `resources` generic may need to be synchronized.
170        /// - `resources` generic may be unretained, you must ensure it is kept alive while in use.
171        #[unsafe(method(initWithResources:))]
172        #[unsafe(method_family = init)]
173        pub unsafe fn initWithResources(
174            this: Allocated<Self>,
175            resources: Option<&NSArray<ProtocolObject<dyn MTLResource>>>,
176        ) -> Retained<Self>;
177    );
178}
179
180/// Methods declared on superclass `NSObject`.
181#[cfg(all(
182    feature = "MPSCore",
183    feature = "MPSNNGradientState",
184    feature = "MPSState"
185))]
186impl MPSCNNGroupNormalizationGradientState {
187    extern_methods!(
188        #[unsafe(method(new))]
189        #[unsafe(method_family = new)]
190        pub unsafe fn new() -> Retained<Self>;
191    );
192}
193
194/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnngroupnormalizationgradientstatebatch?language=objc)
195#[cfg(all(
196    feature = "MPSCore",
197    feature = "MPSNNGradientState",
198    feature = "MPSState"
199))]
200pub type MPSCNNGroupNormalizationGradientStateBatch =
201    NSArray<MPSCNNGroupNormalizationGradientState>;
202
203extern_protocol!(
204    /// The MPSCNNGroupNormalizationDataSource protocol declares the methods that an
205    /// group of MPSCNNGroupNormalization uses to initialize the
206    /// scale factors (gamma) and bias terms (beta).
207    ///
208    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnngroupnormalizationdatasource?language=objc)
209    pub unsafe trait MPSCNNGroupNormalizationDataSource:
210        NSObjectProtocol + NSCopying
211    {
212        /// Return a pointer to an array containing the gamma terms.
213        ///
214        /// Must have numberOfFeatureChannels values since scaling is done per feature channel.
215        #[unsafe(method(gamma))]
216        #[unsafe(method_family = none)]
217        unsafe fn gamma(&self) -> *mut c_float;
218
219        /// Return a pointer to an array containing the beta terms.
220        ///
221        /// Must have numberOfFeatureChannels values since scaling is done per feature channel.
222        #[unsafe(method(beta))]
223        #[unsafe(method_family = none)]
224        unsafe fn beta(&self) -> *mut c_float;
225
226        #[unsafe(method(numberOfFeatureChannels))]
227        #[unsafe(method_family = none)]
228        unsafe fn numberOfFeatureChannels(&self) -> NSUInteger;
229
230        /// numberOfFeatureChannels/numberOfGroups channels are normalized together.
231        #[unsafe(method(numberOfGroups))]
232        #[unsafe(method_family = none)]
233        unsafe fn numberOfGroups(&self) -> NSUInteger;
234
235        /// Setter for [`numberOfGroups`][Self::numberOfGroups].
236        #[unsafe(method(setNumberOfGroups:))]
237        #[unsafe(method_family = none)]
238        unsafe fn setNumberOfGroups(&self, number_of_groups: NSUInteger);
239
240        /// A label that is transferred to the group normalization filter at init time
241        ///
242        /// Overridden by a MPSCNNGroupNormalizationNode.label if it is non-nil.
243        #[unsafe(method(label))]
244        #[unsafe(method_family = none)]
245        unsafe fn label(&self) -> Option<Retained<NSString>>;
246
247        #[cfg(all(
248            feature = "MPSCNNNormalizationWeights",
249            feature = "MPSCore",
250            feature = "MPSNNGradientState",
251            feature = "MPSState"
252        ))]
253        /// Compute new gamma and beta values using current values and gradients contained within a
254        /// MPSCNNGroupNormalizationStateBatch.
255        ///
256        /// This is for use in the context of training a network within a MPSNNGraph. If you are
257        /// writing your own graph using the low level interface or aren't training group normalization
258        /// it isn't needed.
259        ///
260        /// In this mathod, you should perform the update on a GPU, because at the time it is called
261        /// the data isn't in the state objects yet and the CPU can't do the work. You should not attempt
262        /// to update the MPSCNNGroupNormalization kernel directly with the results. The state object
263        /// returned from the function will be used for that.  A batch of states will be passed in.
264        /// You should accumulate the gradients and then update the weights.
265        ///
266        /// This operation is expected to also decrement the read count of groupNormalizationStateBatch by 1,
267        /// if the states are temporary.
268        ///
269        ///
270        /// Parameter `commandBuffer`: The command buffer on which to encode the update.
271        ///
272        ///
273        /// Parameter `groupNormalizationStateBatch`: A batch of MPSCNNGroupNormalizationGradientState objects containing
274        /// current weights and gradients.
275        ///
276        ///
277        /// Returns: A MPSCNNNormalizationGammaAndBetaState object containing updated gamma and beta values.  If NULL no
278        /// update was performed.
279        #[optional]
280        #[unsafe(method(updateGammaAndBetaWithCommandBuffer:groupNormalizationStateBatch:))]
281        #[unsafe(method_family = none)]
282        unsafe fn updateGammaAndBetaWithCommandBuffer_groupNormalizationStateBatch(
283            &self,
284            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
285            group_normalization_state_batch: &MPSCNNGroupNormalizationGradientStateBatch,
286        ) -> Option<Retained<MPSCNNNormalizationGammaAndBetaState>>;
287
288        #[cfg(all(
289            feature = "MPSCore",
290            feature = "MPSNNGradientState",
291            feature = "MPSState"
292        ))]
293        /// Compute new gamma and beta values using current values and gradients contained within a
294        /// batch MPSCNNGroupNormalizationState objects.  Perform the update on the CPU.
295        ///
296        ///
297        /// Parameter `groupNormalizationStateBatch`: A batch of MPSCNNGroupNormalizationGradientState objects containing
298        /// current gamma and beta values and gradients.
299        ///
300        ///
301        /// Returns: A boolean value indicating if the update was performed.
302        #[optional]
303        #[unsafe(method(updateGammaAndBetaWithGroupNormalizationStateBatch:))]
304        #[unsafe(method_family = none)]
305        unsafe fn updateGammaAndBetaWithGroupNormalizationStateBatch(
306            &self,
307            group_normalization_state_batch: &MPSCNNGroupNormalizationGradientStateBatch,
308        ) -> bool;
309
310        /// An optional tiny number to use to maintain numerical stability.
311        ///
312        /// output_image = (input_image - mean[c]) * gamma[c] / sqrt(variance[c] + epsilon) + beta[c];
313        /// Defalt value if method unavailable: FLT_MIN
314        #[optional]
315        #[unsafe(method(epsilon))]
316        #[unsafe(method_family = none)]
317        unsafe fn epsilon(&self) -> c_float;
318
319        /// Optional NSSecureCoding compatibility.
320        ///
321        /// # Safety
322        ///
323        /// `a_coder` possibly has further requirements.
324        #[optional]
325        #[unsafe(method(encodeWithCoder:))]
326        #[unsafe(method_family = none)]
327        unsafe fn encodeWithCoder(&self, a_coder: &NSCoder);
328
329        /// # Safety
330        ///
331        /// `a_decoder` possibly has further requirements.
332        #[optional]
333        #[unsafe(method(initWithCoder:))]
334        #[unsafe(method_family = init)]
335        unsafe fn initWithCoder(
336            this: Allocated<Self>,
337            a_decoder: &NSCoder,
338        ) -> Option<Retained<Self>>;
339
340        #[optional]
341        #[unsafe(method(supportsSecureCoding))]
342        #[unsafe(method_family = none)]
343        unsafe fn supportsSecureCoding() -> bool;
344
345        /// Optional copy method to create a copy of the data source for use with a new device.
346        ///
347        ///
348        /// Parameter `zone`: The NSZone on which to allocate.
349        ///
350        /// Parameter `device`: The device where the kernel which uses this data source will be used.
351        ///
352        ///
353        /// Returns: A pointer to a copy of this data source.
354        ///
355        /// # Safety
356        ///
357        /// `zone` must be a valid pointer or null.
358        #[optional]
359        #[unsafe(method(copyWithZone:device:))]
360        #[unsafe(method_family = copy)]
361        unsafe fn copyWithZone_device(
362            &self,
363            zone: *mut NSZone,
364            device: Option<&ProtocolObject<dyn MTLDevice>>,
365        ) -> Retained<Self>;
366    }
367);
368
369extern_class!(
370    /// Dependencies: This depends on Metal.framework
371    ///
372    /// This kernel normalizes each image, on a per-group basis, to
373    /// have zero mean and unit variance:
374    ///
375    /// for each image:
376    /// for each channel:
377    /// y = (x - mean) * gamma / sqrt(variance + epsilon) + beta;
378    ///
379    /// The mean and variance are computed per group of channels, as given by the dataSource.
380    ///
381    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnngroupnormalization?language=objc)
382    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
383    #[derive(Debug, PartialEq, Eq, Hash)]
384    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
385    pub struct MPSCNNGroupNormalization;
386);
387
388#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
389extern_conformance!(
390    unsafe impl NSCoding for MPSCNNGroupNormalization {}
391);
392
393#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
394extern_conformance!(
395    unsafe impl NSCopying for MPSCNNGroupNormalization {}
396);
397
398#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
399unsafe impl CopyingHelper for MPSCNNGroupNormalization {
400    type Result = Self;
401}
402
403#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
404extern_conformance!(
405    unsafe impl NSObjectProtocol for MPSCNNGroupNormalization {}
406);
407
408#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
409extern_conformance!(
410    unsafe impl NSSecureCoding for MPSCNNGroupNormalization {}
411);
412
413#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
414impl MPSCNNGroupNormalization {
415    extern_methods!(
416        /// The epsilon value used to bias the variance when normalizing.
417        #[unsafe(method(epsilon))]
418        #[unsafe(method_family = none)]
419        pub unsafe fn epsilon(&self) -> c_float;
420
421        /// Setter for [`epsilon`][Self::epsilon].
422        #[unsafe(method(setEpsilon:))]
423        #[unsafe(method_family = none)]
424        pub unsafe fn setEpsilon(&self, epsilon: c_float);
425
426        /// The data source that the object was initialized with
427        #[unsafe(method(dataSource))]
428        #[unsafe(method_family = none)]
429        pub unsafe fn dataSource(
430            &self,
431        ) -> Retained<ProtocolObject<dyn MPSCNNGroupNormalizationDataSource>>;
432
433        /// Initialize a MPSCNNGroupNormalization kernel on a device.
434        ///
435        /// Parameter `dataSource`: An object conforming to the MPSCNNGroupNormalizationDataSource
436        /// protocol which
437        #[unsafe(method(initWithDevice:dataSource:))]
438        #[unsafe(method_family = init)]
439        pub unsafe fn initWithDevice_dataSource(
440            this: Allocated<Self>,
441            device: &ProtocolObject<dyn MTLDevice>,
442            data_source: &ProtocolObject<dyn MPSCNNGroupNormalizationDataSource>,
443        ) -> Retained<Self>;
444
445        /// Use initWithDevice:dataSource instead
446        #[unsafe(method(initWithDevice:))]
447        #[unsafe(method_family = init)]
448        pub unsafe fn initWithDevice(
449            this: Allocated<Self>,
450            device: &ProtocolObject<dyn MTLDevice>,
451        ) -> Retained<Self>;
452
453        /// NSSecureCoding compatability
454        ///
455        /// While the standard NSSecureCoding/NSCoding method
456        /// -initWithCoder: should work, since the file can't
457        /// know which device your data is allocated on, we
458        /// have to guess and may guess incorrectly.  To avoid
459        /// that problem, use initWithCoder:device instead.
460        ///
461        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
462        ///
463        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
464        ///
465        /// Returns: A new MPSCNNGroupNormalization object, or nil if failure.
466        ///
467        /// # Safety
468        ///
469        /// `a_decoder` possibly has further requirements.
470        #[unsafe(method(initWithCoder:device:))]
471        #[unsafe(method_family = init)]
472        pub unsafe fn initWithCoder_device(
473            this: Allocated<Self>,
474            a_decoder: &NSCoder,
475            device: &ProtocolObject<dyn MTLDevice>,
476        ) -> Option<Retained<Self>>;
477
478        /// Reinitialize the filter using the data source provided at kernel initialization.
479        #[unsafe(method(reloadGammaAndBetaFromDataSource))]
480        #[unsafe(method_family = none)]
481        pub unsafe fn reloadGammaAndBetaFromDataSource(&self);
482
483        #[cfg(all(feature = "MPSCNNNormalizationWeights", feature = "MPSState"))]
484        /// Reload data using new gamma and beta terms contained within an
485        /// MPSCNNGroupNormalizationGradientState object.
486        ///
487        ///
488        /// Parameter `commandBuffer`: The command buffer on which to encode the reload.
489        ///
490        ///
491        /// Parameter `gammaAndBetaState`: The state containing the updated weights which are to
492        /// be reloaded.
493        #[unsafe(method(reloadGammaAndBetaWithCommandBuffer:gammaAndBetaState:))]
494        #[unsafe(method_family = none)]
495        pub unsafe fn reloadGammaAndBetaWithCommandBuffer_gammaAndBetaState(
496            &self,
497            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
498            gamma_and_beta_state: &MPSCNNNormalizationGammaAndBetaState,
499        );
500
501        #[cfg(all(
502            feature = "MPSImage",
503            feature = "MPSNNGradientState",
504            feature = "MPSState"
505        ))]
506        /// Return a MPSCNNGroupNormalizationGradientState object for the provided
507        /// source image, source states, and destination image.
508        #[unsafe(method(resultStateForSourceImage:sourceStates:destinationImage:))]
509        #[unsafe(method_family = none)]
510        pub unsafe fn resultStateForSourceImage_sourceStates_destinationImage(
511            &self,
512            source_image: &MPSImage,
513            source_states: Option<&NSArray<MPSState>>,
514            destination_image: &MPSImage,
515        ) -> Option<Retained<MPSCNNGroupNormalizationGradientState>>;
516
517        #[cfg(all(
518            feature = "MPSImage",
519            feature = "MPSNNGradientState",
520            feature = "MPSState"
521        ))]
522        /// Return a temporary MPSCNNGroupNormalizationGradientState object which may be used with
523        /// a MPSCNNGroupNormalization filter.
524        #[unsafe(method(temporaryResultStateForCommandBuffer:sourceImage:sourceStates:destinationImage:))]
525        #[unsafe(method_family = none)]
526        pub unsafe fn temporaryResultStateForCommandBuffer_sourceImage_sourceStates_destinationImage(
527            &self,
528            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
529            source_image: &MPSImage,
530            source_states: Option<&NSArray<MPSState>>,
531            destination_image: &MPSImage,
532        ) -> Option<Retained<MPSCNNGroupNormalizationGradientState>>;
533    );
534}
535
536/// Methods declared on superclass `MPSKernel`.
537#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
538impl MPSCNNGroupNormalization {
539    extern_methods!(
540        /// Called by NSCoder to decode MPSKernels
541        ///
542        /// This isn't the right interface to decode a MPSKernel, but
543        /// it is the one that NSCoder uses. To enable your NSCoder
544        /// (e.g. NSKeyedUnarchiver) to set which device to use
545        /// extend the object to adopt the MPSDeviceProvider
546        /// protocol. Otherwise, the Metal system default device
547        /// will be used.
548        ///
549        /// # Safety
550        ///
551        /// `a_decoder` possibly has further requirements.
552        #[unsafe(method(initWithCoder:))]
553        #[unsafe(method_family = init)]
554        pub unsafe fn initWithCoder(
555            this: Allocated<Self>,
556            a_decoder: &NSCoder,
557        ) -> Option<Retained<Self>>;
558    );
559}
560
561/// Methods declared on superclass `NSObject`.
562#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
563impl MPSCNNGroupNormalization {
564    extern_methods!(
565        #[unsafe(method(init))]
566        #[unsafe(method_family = init)]
567        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
568
569        #[unsafe(method(new))]
570        #[unsafe(method_family = new)]
571        pub unsafe fn new() -> Retained<Self>;
572    );
573}
574
575extern_class!(
576    /// Dependencies: This depends on Metal.framework
577    ///
578    /// This kernel executes a gradient pass corresponding to MPSCNNGroupNormalization.
579    ///
580    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnngroupnormalizationgradient?language=objc)
581    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
582    #[derive(Debug, PartialEq, Eq, Hash)]
583    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
584    pub struct MPSCNNGroupNormalizationGradient;
585);
586
587#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
588extern_conformance!(
589    unsafe impl NSCoding for MPSCNNGroupNormalizationGradient {}
590);
591
592#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
593extern_conformance!(
594    unsafe impl NSCopying for MPSCNNGroupNormalizationGradient {}
595);
596
597#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
598unsafe impl CopyingHelper for MPSCNNGroupNormalizationGradient {
599    type Result = Self;
600}
601
602#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
603extern_conformance!(
604    unsafe impl NSObjectProtocol for MPSCNNGroupNormalizationGradient {}
605);
606
607#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
608extern_conformance!(
609    unsafe impl NSSecureCoding for MPSCNNGroupNormalizationGradient {}
610);
611
612#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
613impl MPSCNNGroupNormalizationGradient {
614    extern_methods!();
615}
616
617/// Methods declared on superclass `MPSCNNGradientKernel`.
618#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
619impl MPSCNNGroupNormalizationGradient {
620    extern_methods!(
621        /// Standard init with default properties per filter type
622        ///
623        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
624        ///
625        /// Returns: A pointer to the newly initialized object. This will fail, returning
626        /// nil if the device is not supported. Devices must be
627        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
628        #[unsafe(method(initWithDevice:))]
629        #[unsafe(method_family = init)]
630        pub unsafe fn initWithDevice(
631            this: Allocated<Self>,
632            device: &ProtocolObject<dyn MTLDevice>,
633        ) -> Retained<Self>;
634
635        /// NSSecureCoding compatability
636        ///
637        /// While the standard NSSecureCoding/NSCoding method
638        /// -initWithCoder: should work, since the file can't
639        /// know which device your data is allocated on, we
640        /// have to guess and may guess incorrectly.  To avoid
641        /// that problem, use initWithCoder:device instead.
642        ///
643        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
644        ///
645        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
646        ///
647        /// Returns: A new MPSKernel object, or nil if failure.
648        ///
649        /// # Safety
650        ///
651        /// `a_decoder` possibly has further requirements.
652        #[unsafe(method(initWithCoder:device:))]
653        #[unsafe(method_family = init)]
654        pub unsafe fn initWithCoder_device(
655            this: Allocated<Self>,
656            a_decoder: &NSCoder,
657            device: &ProtocolObject<dyn MTLDevice>,
658        ) -> Option<Retained<Self>>;
659    );
660}
661
662/// Methods declared on superclass `MPSKernel`.
663#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
664impl MPSCNNGroupNormalizationGradient {
665    extern_methods!(
666        /// Called by NSCoder to decode MPSKernels
667        ///
668        /// This isn't the right interface to decode a MPSKernel, but
669        /// it is the one that NSCoder uses. To enable your NSCoder
670        /// (e.g. NSKeyedUnarchiver) to set which device to use
671        /// extend the object to adopt the MPSDeviceProvider
672        /// protocol. Otherwise, the Metal system default device
673        /// will be used.
674        ///
675        /// # Safety
676        ///
677        /// `a_decoder` possibly has further requirements.
678        #[unsafe(method(initWithCoder:))]
679        #[unsafe(method_family = init)]
680        pub unsafe fn initWithCoder(
681            this: Allocated<Self>,
682            a_decoder: &NSCoder,
683        ) -> Option<Retained<Self>>;
684    );
685}
686
687/// Methods declared on superclass `NSObject`.
688#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
689impl MPSCNNGroupNormalizationGradient {
690    extern_methods!(
691        #[unsafe(method(init))]
692        #[unsafe(method_family = init)]
693        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
694
695        #[unsafe(method(new))]
696        #[unsafe(method_family = new)]
697        pub unsafe fn new() -> Retained<Self>;
698    );
699}