objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSCNNMath.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    /// The MPSCNNArithmeticGradientState is used to hold the clamp mask used by both
15    /// MPSCNNArithmetic forward filter and MPSCNNArithmeticGradient backward filter.
16    /// The MPSCNNArithmetic forward filter populates the MPSCNNArithmeticGradientState
17    /// object and the MPSCNNArithmeticGradient backward filter consumes the state
18    /// object.
19    ///
20    /// The clamp mask is stored internally and is not accessible by the user.
21    ///
22    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnarithmeticgradientstate?language=objc)
23    #[unsafe(super(MPSNNBinaryGradientState, MPSState, NSObject))]
24    #[derive(Debug, PartialEq, Eq, Hash)]
25    #[cfg(all(
26        feature = "MPSCore",
27        feature = "MPSNNGradientState",
28        feature = "MPSState"
29    ))]
30    pub struct MPSCNNArithmeticGradientState;
31);
32
33#[cfg(all(
34    feature = "MPSCore",
35    feature = "MPSNNGradientState",
36    feature = "MPSState"
37))]
38extern_conformance!(
39    unsafe impl NSObjectProtocol for MPSCNNArithmeticGradientState {}
40);
41
42#[cfg(all(
43    feature = "MPSCore",
44    feature = "MPSNNGradientState",
45    feature = "MPSState"
46))]
47impl MPSCNNArithmeticGradientState {
48    extern_methods!(
49        #[unsafe(method(init))]
50        #[unsafe(method_family = init)]
51        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
52    );
53}
54
55/// Methods declared on superclass `MPSState`.
56#[cfg(all(
57    feature = "MPSCore",
58    feature = "MPSNNGradientState",
59    feature = "MPSState"
60))]
61impl MPSCNNArithmeticGradientState {
62    extern_methods!(
63        /// Create a MPSState holding a temporary MTLBuffer
64        ///
65        /// Parameter `cmdBuf`: The command buffer against which the temporary resource is allocated
66        ///
67        /// Parameter `bufferSize`: The size of the buffer in bytes
68        #[unsafe(method(temporaryStateWithCommandBuffer:bufferSize:))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn temporaryStateWithCommandBuffer_bufferSize(
71            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
72            buffer_size: usize,
73        ) -> Retained<Self>;
74
75        /// Create a MPSState holding a temporary MTLTexture
76        ///
77        /// Parameter `cmdBuf`: The command buffer against which the temporary resource is allocated
78        ///
79        /// Parameter `descriptor`: A descriptor for the new temporary texture
80        #[unsafe(method(temporaryStateWithCommandBuffer:textureDescriptor:))]
81        #[unsafe(method_family = none)]
82        pub unsafe fn temporaryStateWithCommandBuffer_textureDescriptor(
83            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
84            descriptor: &MTLTextureDescriptor,
85        ) -> Retained<Self>;
86
87        /// Create a new autoreleased temporary state object without underlying resource
88        ///
89        /// Parameter `cmdBuf`: The command buffer with which the temporary resource is associated
90        #[unsafe(method(temporaryStateWithCommandBuffer:))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn temporaryStateWithCommandBuffer(
93            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
94        ) -> Retained<Self>;
95
96        #[unsafe(method(initWithDevice:bufferSize:))]
97        #[unsafe(method_family = init)]
98        pub unsafe fn initWithDevice_bufferSize(
99            this: Allocated<Self>,
100            device: &ProtocolObject<dyn MTLDevice>,
101            buffer_size: usize,
102        ) -> Retained<Self>;
103
104        #[unsafe(method(initWithDevice:textureDescriptor:))]
105        #[unsafe(method_family = init)]
106        pub unsafe fn initWithDevice_textureDescriptor(
107            this: Allocated<Self>,
108            device: &ProtocolObject<dyn MTLDevice>,
109            descriptor: &MTLTextureDescriptor,
110        ) -> Retained<Self>;
111
112        /// Create a MPSState with a non-temporary MTLResource
113        ///
114        /// Parameter `resource`: A MTLBuffer or MTLTexture. May be nil.
115        ///
116        /// # Safety
117        ///
118        /// - `resource` may need to be synchronized.
119        /// - `resource` may be unretained, you must ensure it is kept alive while in use.
120        #[unsafe(method(initWithResource:))]
121        #[unsafe(method_family = init)]
122        pub unsafe fn initWithResource(
123            this: Allocated<Self>,
124            resource: Option<&ProtocolObject<dyn MTLResource>>,
125        ) -> Retained<Self>;
126
127        /// Initialize a non-temporary state to hold a number of textures and buffers
128        ///
129        /// The allocation of each resource will be deferred  until it is needed.
130        /// This occurs when -resource or -resourceAtIndex: is called.
131        ///
132        /// Parameter `resourceList`: The list of resources to create.
133        #[unsafe(method(initWithDevice:resourceList:))]
134        #[unsafe(method_family = init)]
135        pub unsafe fn initWithDevice_resourceList(
136            this: Allocated<Self>,
137            device: &ProtocolObject<dyn MTLDevice>,
138            resource_list: &MPSStateResourceList,
139        ) -> Retained<Self>;
140
141        /// Initialize a temporary state to hold a number of textures and buffers
142        ///
143        /// The textures occur first in sequence
144        #[unsafe(method(temporaryStateWithCommandBuffer:resourceList:))]
145        #[unsafe(method_family = none)]
146        pub unsafe fn temporaryStateWithCommandBuffer_resourceList(
147            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
148            resource_list: &MPSStateResourceList,
149        ) -> Retained<Self>;
150
151        /// Create a state object with a list of MTLResources
152        ///
153        /// Because MPS prefers deferred allocation of resources
154        /// your application should use -initWithTextures:bufferSizes:bufferCount:
155        /// whenever possible. This method is useful for cases when the
156        /// MTLResources must be initialized by the CPU.
157        ///
158        /// # Safety
159        ///
160        /// - `resources` generic may need to be synchronized.
161        /// - `resources` generic may be unretained, you must ensure it is kept alive while in use.
162        #[unsafe(method(initWithResources:))]
163        #[unsafe(method_family = init)]
164        pub unsafe fn initWithResources(
165            this: Allocated<Self>,
166            resources: Option<&NSArray<ProtocolObject<dyn MTLResource>>>,
167        ) -> Retained<Self>;
168    );
169}
170
171/// Methods declared on superclass `NSObject`.
172#[cfg(all(
173    feature = "MPSCore",
174    feature = "MPSNNGradientState",
175    feature = "MPSState"
176))]
177impl MPSCNNArithmeticGradientState {
178    extern_methods!(
179        #[unsafe(method(new))]
180        #[unsafe(method_family = new)]
181        pub unsafe fn new() -> Retained<Self>;
182    );
183}
184
185/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnarithmeticgradientstatebatch?language=objc)
186#[cfg(all(
187    feature = "MPSCore",
188    feature = "MPSNNGradientState",
189    feature = "MPSState"
190))]
191pub type MPSCNNArithmeticGradientStateBatch = NSArray<MPSCNNArithmeticGradientState>;
192
193extern_class!(
194    /// Dependencies: This depends on Metal.framework
195    ///
196    /// The MPSCNNArithmetic filter takes two source images, a primary source image and a
197    /// secondary source image, and outputs a single destination image. It applies an
198    /// element-wise arithmetic operator to each pixel in a primary source image and a
199    /// corresponding pixel in a secondary source image over a specified region.
200    ///
201    /// The supported arithmetic operators are the following:
202    /// - Addition
203    /// - Subtraction
204    /// - Multiplication
205    /// - Division
206    /// - Comparison
207    ///
208    /// This filter takes additional parameters: primaryScale, secondaryScale, and bias. The default
209    /// value for primaryScale and secondaryScale is 1.0f. The default value for bias is 0.0f. This
210    /// filter applies primaryScale, secondaryScale, and bias to the primary source pixel (x) and
211    /// secondary source pixel (y) in the following way:
212    /// - Addition:         result = ((primaryScale * x) + (secondaryScale * y)) + bias
213    /// - Subtraction:      result = ((primaryScale * x) - (secondaryScale * y)) + bias
214    /// - Multiplicaton:    result = ((primaryScale * x) * (secondaryScale * y)) + bias
215    /// - Division:         result = ((primaryScale * x) / (secondaryScale * y)) + bias
216    /// - Comparison:       Unused.
217    ///
218    /// To clamp the result of an arithmetic operation, where
219    /// result = clamp(result, minimumValue, maximumValue),
220    /// set the minimumValue and maximumValue appropriately. The default value of minimumValue
221    /// is -FLT_MAX. The default value of maximumValue is FLT_MAX.
222    ///
223    /// This filter also takes the following additional parameters:
224    /// - primaryStrideInPixelsX, primaryStrideInPixelsY, primaryStrideInFeatureChannels
225    /// - secondaryStrideInPixelsX, secondaryStrideInPixelsY, secondaryStrideInFeatureChannels
226    /// These parameters can be used to control broadcasting for the data stored in the primary and
227    /// secondary source images. For example, setting all strides for the primary source image to 0
228    /// will result in the primarySource image being treated as a scalar value. The only supported
229    /// values are 0 or 1. The default value of these parameters is 1.
230    ///
231    /// The number of output feature channels remains the same as the number of input feature
232    /// channels.
233    ///
234    /// You must use one of the sub-classes of MPSImageArithmetic.
235    ///
236    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnarithmetic?language=objc)
237    #[unsafe(super(MPSCNNBinaryKernel, MPSKernel, NSObject))]
238    #[derive(Debug, PartialEq, Eq, Hash)]
239    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
240    pub struct MPSCNNArithmetic;
241);
242
243#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
244extern_conformance!(
245    unsafe impl NSCoding for MPSCNNArithmetic {}
246);
247
248#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
249extern_conformance!(
250    unsafe impl NSCopying for MPSCNNArithmetic {}
251);
252
253#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
254unsafe impl CopyingHelper for MPSCNNArithmetic {
255    type Result = Self;
256}
257
258#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
259extern_conformance!(
260    unsafe impl NSObjectProtocol for MPSCNNArithmetic {}
261);
262
263#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
264extern_conformance!(
265    unsafe impl NSSecureCoding for MPSCNNArithmetic {}
266);
267
268#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
269impl MPSCNNArithmetic {
270    extern_methods!(
271        #[unsafe(method(primaryScale))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn primaryScale(&self) -> c_float;
274
275        /// Setter for [`primaryScale`][Self::primaryScale].
276        #[unsafe(method(setPrimaryScale:))]
277        #[unsafe(method_family = none)]
278        pub unsafe fn setPrimaryScale(&self, primary_scale: c_float);
279
280        #[unsafe(method(secondaryScale))]
281        #[unsafe(method_family = none)]
282        pub unsafe fn secondaryScale(&self) -> c_float;
283
284        /// Setter for [`secondaryScale`][Self::secondaryScale].
285        #[unsafe(method(setSecondaryScale:))]
286        #[unsafe(method_family = none)]
287        pub unsafe fn setSecondaryScale(&self, secondary_scale: c_float);
288
289        #[unsafe(method(bias))]
290        #[unsafe(method_family = none)]
291        pub unsafe fn bias(&self) -> c_float;
292
293        /// Setter for [`bias`][Self::bias].
294        #[unsafe(method(setBias:))]
295        #[unsafe(method_family = none)]
296        pub unsafe fn setBias(&self, bias: c_float);
297
298        /// The primarySource stride in the feature channel dimension. The only supported values are 0 or 1.
299        /// The default value for each dimension is 1.
300        #[unsafe(method(primaryStrideInFeatureChannels))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn primaryStrideInFeatureChannels(&self) -> NSUInteger;
303
304        /// Setter for [`primaryStrideInFeatureChannels`][Self::primaryStrideInFeatureChannels].
305        #[unsafe(method(setPrimaryStrideInFeatureChannels:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn setPrimaryStrideInFeatureChannels(
308            &self,
309            primary_stride_in_feature_channels: NSUInteger,
310        );
311
312        /// The secondarySource stride in the feature channel dimension. The only supported values are 0 or 1.
313        /// The default value for each dimension is 1.
314        #[unsafe(method(secondaryStrideInFeatureChannels))]
315        #[unsafe(method_family = none)]
316        pub unsafe fn secondaryStrideInFeatureChannels(&self) -> NSUInteger;
317
318        /// Setter for [`secondaryStrideInFeatureChannels`][Self::secondaryStrideInFeatureChannels].
319        #[unsafe(method(setSecondaryStrideInFeatureChannels:))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn setSecondaryStrideInFeatureChannels(
322            &self,
323            secondary_stride_in_feature_channels: NSUInteger,
324        );
325
326        /// minimumValue is to clamp the result of an arithmetic operation:
327        /// result = clamp(result, minimumValue, maximumValue).
328        /// The default value of minimumValue is -FLT_MAX.
329        #[unsafe(method(minimumValue))]
330        #[unsafe(method_family = none)]
331        pub unsafe fn minimumValue(&self) -> c_float;
332
333        /// Setter for [`minimumValue`][Self::minimumValue].
334        #[unsafe(method(setMinimumValue:))]
335        #[unsafe(method_family = none)]
336        pub unsafe fn setMinimumValue(&self, minimum_value: c_float);
337
338        /// maximumValue is used to clamp the result of an arithmetic operation:
339        /// result = clamp(result, minimumValue, maximumValue).
340        /// The default value of maximumValue is FLT_MAX.
341        #[unsafe(method(maximumValue))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn maximumValue(&self) -> c_float;
344
345        /// Setter for [`maximumValue`][Self::maximumValue].
346        #[unsafe(method(setMaximumValue:))]
347        #[unsafe(method_family = none)]
348        pub unsafe fn setMaximumValue(&self, maximum_value: c_float);
349
350        #[unsafe(method(initWithDevice:))]
351        #[unsafe(method_family = init)]
352        pub unsafe fn initWithDevice(
353            this: Allocated<Self>,
354            device: &ProtocolObject<dyn MTLDevice>,
355        ) -> Retained<Self>;
356
357        #[cfg(all(
358            feature = "MPSImage",
359            feature = "MPSNNGradientState",
360            feature = "MPSState"
361        ))]
362        /// Encode call that operates on a state for later consumption by a gradient kernel in training
363        ///
364        /// This is the older style of encode which reads the offset, doesn't change it,
365        /// and ignores the padding method.
366        ///
367        /// Parameter `commandBuffer`: The command buffer
368        ///
369        /// Parameter `primaryImage`: A MPSImage to use as the source images for the filter.
370        ///
371        /// Parameter `secondaryImage`: A MPSImage to use as the source images for the filter.
372        ///
373        /// Parameter `destinationState`: MPSCNNArithmeticGradientState to be consumed by the gradient layer
374        ///
375        /// Parameter `destinationImage`: A valid MPSImage to be overwritten by result image. destinationImage
376        /// may not alias primarySourceImage or secondarySourceImage.
377        #[unsafe(method(encodeToCommandBuffer:primaryImage:secondaryImage:destinationState:destinationImage:))]
378        #[unsafe(method_family = none)]
379        pub unsafe fn encodeToCommandBuffer_primaryImage_secondaryImage_destinationState_destinationImage(
380            &self,
381            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
382            primary_image: &MPSImage,
383            secondary_image: &MPSImage,
384            destination_state: &MPSCNNArithmeticGradientState,
385            destination_image: &MPSImage,
386        );
387
388        #[cfg(all(
389            feature = "MPSImage",
390            feature = "MPSNDArray",
391            feature = "MPSNNGradientState",
392            feature = "MPSState"
393        ))]
394        /// Encode call that operates on a state for later consumption by a gradient kernel in training
395        ///
396        /// This is the older style of encode which reads the offset, doesn't change it,
397        /// and ignores the padding method. Multiple images are processed concurrently.
398        /// All images must have MPSImage.numberOfImages = 1.
399        ///
400        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded filter
401        ///
402        /// Parameter `primaryImages`: An array of MPSImage objects containing the primary source images.
403        ///
404        /// Parameter `secondaryImages`: An array MPSImage objects containing the secondary source images.
405        ///
406        /// Parameter `destinationStates`: An array of MPSCNNArithmeticGradientStateBatch to be consumed by the gradient layer
407        ///
408        /// Parameter `destinationImages`: An array of MPSImage objects to contain the result images.
409        /// destinationImages may not alias primarySourceImages or secondarySourceImages
410        /// in any manner.
411        #[unsafe(method(encodeBatchToCommandBuffer:primaryImages:secondaryImages:destinationStates:destinationImages:))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn encodeBatchToCommandBuffer_primaryImages_secondaryImages_destinationStates_destinationImages(
414            &self,
415            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
416            primary_images: &MPSImageBatch,
417            secondary_images: &MPSImageBatch,
418            destination_states: &MPSCNNArithmeticGradientStateBatch,
419            destination_images: &MPSImageBatch,
420        );
421    );
422}
423
424/// Methods declared on superclass `MPSCNNBinaryKernel`.
425#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
426impl MPSCNNArithmetic {
427    extern_methods!(
428        /// NSSecureCoding compatability
429        ///
430        /// While the standard NSSecureCoding/NSCoding method
431        /// -initWithCoder: should work, since the file can't
432        /// know which device your data is allocated on, we
433        /// have to guess and may guess incorrectly.  To avoid
434        /// that problem, use initWithCoder:device instead.
435        ///
436        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
437        ///
438        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
439        ///
440        /// Returns: A new MPSKernel object, or nil if failure.
441        ///
442        /// # Safety
443        ///
444        /// `a_decoder` possibly has further requirements.
445        #[unsafe(method(initWithCoder:device:))]
446        #[unsafe(method_family = init)]
447        pub unsafe fn initWithCoder_device(
448            this: Allocated<Self>,
449            a_decoder: &NSCoder,
450            device: &ProtocolObject<dyn MTLDevice>,
451        ) -> Option<Retained<Self>>;
452    );
453}
454
455/// Methods declared on superclass `MPSKernel`.
456#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
457impl MPSCNNArithmetic {
458    extern_methods!(
459        /// Called by NSCoder to decode MPSKernels
460        ///
461        /// This isn't the right interface to decode a MPSKernel, but
462        /// it is the one that NSCoder uses. To enable your NSCoder
463        /// (e.g. NSKeyedUnarchiver) to set which device to use
464        /// extend the object to adopt the MPSDeviceProvider
465        /// protocol. Otherwise, the Metal system default device
466        /// will be used.
467        ///
468        /// # Safety
469        ///
470        /// `a_decoder` possibly has further requirements.
471        #[unsafe(method(initWithCoder:))]
472        #[unsafe(method_family = init)]
473        pub unsafe fn initWithCoder(
474            this: Allocated<Self>,
475            a_decoder: &NSCoder,
476        ) -> Option<Retained<Self>>;
477    );
478}
479
480/// Methods declared on superclass `NSObject`.
481#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
482impl MPSCNNArithmetic {
483    extern_methods!(
484        #[unsafe(method(init))]
485        #[unsafe(method_family = init)]
486        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
487
488        #[unsafe(method(new))]
489        #[unsafe(method_family = new)]
490        pub unsafe fn new() -> Retained<Self>;
491    );
492}
493
494extern_class!(
495    /// Dependencies: This depends on Metal.framework.
496    ///
497    /// Specifies the addition operator.
498    /// For each pixel in the primary source image (x) and each pixel in a secondary source image (y),
499    /// it applies the following function: result = ((primaryScale * x) + (secondaryScale * y)) + bias.
500    ///
501    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnadd?language=objc)
502    #[unsafe(super(MPSCNNArithmetic, MPSCNNBinaryKernel, MPSKernel, NSObject))]
503    #[derive(Debug, PartialEq, Eq, Hash)]
504    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
505    pub struct MPSCNNAdd;
506);
507
508#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
509extern_conformance!(
510    unsafe impl NSCoding for MPSCNNAdd {}
511);
512
513#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
514extern_conformance!(
515    unsafe impl NSCopying for MPSCNNAdd {}
516);
517
518#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
519unsafe impl CopyingHelper for MPSCNNAdd {
520    type Result = Self;
521}
522
523#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
524extern_conformance!(
525    unsafe impl NSObjectProtocol for MPSCNNAdd {}
526);
527
528#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
529extern_conformance!(
530    unsafe impl NSSecureCoding for MPSCNNAdd {}
531);
532
533#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
534impl MPSCNNAdd {
535    extern_methods!(
536        /// Initialize the addition operator.
537        ///
538        /// Parameter `device`: The device the filter will run on.
539        ///
540        /// Returns: A valid MPSCNNAdd object or nil, if failure.
541        #[unsafe(method(initWithDevice:))]
542        #[unsafe(method_family = init)]
543        pub unsafe fn initWithDevice(
544            this: Allocated<Self>,
545            device: &ProtocolObject<dyn MTLDevice>,
546        ) -> Retained<Self>;
547    );
548}
549
550/// Methods declared on superclass `MPSCNNBinaryKernel`.
551#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
552impl MPSCNNAdd {
553    extern_methods!(
554        /// NSSecureCoding compatability
555        ///
556        /// While the standard NSSecureCoding/NSCoding method
557        /// -initWithCoder: should work, since the file can't
558        /// know which device your data is allocated on, we
559        /// have to guess and may guess incorrectly.  To avoid
560        /// that problem, use initWithCoder:device instead.
561        ///
562        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
563        ///
564        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
565        ///
566        /// Returns: A new MPSKernel object, or nil if failure.
567        ///
568        /// # Safety
569        ///
570        /// `a_decoder` possibly has further requirements.
571        #[unsafe(method(initWithCoder:device:))]
572        #[unsafe(method_family = init)]
573        pub unsafe fn initWithCoder_device(
574            this: Allocated<Self>,
575            a_decoder: &NSCoder,
576            device: &ProtocolObject<dyn MTLDevice>,
577        ) -> Option<Retained<Self>>;
578    );
579}
580
581/// Methods declared on superclass `MPSKernel`.
582#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
583impl MPSCNNAdd {
584    extern_methods!(
585        /// Called by NSCoder to decode MPSKernels
586        ///
587        /// This isn't the right interface to decode a MPSKernel, but
588        /// it is the one that NSCoder uses. To enable your NSCoder
589        /// (e.g. NSKeyedUnarchiver) to set which device to use
590        /// extend the object to adopt the MPSDeviceProvider
591        /// protocol. Otherwise, the Metal system default device
592        /// will be used.
593        ///
594        /// # Safety
595        ///
596        /// `a_decoder` possibly has further requirements.
597        #[unsafe(method(initWithCoder:))]
598        #[unsafe(method_family = init)]
599        pub unsafe fn initWithCoder(
600            this: Allocated<Self>,
601            a_decoder: &NSCoder,
602        ) -> Option<Retained<Self>>;
603    );
604}
605
606/// Methods declared on superclass `NSObject`.
607#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
608impl MPSCNNAdd {
609    extern_methods!(
610        #[unsafe(method(init))]
611        #[unsafe(method_family = init)]
612        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
613
614        #[unsafe(method(new))]
615        #[unsafe(method_family = new)]
616        pub unsafe fn new() -> Retained<Self>;
617    );
618}
619
620extern_class!(
621    /// Dependencies: This depends on Metal.framework.
622    ///
623    /// Specifies the subtraction operator.
624    /// For each pixel in the primary source image (x) and each pixel in a secondary source image (y),
625    /// it applies the following function: result = ((primaryScale * x) - (secondaryScale * y)) + bias.
626    ///
627    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnsubtract?language=objc)
628    #[unsafe(super(MPSCNNArithmetic, MPSCNNBinaryKernel, MPSKernel, NSObject))]
629    #[derive(Debug, PartialEq, Eq, Hash)]
630    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
631    pub struct MPSCNNSubtract;
632);
633
634#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
635extern_conformance!(
636    unsafe impl NSCoding for MPSCNNSubtract {}
637);
638
639#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
640extern_conformance!(
641    unsafe impl NSCopying for MPSCNNSubtract {}
642);
643
644#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
645unsafe impl CopyingHelper for MPSCNNSubtract {
646    type Result = Self;
647}
648
649#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
650extern_conformance!(
651    unsafe impl NSObjectProtocol for MPSCNNSubtract {}
652);
653
654#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
655extern_conformance!(
656    unsafe impl NSSecureCoding for MPSCNNSubtract {}
657);
658
659#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
660impl MPSCNNSubtract {
661    extern_methods!(
662        /// Initialize the subtraction operator
663        ///
664        /// Parameter `device`: The device the filter will run on.
665        ///
666        /// Returns: A valid MPSCNNSubtract object or nil, if failure.
667        #[unsafe(method(initWithDevice:))]
668        #[unsafe(method_family = init)]
669        pub unsafe fn initWithDevice(
670            this: Allocated<Self>,
671            device: &ProtocolObject<dyn MTLDevice>,
672        ) -> Retained<Self>;
673    );
674}
675
676/// Methods declared on superclass `MPSCNNBinaryKernel`.
677#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
678impl MPSCNNSubtract {
679    extern_methods!(
680        /// NSSecureCoding compatability
681        ///
682        /// While the standard NSSecureCoding/NSCoding method
683        /// -initWithCoder: should work, since the file can't
684        /// know which device your data is allocated on, we
685        /// have to guess and may guess incorrectly.  To avoid
686        /// that problem, use initWithCoder:device instead.
687        ///
688        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
689        ///
690        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
691        ///
692        /// Returns: A new MPSKernel object, or nil if failure.
693        ///
694        /// # Safety
695        ///
696        /// `a_decoder` possibly has further requirements.
697        #[unsafe(method(initWithCoder:device:))]
698        #[unsafe(method_family = init)]
699        pub unsafe fn initWithCoder_device(
700            this: Allocated<Self>,
701            a_decoder: &NSCoder,
702            device: &ProtocolObject<dyn MTLDevice>,
703        ) -> Option<Retained<Self>>;
704    );
705}
706
707/// Methods declared on superclass `MPSKernel`.
708#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
709impl MPSCNNSubtract {
710    extern_methods!(
711        /// Called by NSCoder to decode MPSKernels
712        ///
713        /// This isn't the right interface to decode a MPSKernel, but
714        /// it is the one that NSCoder uses. To enable your NSCoder
715        /// (e.g. NSKeyedUnarchiver) to set which device to use
716        /// extend the object to adopt the MPSDeviceProvider
717        /// protocol. Otherwise, the Metal system default device
718        /// will be used.
719        ///
720        /// # Safety
721        ///
722        /// `a_decoder` possibly has further requirements.
723        #[unsafe(method(initWithCoder:))]
724        #[unsafe(method_family = init)]
725        pub unsafe fn initWithCoder(
726            this: Allocated<Self>,
727            a_decoder: &NSCoder,
728        ) -> Option<Retained<Self>>;
729    );
730}
731
732/// Methods declared on superclass `NSObject`.
733#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
734impl MPSCNNSubtract {
735    extern_methods!(
736        #[unsafe(method(init))]
737        #[unsafe(method_family = init)]
738        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
739
740        #[unsafe(method(new))]
741        #[unsafe(method_family = new)]
742        pub unsafe fn new() -> Retained<Self>;
743    );
744}
745
746extern_class!(
747    /// Dependencies: This depends on Metal.framework.
748    ///
749    /// Specifies the multiplication operator.
750    /// For each pixel in the primary source image (x) and each pixel in a secondary source image (y),
751    /// it applies the following function: result = ((primaryScale * x) * (secondaryScale * y)) + bias.
752    ///
753    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnmultiply?language=objc)
754    #[unsafe(super(MPSCNNArithmetic, MPSCNNBinaryKernel, MPSKernel, NSObject))]
755    #[derive(Debug, PartialEq, Eq, Hash)]
756    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
757    pub struct MPSCNNMultiply;
758);
759
760#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
761extern_conformance!(
762    unsafe impl NSCoding for MPSCNNMultiply {}
763);
764
765#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
766extern_conformance!(
767    unsafe impl NSCopying for MPSCNNMultiply {}
768);
769
770#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
771unsafe impl CopyingHelper for MPSCNNMultiply {
772    type Result = Self;
773}
774
775#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
776extern_conformance!(
777    unsafe impl NSObjectProtocol for MPSCNNMultiply {}
778);
779
780#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
781extern_conformance!(
782    unsafe impl NSSecureCoding for MPSCNNMultiply {}
783);
784
785#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
786impl MPSCNNMultiply {
787    extern_methods!(
788        /// Initialize the multiplication operator
789        ///
790        /// Parameter `device`: The device the filter will run on.
791        ///
792        /// Returns: A valid MPSCNNMultiply object or nil, if failure.
793        #[unsafe(method(initWithDevice:))]
794        #[unsafe(method_family = init)]
795        pub unsafe fn initWithDevice(
796            this: Allocated<Self>,
797            device: &ProtocolObject<dyn MTLDevice>,
798        ) -> Retained<Self>;
799    );
800}
801
802/// Methods declared on superclass `MPSCNNBinaryKernel`.
803#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
804impl MPSCNNMultiply {
805    extern_methods!(
806        /// NSSecureCoding compatability
807        ///
808        /// While the standard NSSecureCoding/NSCoding method
809        /// -initWithCoder: should work, since the file can't
810        /// know which device your data is allocated on, we
811        /// have to guess and may guess incorrectly.  To avoid
812        /// that problem, use initWithCoder:device instead.
813        ///
814        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
815        ///
816        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
817        ///
818        /// Returns: A new MPSKernel object, or nil if failure.
819        ///
820        /// # Safety
821        ///
822        /// `a_decoder` possibly has further requirements.
823        #[unsafe(method(initWithCoder:device:))]
824        #[unsafe(method_family = init)]
825        pub unsafe fn initWithCoder_device(
826            this: Allocated<Self>,
827            a_decoder: &NSCoder,
828            device: &ProtocolObject<dyn MTLDevice>,
829        ) -> Option<Retained<Self>>;
830    );
831}
832
833/// Methods declared on superclass `MPSKernel`.
834#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
835impl MPSCNNMultiply {
836    extern_methods!(
837        /// Called by NSCoder to decode MPSKernels
838        ///
839        /// This isn't the right interface to decode a MPSKernel, but
840        /// it is the one that NSCoder uses. To enable your NSCoder
841        /// (e.g. NSKeyedUnarchiver) to set which device to use
842        /// extend the object to adopt the MPSDeviceProvider
843        /// protocol. Otherwise, the Metal system default device
844        /// will be used.
845        ///
846        /// # Safety
847        ///
848        /// `a_decoder` possibly has further requirements.
849        #[unsafe(method(initWithCoder:))]
850        #[unsafe(method_family = init)]
851        pub unsafe fn initWithCoder(
852            this: Allocated<Self>,
853            a_decoder: &NSCoder,
854        ) -> Option<Retained<Self>>;
855    );
856}
857
858/// Methods declared on superclass `NSObject`.
859#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
860impl MPSCNNMultiply {
861    extern_methods!(
862        #[unsafe(method(init))]
863        #[unsafe(method_family = init)]
864        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
865
866        #[unsafe(method(new))]
867        #[unsafe(method_family = new)]
868        pub unsafe fn new() -> Retained<Self>;
869    );
870}
871
872extern_class!(
873    /// Dependencies: This depends on Metal.framework.
874    ///
875    /// Specifies the division operator.
876    /// For each pixel in the primary source image (x) and each pixel in a secondary source image (y),
877    /// it applies the following function: result = ((primaryScale * x) / (secondaryScale * y)) + bias.
878    ///
879    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnndivide?language=objc)
880    #[unsafe(super(MPSCNNArithmetic, MPSCNNBinaryKernel, MPSKernel, NSObject))]
881    #[derive(Debug, PartialEq, Eq, Hash)]
882    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
883    pub struct MPSCNNDivide;
884);
885
886#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
887extern_conformance!(
888    unsafe impl NSCoding for MPSCNNDivide {}
889);
890
891#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
892extern_conformance!(
893    unsafe impl NSCopying for MPSCNNDivide {}
894);
895
896#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
897unsafe impl CopyingHelper for MPSCNNDivide {
898    type Result = Self;
899}
900
901#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
902extern_conformance!(
903    unsafe impl NSObjectProtocol for MPSCNNDivide {}
904);
905
906#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
907extern_conformance!(
908    unsafe impl NSSecureCoding for MPSCNNDivide {}
909);
910
911#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
912impl MPSCNNDivide {
913    extern_methods!(
914        /// Initialize the division operator
915        ///
916        /// Parameter `device`: The device the filter will run on.
917        ///
918        /// Returns: A valid MPSCNNDivide object or nil, if failure.
919        #[unsafe(method(initWithDevice:))]
920        #[unsafe(method_family = init)]
921        pub unsafe fn initWithDevice(
922            this: Allocated<Self>,
923            device: &ProtocolObject<dyn MTLDevice>,
924        ) -> Retained<Self>;
925    );
926}
927
928/// Methods declared on superclass `MPSCNNBinaryKernel`.
929#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
930impl MPSCNNDivide {
931    extern_methods!(
932        /// NSSecureCoding compatability
933        ///
934        /// While the standard NSSecureCoding/NSCoding method
935        /// -initWithCoder: should work, since the file can't
936        /// know which device your data is allocated on, we
937        /// have to guess and may guess incorrectly.  To avoid
938        /// that problem, use initWithCoder:device instead.
939        ///
940        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
941        ///
942        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
943        ///
944        /// Returns: A new MPSKernel object, or nil if failure.
945        ///
946        /// # Safety
947        ///
948        /// `a_decoder` possibly has further requirements.
949        #[unsafe(method(initWithCoder:device:))]
950        #[unsafe(method_family = init)]
951        pub unsafe fn initWithCoder_device(
952            this: Allocated<Self>,
953            a_decoder: &NSCoder,
954            device: &ProtocolObject<dyn MTLDevice>,
955        ) -> Option<Retained<Self>>;
956    );
957}
958
959/// Methods declared on superclass `MPSKernel`.
960#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
961impl MPSCNNDivide {
962    extern_methods!(
963        /// Called by NSCoder to decode MPSKernels
964        ///
965        /// This isn't the right interface to decode a MPSKernel, but
966        /// it is the one that NSCoder uses. To enable your NSCoder
967        /// (e.g. NSKeyedUnarchiver) to set which device to use
968        /// extend the object to adopt the MPSDeviceProvider
969        /// protocol. Otherwise, the Metal system default device
970        /// will be used.
971        ///
972        /// # Safety
973        ///
974        /// `a_decoder` possibly has further requirements.
975        #[unsafe(method(initWithCoder:))]
976        #[unsafe(method_family = init)]
977        pub unsafe fn initWithCoder(
978            this: Allocated<Self>,
979            a_decoder: &NSCoder,
980        ) -> Option<Retained<Self>>;
981    );
982}
983
984/// Methods declared on superclass `NSObject`.
985#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
986impl MPSCNNDivide {
987    extern_methods!(
988        #[unsafe(method(init))]
989        #[unsafe(method_family = init)]
990        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
991
992        #[unsafe(method(new))]
993        #[unsafe(method_family = new)]
994        pub unsafe fn new() -> Retained<Self>;
995    );
996}
997
998/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnncomparisontype?language=objc)
999// NS_OPTIONS
1000#[repr(transparent)]
1001#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1002pub struct MPSNNComparisonType(pub NSUInteger);
1003bitflags::bitflags! {
1004    impl MPSNNComparisonType: NSUInteger {
1005        #[doc(alias = "MPSNNComparisonTypeEqual")]
1006        const Equal = 0;
1007        #[doc(alias = "MPSNNComparisonTypeNotEqual")]
1008        const NotEqual = 1;
1009        #[doc(alias = "MPSNNComparisonTypeLess")]
1010        const Less = 2;
1011        #[doc(alias = "MPSNNComparisonTypeLessOrEqual")]
1012        const LessOrEqual = 3;
1013        #[doc(alias = "MPSNNComparisonTypeGreater")]
1014        const Greater = 4;
1015        #[doc(alias = "MPSNNComparisonTypeGreaterOrEqual")]
1016        const GreaterOrEqual = 5;
1017    }
1018}
1019
1020unsafe impl Encode for MPSNNComparisonType {
1021    const ENCODING: Encoding = NSUInteger::ENCODING;
1022}
1023
1024unsafe impl RefEncode for MPSNNComparisonType {
1025    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
1026}
1027
1028extern_class!(
1029    /// Dependencies: This depends on Metal.framework.
1030    ///
1031    /// Specifies the elementwise comparison operator.
1032    /// For each pixel in the primary source image (x) and each pixel in a secondary source image (y),
1033    /// it applies the following function: result = (abs(x-y))
1034    /// <
1035    /// = threshold
1036    ///
1037    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsnncompare?language=objc)
1038    #[unsafe(super(MPSCNNArithmetic, MPSCNNBinaryKernel, MPSKernel, NSObject))]
1039    #[derive(Debug, PartialEq, Eq, Hash)]
1040    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1041    pub struct MPSNNCompare;
1042);
1043
1044#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1045extern_conformance!(
1046    unsafe impl NSCoding for MPSNNCompare {}
1047);
1048
1049#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1050extern_conformance!(
1051    unsafe impl NSCopying for MPSNNCompare {}
1052);
1053
1054#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1055unsafe impl CopyingHelper for MPSNNCompare {
1056    type Result = Self;
1057}
1058
1059#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1060extern_conformance!(
1061    unsafe impl NSObjectProtocol for MPSNNCompare {}
1062);
1063
1064#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1065extern_conformance!(
1066    unsafe impl NSSecureCoding for MPSNNCompare {}
1067);
1068
1069#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1070impl MPSNNCompare {
1071    extern_methods!(
1072        /// The comparison type to use
1073        #[unsafe(method(comparisonType))]
1074        #[unsafe(method_family = none)]
1075        pub unsafe fn comparisonType(&self) -> MPSNNComparisonType;
1076
1077        /// Setter for [`comparisonType`][Self::comparisonType].
1078        #[unsafe(method(setComparisonType:))]
1079        #[unsafe(method_family = none)]
1080        pub unsafe fn setComparisonType(&self, comparison_type: MPSNNComparisonType);
1081
1082        /// The threshold to use when comparing for equality.  Two values will
1083        /// be considered to be equal if the absolute value of their difference
1084        /// is less than, or equal, to the specified threshold:
1085        /// result = |b - a|
1086        /// <
1087        /// = threshold
1088        #[unsafe(method(threshold))]
1089        #[unsafe(method_family = none)]
1090        pub unsafe fn threshold(&self) -> c_float;
1091
1092        /// Setter for [`threshold`][Self::threshold].
1093        #[unsafe(method(setThreshold:))]
1094        #[unsafe(method_family = none)]
1095        pub unsafe fn setThreshold(&self, threshold: c_float);
1096
1097        /// Initialize the comparison operator
1098        ///
1099        /// Parameter `device`: The device the filter will run on.
1100        ///
1101        /// Returns: A valid MPSNNCompare object or nil, if failure.
1102        #[unsafe(method(initWithDevice:))]
1103        #[unsafe(method_family = init)]
1104        pub unsafe fn initWithDevice(
1105            this: Allocated<Self>,
1106            device: &ProtocolObject<dyn MTLDevice>,
1107        ) -> Retained<Self>;
1108    );
1109}
1110
1111/// Methods declared on superclass `MPSCNNBinaryKernel`.
1112#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1113impl MPSNNCompare {
1114    extern_methods!(
1115        /// NSSecureCoding compatability
1116        ///
1117        /// While the standard NSSecureCoding/NSCoding method
1118        /// -initWithCoder: should work, since the file can't
1119        /// know which device your data is allocated on, we
1120        /// have to guess and may guess incorrectly.  To avoid
1121        /// that problem, use initWithCoder:device instead.
1122        ///
1123        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1124        ///
1125        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1126        ///
1127        /// Returns: A new MPSKernel object, or nil if failure.
1128        ///
1129        /// # Safety
1130        ///
1131        /// `a_decoder` possibly has further requirements.
1132        #[unsafe(method(initWithCoder:device:))]
1133        #[unsafe(method_family = init)]
1134        pub unsafe fn initWithCoder_device(
1135            this: Allocated<Self>,
1136            a_decoder: &NSCoder,
1137            device: &ProtocolObject<dyn MTLDevice>,
1138        ) -> Option<Retained<Self>>;
1139    );
1140}
1141
1142/// Methods declared on superclass `MPSKernel`.
1143#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1144impl MPSNNCompare {
1145    extern_methods!(
1146        /// Called by NSCoder to decode MPSKernels
1147        ///
1148        /// This isn't the right interface to decode a MPSKernel, but
1149        /// it is the one that NSCoder uses. To enable your NSCoder
1150        /// (e.g. NSKeyedUnarchiver) to set which device to use
1151        /// extend the object to adopt the MPSDeviceProvider
1152        /// protocol. Otherwise, the Metal system default device
1153        /// will be used.
1154        ///
1155        /// # Safety
1156        ///
1157        /// `a_decoder` possibly has further requirements.
1158        #[unsafe(method(initWithCoder:))]
1159        #[unsafe(method_family = init)]
1160        pub unsafe fn initWithCoder(
1161            this: Allocated<Self>,
1162            a_decoder: &NSCoder,
1163        ) -> Option<Retained<Self>>;
1164    );
1165}
1166
1167/// Methods declared on superclass `NSObject`.
1168#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1169impl MPSNNCompare {
1170    extern_methods!(
1171        #[unsafe(method(init))]
1172        #[unsafe(method_family = init)]
1173        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1174
1175        #[unsafe(method(new))]
1176        #[unsafe(method_family = new)]
1177        pub unsafe fn new() -> Retained<Self>;
1178    );
1179}
1180
1181extern_class!(
1182    /// Dependencies: This depends on Metal.framework
1183    ///
1184    /// The MPSCNNArithmeticGradient filter is the backward filter for the MPSCNNArithmetic
1185    /// forward filter.
1186    ///
1187    /// The forward filter takes two inputs, primary and secondary source images, and produces
1188    /// a single output image. Thus, going backwards requires two separate filters (one for
1189    /// the primary source image and one for the secondary source image) that take multiple
1190    /// inputs and produce a single output. The secondarySourceFilter property is used to
1191    /// indicate whether the filter is operating on the primary or secondary source image from
1192    /// the forward pass.
1193    ///
1194    /// All the arithmetic gradient filters require the following inputs: gradient image from
1195    /// the previous layer (going backwards) and all the applicable input source images from
1196    /// the forward pass.
1197    ///
1198    /// The forward filter takes the following additional parameters:
1199    /// - primaryStrideInPixelsX, primaryStrideInPixelsY, primaryStrideInFeatureChannels
1200    /// - secondaryStrideInPixelsX, secondaryStrideInPixelsY, secondaryStrideInFeatureChannels
1201    /// These parameters can be used in the forward filter to control broadcasting for the data
1202    /// stored in the primary and secondary source images. For example, setting all strides for
1203    /// the primary source image to 0 will result in the primarySource image being treated as a
1204    /// single pixel. The only supported values are 0 or 1. The default value of these parameters
1205    /// is 1.
1206    ///
1207    /// The first input to the backward filter is the gradient image from the previous layer
1208    /// (going backwards), so there are no broadcasting parameters for this input. For the
1209    /// backward filter, the broadcasting parameters for the second input must match the
1210    /// broadcasting parameters set for the same image in the forward filter.
1211    ///
1212    /// In the backward pass, broadcasting results in a reduction operation (sum) across all of the
1213    /// applicable broadcasting dimensions (rows, columns, feature channels, or any combination
1214    /// thereof) to produce the destination image of the size that matches the primary/secondary
1215    /// input images used in the forward pass.
1216    ///
1217    /// In the case of no broadcasting, the following arithmetic gradient operations are copy
1218    /// operations (that can be optimized away by the graph interface):
1219    /// - Add (primarySource, secondarySource)
1220    /// - Subtract (primarySource)
1221    ///
1222    /// Similarly to the forward filter, this backward filter takes additional parameters:
1223    /// primaryScale, secondaryScale, and bias. The default value for primaryScale and secondaryScale
1224    /// is 1.0f. The default value for bias is 0.0f. This filter applies primaryScale to the primary
1225    /// source image, applies the secondaryScale to the secondary source image, where appropriate,
1226    /// and applies bias to the result, i.e.:
1227    /// result = ((primaryScale * x) [insert operation] (secondaryScale * y)) + bias.
1228    ///
1229    /// The subtraction gradient filter for the secondary source image requires that the primaryScale
1230    /// property is set to -1.0f (for x - y, d/dy(x - y) = -1).
1231    ///
1232    /// In the forward filter, there is support for clamping the result of the available operations,
1233    /// where result = clamp(result, minimumValue, maximumValue). The clamp backward operation is
1234    /// not supported in the arithmetic gradient filters. If you require this functionality, it can
1235    /// be implemented by performing a clamp backward operation before calling the arithmetic gradient
1236    /// filters. You would need to apply the following function on the incomping gradient input image:
1237    /// f(x) = ((minimumValue
1238    /// <
1239    /// x)
1240    /// &
1241    /// &
1242    /// (x
1243    /// <
1244    /// maximumValue)) ? 1 : 0, where x is the original result
1245    /// (before clamping) of the forward arithmetic filter.
1246    ///
1247    /// The number of output feature channels remains the same as the number of input feature
1248    /// channels.
1249    ///
1250    /// You must use one of the sub-classes of MPSImageArithmeticGradient.
1251    ///
1252    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnarithmeticgradient?language=objc)
1253    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
1254    #[derive(Debug, PartialEq, Eq, Hash)]
1255    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1256    pub struct MPSCNNArithmeticGradient;
1257);
1258
1259#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1260extern_conformance!(
1261    unsafe impl NSCoding for MPSCNNArithmeticGradient {}
1262);
1263
1264#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1265extern_conformance!(
1266    unsafe impl NSCopying for MPSCNNArithmeticGradient {}
1267);
1268
1269#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1270unsafe impl CopyingHelper for MPSCNNArithmeticGradient {
1271    type Result = Self;
1272}
1273
1274#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1275extern_conformance!(
1276    unsafe impl NSObjectProtocol for MPSCNNArithmeticGradient {}
1277);
1278
1279#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1280extern_conformance!(
1281    unsafe impl NSSecureCoding for MPSCNNArithmeticGradient {}
1282);
1283
1284#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1285impl MPSCNNArithmeticGradient {
1286    extern_methods!(
1287        #[unsafe(method(primaryScale))]
1288        #[unsafe(method_family = none)]
1289        pub unsafe fn primaryScale(&self) -> c_float;
1290
1291        /// Setter for [`primaryScale`][Self::primaryScale].
1292        #[unsafe(method(setPrimaryScale:))]
1293        #[unsafe(method_family = none)]
1294        pub unsafe fn setPrimaryScale(&self, primary_scale: c_float);
1295
1296        #[unsafe(method(secondaryScale))]
1297        #[unsafe(method_family = none)]
1298        pub unsafe fn secondaryScale(&self) -> c_float;
1299
1300        /// Setter for [`secondaryScale`][Self::secondaryScale].
1301        #[unsafe(method(setSecondaryScale:))]
1302        #[unsafe(method_family = none)]
1303        pub unsafe fn setSecondaryScale(&self, secondary_scale: c_float);
1304
1305        #[unsafe(method(bias))]
1306        #[unsafe(method_family = none)]
1307        pub unsafe fn bias(&self) -> c_float;
1308
1309        /// Setter for [`bias`][Self::bias].
1310        #[unsafe(method(setBias:))]
1311        #[unsafe(method_family = none)]
1312        pub unsafe fn setBias(&self, bias: c_float);
1313
1314        /// The secondarySource stride in the feature channel dimension. The only supported values are 0 or 1.
1315        /// The default value for each dimension is 1.
1316        #[unsafe(method(secondaryStrideInFeatureChannels))]
1317        #[unsafe(method_family = none)]
1318        pub unsafe fn secondaryStrideInFeatureChannels(&self) -> NSUInteger;
1319
1320        /// Setter for [`secondaryStrideInFeatureChannels`][Self::secondaryStrideInFeatureChannels].
1321        #[unsafe(method(setSecondaryStrideInFeatureChannels:))]
1322        #[unsafe(method_family = none)]
1323        pub unsafe fn setSecondaryStrideInFeatureChannels(
1324            &self,
1325            secondary_stride_in_feature_channels: NSUInteger,
1326        );
1327
1328        /// minimumValue is to clamp the result of an arithmetic operation:
1329        /// result = clamp(result, minimumValue, maximumValue).
1330        /// The default value of minimumValue is -FLT_MAX.
1331        #[unsafe(method(minimumValue))]
1332        #[unsafe(method_family = none)]
1333        pub unsafe fn minimumValue(&self) -> c_float;
1334
1335        /// Setter for [`minimumValue`][Self::minimumValue].
1336        #[unsafe(method(setMinimumValue:))]
1337        #[unsafe(method_family = none)]
1338        pub unsafe fn setMinimumValue(&self, minimum_value: c_float);
1339
1340        /// maximumValue is used to clamp the result of an arithmetic operation:
1341        /// result = clamp(result, minimumValue, maximumValue).
1342        /// The default value of maximumValue is FLT_MAX.
1343        #[unsafe(method(maximumValue))]
1344        #[unsafe(method_family = none)]
1345        pub unsafe fn maximumValue(&self) -> c_float;
1346
1347        /// Setter for [`maximumValue`][Self::maximumValue].
1348        #[unsafe(method(setMaximumValue:))]
1349        #[unsafe(method_family = none)]
1350        pub unsafe fn setMaximumValue(&self, maximum_value: c_float);
1351
1352        /// The isSecondarySourceFilter property is used to indicate whether the arithmetic gradient
1353        /// filter is operating on the primary or secondary source image from the forward pass.
1354        #[unsafe(method(isSecondarySourceFilter))]
1355        #[unsafe(method_family = none)]
1356        pub unsafe fn isSecondarySourceFilter(&self) -> bool;
1357
1358        #[unsafe(method(initWithDevice:))]
1359        #[unsafe(method_family = init)]
1360        pub unsafe fn initWithDevice(
1361            this: Allocated<Self>,
1362            device: &ProtocolObject<dyn MTLDevice>,
1363        ) -> Retained<Self>;
1364
1365        #[unsafe(method(initWithDevice:isSecondarySourceFilter:))]
1366        #[unsafe(method_family = init)]
1367        pub unsafe fn initWithDevice_isSecondarySourceFilter(
1368            this: Allocated<Self>,
1369            device: &ProtocolObject<dyn MTLDevice>,
1370            is_secondary_source_filter: bool,
1371        ) -> Retained<Self>;
1372    );
1373}
1374
1375/// Methods declared on superclass `MPSCNNGradientKernel`.
1376#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1377impl MPSCNNArithmeticGradient {
1378    extern_methods!(
1379        /// NSSecureCoding compatability
1380        ///
1381        /// While the standard NSSecureCoding/NSCoding method
1382        /// -initWithCoder: should work, since the file can't
1383        /// know which device your data is allocated on, we
1384        /// have to guess and may guess incorrectly.  To avoid
1385        /// that problem, use initWithCoder:device instead.
1386        ///
1387        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1388        ///
1389        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1390        ///
1391        /// Returns: A new MPSKernel object, or nil if failure.
1392        ///
1393        /// # Safety
1394        ///
1395        /// `a_decoder` possibly has further requirements.
1396        #[unsafe(method(initWithCoder:device:))]
1397        #[unsafe(method_family = init)]
1398        pub unsafe fn initWithCoder_device(
1399            this: Allocated<Self>,
1400            a_decoder: &NSCoder,
1401            device: &ProtocolObject<dyn MTLDevice>,
1402        ) -> Option<Retained<Self>>;
1403    );
1404}
1405
1406/// Methods declared on superclass `MPSKernel`.
1407#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1408impl MPSCNNArithmeticGradient {
1409    extern_methods!(
1410        /// Called by NSCoder to decode MPSKernels
1411        ///
1412        /// This isn't the right interface to decode a MPSKernel, but
1413        /// it is the one that NSCoder uses. To enable your NSCoder
1414        /// (e.g. NSKeyedUnarchiver) to set which device to use
1415        /// extend the object to adopt the MPSDeviceProvider
1416        /// protocol. Otherwise, the Metal system default device
1417        /// will be used.
1418        ///
1419        /// # Safety
1420        ///
1421        /// `a_decoder` possibly has further requirements.
1422        #[unsafe(method(initWithCoder:))]
1423        #[unsafe(method_family = init)]
1424        pub unsafe fn initWithCoder(
1425            this: Allocated<Self>,
1426            a_decoder: &NSCoder,
1427        ) -> Option<Retained<Self>>;
1428    );
1429}
1430
1431/// Methods declared on superclass `NSObject`.
1432#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1433impl MPSCNNArithmeticGradient {
1434    extern_methods!(
1435        #[unsafe(method(init))]
1436        #[unsafe(method_family = init)]
1437        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1438
1439        #[unsafe(method(new))]
1440        #[unsafe(method_family = new)]
1441        pub unsafe fn new() -> Retained<Self>;
1442    );
1443}
1444
1445extern_class!(
1446    /// Dependencies: This depends on Metal.framework.
1447    ///
1448    /// Specifies the addition gradient operator.
1449    /// This arithmetic gradient filter requires the following inputs: gradient image from
1450    /// the previous layer (going backwards) and either the primary or the secondary source
1451    /// image from the forward pass. You will need a separate filter for the primary and
1452    /// secondary source images.
1453    ///
1454    /// Without broadcasting, the arithmetic add gradient operation is a copy operation on
1455    /// the input gradient image. It is the same operation for both the primary and secondary
1456    /// source images (for x + y, d/dx(x + y) = 1, d/dy(x + y) = 1). This copy operation can
1457    /// be optimized away by the graph interface.
1458    ///
1459    /// Setting the broadcasting parameters results in a reduction operation (sum) across all
1460    /// of the applicable broadcasting dimensions (rows, columns, feature channels, or any
1461    /// combination thereof) to produce the destination image of the size that matches the
1462    /// primary/secondary input images used in the forward pass.
1463    ///
1464    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnaddgradient?language=objc)
1465    #[unsafe(super(
1466        MPSCNNArithmeticGradient,
1467        MPSCNNGradientKernel,
1468        MPSCNNBinaryKernel,
1469        MPSKernel,
1470        NSObject
1471    ))]
1472    #[derive(Debug, PartialEq, Eq, Hash)]
1473    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1474    pub struct MPSCNNAddGradient;
1475);
1476
1477#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1478extern_conformance!(
1479    unsafe impl NSCoding for MPSCNNAddGradient {}
1480);
1481
1482#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1483extern_conformance!(
1484    unsafe impl NSCopying for MPSCNNAddGradient {}
1485);
1486
1487#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1488unsafe impl CopyingHelper for MPSCNNAddGradient {
1489    type Result = Self;
1490}
1491
1492#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1493extern_conformance!(
1494    unsafe impl NSObjectProtocol for MPSCNNAddGradient {}
1495);
1496
1497#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1498extern_conformance!(
1499    unsafe impl NSSecureCoding for MPSCNNAddGradient {}
1500);
1501
1502#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1503impl MPSCNNAddGradient {
1504    extern_methods!(
1505        /// Initialize the addition gradient operator.
1506        ///
1507        /// Parameter `device`: The device the filter will run on.
1508        ///
1509        /// Parameter `isSecondarySourceFilter`: A boolean indicating whether the arithmetic gradient
1510        /// filter is operating on the primary or secondary source image from the forward pass.
1511        ///
1512        /// Returns: A valid MPSCNNAddGradient object or nil, if failure.
1513        #[unsafe(method(initWithDevice:isSecondarySourceFilter:))]
1514        #[unsafe(method_family = init)]
1515        pub unsafe fn initWithDevice_isSecondarySourceFilter(
1516            this: Allocated<Self>,
1517            device: &ProtocolObject<dyn MTLDevice>,
1518            is_secondary_source_filter: bool,
1519        ) -> Retained<Self>;
1520    );
1521}
1522
1523/// Methods declared on superclass `MPSCNNArithmeticGradient`.
1524#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1525impl MPSCNNAddGradient {
1526    extern_methods!(
1527        #[unsafe(method(initWithDevice:))]
1528        #[unsafe(method_family = init)]
1529        pub unsafe fn initWithDevice(
1530            this: Allocated<Self>,
1531            device: &ProtocolObject<dyn MTLDevice>,
1532        ) -> Retained<Self>;
1533    );
1534}
1535
1536/// Methods declared on superclass `MPSCNNGradientKernel`.
1537#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1538impl MPSCNNAddGradient {
1539    extern_methods!(
1540        /// NSSecureCoding compatability
1541        ///
1542        /// While the standard NSSecureCoding/NSCoding method
1543        /// -initWithCoder: should work, since the file can't
1544        /// know which device your data is allocated on, we
1545        /// have to guess and may guess incorrectly.  To avoid
1546        /// that problem, use initWithCoder:device instead.
1547        ///
1548        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1549        ///
1550        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1551        ///
1552        /// Returns: A new MPSKernel object, or nil if failure.
1553        ///
1554        /// # Safety
1555        ///
1556        /// `a_decoder` possibly has further requirements.
1557        #[unsafe(method(initWithCoder:device:))]
1558        #[unsafe(method_family = init)]
1559        pub unsafe fn initWithCoder_device(
1560            this: Allocated<Self>,
1561            a_decoder: &NSCoder,
1562            device: &ProtocolObject<dyn MTLDevice>,
1563        ) -> Option<Retained<Self>>;
1564    );
1565}
1566
1567/// Methods declared on superclass `MPSKernel`.
1568#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1569impl MPSCNNAddGradient {
1570    extern_methods!(
1571        /// Called by NSCoder to decode MPSKernels
1572        ///
1573        /// This isn't the right interface to decode a MPSKernel, but
1574        /// it is the one that NSCoder uses. To enable your NSCoder
1575        /// (e.g. NSKeyedUnarchiver) to set which device to use
1576        /// extend the object to adopt the MPSDeviceProvider
1577        /// protocol. Otherwise, the Metal system default device
1578        /// will be used.
1579        ///
1580        /// # Safety
1581        ///
1582        /// `a_decoder` possibly has further requirements.
1583        #[unsafe(method(initWithCoder:))]
1584        #[unsafe(method_family = init)]
1585        pub unsafe fn initWithCoder(
1586            this: Allocated<Self>,
1587            a_decoder: &NSCoder,
1588        ) -> Option<Retained<Self>>;
1589    );
1590}
1591
1592/// Methods declared on superclass `NSObject`.
1593#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1594impl MPSCNNAddGradient {
1595    extern_methods!(
1596        #[unsafe(method(init))]
1597        #[unsafe(method_family = init)]
1598        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1599
1600        #[unsafe(method(new))]
1601        #[unsafe(method_family = new)]
1602        pub unsafe fn new() -> Retained<Self>;
1603    );
1604}
1605
1606extern_class!(
1607    /// Dependencies: This depends on Metal.framework.
1608    ///
1609    /// Specifies the subtraction gradient operator.
1610    /// This arithmetic gradient filter requires the following inputs: gradient image from
1611    /// the previous layer (going backwards) and either the primary or the secondary source
1612    /// image from the forward pass. You will need a separate filter for the primary and
1613    /// secondary source images.
1614    ///
1615    /// Without broadcasting, the arithmetic subtract gradient operation for the primary
1616    /// source image is a copy operation on the input gradient image (for x - y, d/dx(x - y) = 1).
1617    /// This copy operation can be optimized away by the graph interface.
1618    ///
1619    /// For the secondary source image, the result is a negation of the gradient image from
1620    /// the previous layer (for x - y, d/dy(x - y) = -1).
1621    ///
1622    /// Setting the broadcasting parameters results in a reduction operation (sum) across all
1623    /// of the applicable broadcasting dimensions (rows, columns, feature channels, or any
1624    /// combination thereof) to produce the destination image of the size that matches the
1625    /// primary/secondary input images used in the forward pass.
1626    ///
1627    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnsubtractgradient?language=objc)
1628    #[unsafe(super(
1629        MPSCNNArithmeticGradient,
1630        MPSCNNGradientKernel,
1631        MPSCNNBinaryKernel,
1632        MPSKernel,
1633        NSObject
1634    ))]
1635    #[derive(Debug, PartialEq, Eq, Hash)]
1636    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1637    pub struct MPSCNNSubtractGradient;
1638);
1639
1640#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1641extern_conformance!(
1642    unsafe impl NSCoding for MPSCNNSubtractGradient {}
1643);
1644
1645#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1646extern_conformance!(
1647    unsafe impl NSCopying for MPSCNNSubtractGradient {}
1648);
1649
1650#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1651unsafe impl CopyingHelper for MPSCNNSubtractGradient {
1652    type Result = Self;
1653}
1654
1655#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1656extern_conformance!(
1657    unsafe impl NSObjectProtocol for MPSCNNSubtractGradient {}
1658);
1659
1660#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1661extern_conformance!(
1662    unsafe impl NSSecureCoding for MPSCNNSubtractGradient {}
1663);
1664
1665#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1666impl MPSCNNSubtractGradient {
1667    extern_methods!(
1668        /// Initialize the subtraction gradient operator.
1669        ///
1670        /// Parameter `device`: The device the filter will run on.
1671        ///
1672        /// Parameter `isSecondarySourceFilter`: A boolean indicating whether the arithmetic gradient
1673        /// filter is operating on the primary or secondary source image from the forward pass.
1674        ///
1675        /// Returns: A valid MPSCNNSubtractGradient object or nil, if failure.
1676        #[unsafe(method(initWithDevice:isSecondarySourceFilter:))]
1677        #[unsafe(method_family = init)]
1678        pub unsafe fn initWithDevice_isSecondarySourceFilter(
1679            this: Allocated<Self>,
1680            device: &ProtocolObject<dyn MTLDevice>,
1681            is_secondary_source_filter: bool,
1682        ) -> Retained<Self>;
1683    );
1684}
1685
1686/// Methods declared on superclass `MPSCNNArithmeticGradient`.
1687#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1688impl MPSCNNSubtractGradient {
1689    extern_methods!(
1690        #[unsafe(method(initWithDevice:))]
1691        #[unsafe(method_family = init)]
1692        pub unsafe fn initWithDevice(
1693            this: Allocated<Self>,
1694            device: &ProtocolObject<dyn MTLDevice>,
1695        ) -> Retained<Self>;
1696    );
1697}
1698
1699/// Methods declared on superclass `MPSCNNGradientKernel`.
1700#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1701impl MPSCNNSubtractGradient {
1702    extern_methods!(
1703        /// NSSecureCoding compatability
1704        ///
1705        /// While the standard NSSecureCoding/NSCoding method
1706        /// -initWithCoder: should work, since the file can't
1707        /// know which device your data is allocated on, we
1708        /// have to guess and may guess incorrectly.  To avoid
1709        /// that problem, use initWithCoder:device instead.
1710        ///
1711        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1712        ///
1713        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1714        ///
1715        /// Returns: A new MPSKernel object, or nil if failure.
1716        ///
1717        /// # Safety
1718        ///
1719        /// `a_decoder` possibly has further requirements.
1720        #[unsafe(method(initWithCoder:device:))]
1721        #[unsafe(method_family = init)]
1722        pub unsafe fn initWithCoder_device(
1723            this: Allocated<Self>,
1724            a_decoder: &NSCoder,
1725            device: &ProtocolObject<dyn MTLDevice>,
1726        ) -> Option<Retained<Self>>;
1727    );
1728}
1729
1730/// Methods declared on superclass `MPSKernel`.
1731#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1732impl MPSCNNSubtractGradient {
1733    extern_methods!(
1734        /// Called by NSCoder to decode MPSKernels
1735        ///
1736        /// This isn't the right interface to decode a MPSKernel, but
1737        /// it is the one that NSCoder uses. To enable your NSCoder
1738        /// (e.g. NSKeyedUnarchiver) to set which device to use
1739        /// extend the object to adopt the MPSDeviceProvider
1740        /// protocol. Otherwise, the Metal system default device
1741        /// will be used.
1742        ///
1743        /// # Safety
1744        ///
1745        /// `a_decoder` possibly has further requirements.
1746        #[unsafe(method(initWithCoder:))]
1747        #[unsafe(method_family = init)]
1748        pub unsafe fn initWithCoder(
1749            this: Allocated<Self>,
1750            a_decoder: &NSCoder,
1751        ) -> Option<Retained<Self>>;
1752    );
1753}
1754
1755/// Methods declared on superclass `NSObject`.
1756#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1757impl MPSCNNSubtractGradient {
1758    extern_methods!(
1759        #[unsafe(method(init))]
1760        #[unsafe(method_family = init)]
1761        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1762
1763        #[unsafe(method(new))]
1764        #[unsafe(method_family = new)]
1765        pub unsafe fn new() -> Retained<Self>;
1766    );
1767}
1768
1769extern_class!(
1770    /// Dependencies: This depends on Metal.framework.
1771    ///
1772    /// Specifies the multiplication gradient operator.
1773    /// This arithmetic gradient filter requires the following inputs: gradient image from
1774    /// the previous layer (going backwards) and either the primary or the secondary source
1775    /// image from the forward pass. You will need a separate filter for the primary and
1776    /// secondary source images.
1777    ///
1778    /// Without broadcasting, the arithmetic multiply gradient operation is an element-wise
1779    /// multiplication operation between the gradient image from the previous layer (going
1780    /// backwards) and:
1781    /// - The secondary source image from the forward pass for the primary source filter
1782    /// (for x * y, d/dx(x * y) = y).
1783    /// - The primary source image from the forward pass for the secondary source filter
1784    /// (for x * y, d/dy(x * y) = x).
1785    ///
1786    /// Setting the broadcasting parameters results in a reduction operation (sum) across all
1787    /// of the applicable broadcasting dimensions (rows, columns, feature channels, or any
1788    /// combination thereof) to produce the destination image of the size that matches the
1789    /// primary/secondary input images used in the forward pass.
1790    ///
1791    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnmultiplygradient?language=objc)
1792    #[unsafe(super(
1793        MPSCNNArithmeticGradient,
1794        MPSCNNGradientKernel,
1795        MPSCNNBinaryKernel,
1796        MPSKernel,
1797        NSObject
1798    ))]
1799    #[derive(Debug, PartialEq, Eq, Hash)]
1800    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1801    pub struct MPSCNNMultiplyGradient;
1802);
1803
1804#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1805extern_conformance!(
1806    unsafe impl NSCoding for MPSCNNMultiplyGradient {}
1807);
1808
1809#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1810extern_conformance!(
1811    unsafe impl NSCopying for MPSCNNMultiplyGradient {}
1812);
1813
1814#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1815unsafe impl CopyingHelper for MPSCNNMultiplyGradient {
1816    type Result = Self;
1817}
1818
1819#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1820extern_conformance!(
1821    unsafe impl NSObjectProtocol for MPSCNNMultiplyGradient {}
1822);
1823
1824#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1825extern_conformance!(
1826    unsafe impl NSSecureCoding for MPSCNNMultiplyGradient {}
1827);
1828
1829#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1830impl MPSCNNMultiplyGradient {
1831    extern_methods!(
1832        /// Initialize the multiplication gradient operator.
1833        ///
1834        /// Parameter `device`: The device the filter will run on.
1835        ///
1836        /// Parameter `isSecondarySourceFilter`: A boolean indicating whether the arithmetic gradient
1837        /// filter is operating on the primary or secondary source image from the forward pass.
1838        ///
1839        /// Returns: A valid MPSCNNMultiplyGradient object or nil, if failure.
1840        #[unsafe(method(initWithDevice:isSecondarySourceFilter:))]
1841        #[unsafe(method_family = init)]
1842        pub unsafe fn initWithDevice_isSecondarySourceFilter(
1843            this: Allocated<Self>,
1844            device: &ProtocolObject<dyn MTLDevice>,
1845            is_secondary_source_filter: bool,
1846        ) -> Retained<Self>;
1847    );
1848}
1849
1850/// Methods declared on superclass `MPSCNNArithmeticGradient`.
1851#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1852impl MPSCNNMultiplyGradient {
1853    extern_methods!(
1854        #[unsafe(method(initWithDevice:))]
1855        #[unsafe(method_family = init)]
1856        pub unsafe fn initWithDevice(
1857            this: Allocated<Self>,
1858            device: &ProtocolObject<dyn MTLDevice>,
1859        ) -> Retained<Self>;
1860    );
1861}
1862
1863/// Methods declared on superclass `MPSCNNGradientKernel`.
1864#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1865impl MPSCNNMultiplyGradient {
1866    extern_methods!(
1867        /// NSSecureCoding compatability
1868        ///
1869        /// While the standard NSSecureCoding/NSCoding method
1870        /// -initWithCoder: should work, since the file can't
1871        /// know which device your data is allocated on, we
1872        /// have to guess and may guess incorrectly.  To avoid
1873        /// that problem, use initWithCoder:device instead.
1874        ///
1875        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
1876        ///
1877        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
1878        ///
1879        /// Returns: A new MPSKernel object, or nil if failure.
1880        ///
1881        /// # Safety
1882        ///
1883        /// `a_decoder` possibly has further requirements.
1884        #[unsafe(method(initWithCoder:device:))]
1885        #[unsafe(method_family = init)]
1886        pub unsafe fn initWithCoder_device(
1887            this: Allocated<Self>,
1888            a_decoder: &NSCoder,
1889            device: &ProtocolObject<dyn MTLDevice>,
1890        ) -> Option<Retained<Self>>;
1891    );
1892}
1893
1894/// Methods declared on superclass `MPSKernel`.
1895#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1896impl MPSCNNMultiplyGradient {
1897    extern_methods!(
1898        /// Called by NSCoder to decode MPSKernels
1899        ///
1900        /// This isn't the right interface to decode a MPSKernel, but
1901        /// it is the one that NSCoder uses. To enable your NSCoder
1902        /// (e.g. NSKeyedUnarchiver) to set which device to use
1903        /// extend the object to adopt the MPSDeviceProvider
1904        /// protocol. Otherwise, the Metal system default device
1905        /// will be used.
1906        ///
1907        /// # Safety
1908        ///
1909        /// `a_decoder` possibly has further requirements.
1910        #[unsafe(method(initWithCoder:))]
1911        #[unsafe(method_family = init)]
1912        pub unsafe fn initWithCoder(
1913            this: Allocated<Self>,
1914            a_decoder: &NSCoder,
1915        ) -> Option<Retained<Self>>;
1916    );
1917}
1918
1919/// Methods declared on superclass `NSObject`.
1920#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
1921impl MPSCNNMultiplyGradient {
1922    extern_methods!(
1923        #[unsafe(method(init))]
1924        #[unsafe(method_family = init)]
1925        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1926
1927        #[unsafe(method(new))]
1928        #[unsafe(method_family = new)]
1929        pub unsafe fn new() -> Retained<Self>;
1930    );
1931}