objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSCNNSoftMax.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6use objc2_metal::*;
7
8use crate::*;
9
10extern_class!(
11    /// Dependencies: This depends on Metal.framework
12    ///
13    /// The softMax filter is a neural transfer function and is useful for classification tasks.
14    /// The softMax filter is applied across feature channels and in a convolutional manner at all
15    /// spatial locations. The softMax filter can be seen as the combination of an
16    /// activation function (exponential) and a normalization operator.
17    /// For each feature channel per pixel in an image in a feature map, the softMax filter computes the following:
18    /// result channel in pixel = exp(pixel(x,y,k))/sum(exp(pixel(x,y,0)) ... exp(pixel(x,y,N-1))
19    /// where N is the number of feature channels
20    ///
21    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnsoftmax?language=objc)
22    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
23    #[derive(Debug, PartialEq, Eq, Hash)]
24    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
25    pub struct MPSCNNSoftMax;
26);
27
28#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
29extern_conformance!(
30    unsafe impl NSCoding for MPSCNNSoftMax {}
31);
32
33#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
34extern_conformance!(
35    unsafe impl NSCopying for MPSCNNSoftMax {}
36);
37
38#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
39unsafe impl CopyingHelper for MPSCNNSoftMax {
40    type Result = Self;
41}
42
43#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
44extern_conformance!(
45    unsafe impl NSObjectProtocol for MPSCNNSoftMax {}
46);
47
48#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
49extern_conformance!(
50    unsafe impl NSSecureCoding for MPSCNNSoftMax {}
51);
52
53#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
54impl MPSCNNSoftMax {
55    extern_methods!();
56}
57
58/// Methods declared on superclass `MPSCNNKernel`.
59#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
60impl MPSCNNSoftMax {
61    extern_methods!(
62        /// Standard init with default properties per filter type
63        ///
64        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
65        ///
66        /// Returns: A pointer to the newly initialized object. This will fail, returning
67        /// nil if the device is not supported. Devices must be
68        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
69        #[unsafe(method(initWithDevice:))]
70        #[unsafe(method_family = init)]
71        pub unsafe fn initWithDevice(
72            this: Allocated<Self>,
73            device: &ProtocolObject<dyn MTLDevice>,
74        ) -> Retained<Self>;
75
76        /// NSSecureCoding compatability
77        ///
78        /// While the standard NSSecureCoding/NSCoding method
79        /// -initWithCoder: should work, since the file can't
80        /// know which device your data is allocated on, we
81        /// have to guess and may guess incorrectly.  To avoid
82        /// that problem, use initWithCoder:device instead.
83        ///
84        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
85        ///
86        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
87        ///
88        /// Returns: A new MPSKernel object, or nil if failure.
89        ///
90        /// # Safety
91        ///
92        /// `a_decoder` possibly has further requirements.
93        #[unsafe(method(initWithCoder:device:))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn initWithCoder_device(
96            this: Allocated<Self>,
97            a_decoder: &NSCoder,
98            device: &ProtocolObject<dyn MTLDevice>,
99        ) -> Option<Retained<Self>>;
100    );
101}
102
103/// Methods declared on superclass `MPSKernel`.
104#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
105impl MPSCNNSoftMax {
106    extern_methods!(
107        /// Called by NSCoder to decode MPSKernels
108        ///
109        /// This isn't the right interface to decode a MPSKernel, but
110        /// it is the one that NSCoder uses. To enable your NSCoder
111        /// (e.g. NSKeyedUnarchiver) to set which device to use
112        /// extend the object to adopt the MPSDeviceProvider
113        /// protocol. Otherwise, the Metal system default device
114        /// will be used.
115        ///
116        /// # Safety
117        ///
118        /// `a_decoder` possibly has further requirements.
119        #[unsafe(method(initWithCoder:))]
120        #[unsafe(method_family = init)]
121        pub unsafe fn initWithCoder(
122            this: Allocated<Self>,
123            a_decoder: &NSCoder,
124        ) -> Option<Retained<Self>>;
125    );
126}
127
128/// Methods declared on superclass `NSObject`.
129#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
130impl MPSCNNSoftMax {
131    extern_methods!(
132        #[unsafe(method(init))]
133        #[unsafe(method_family = init)]
134        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
135
136        #[unsafe(method(new))]
137        #[unsafe(method_family = new)]
138        pub unsafe fn new() -> Retained<Self>;
139    );
140}
141
142extern_class!(
143    /// Dependencies: This depends on Metal.framework
144    ///
145    /// The softMax gradient filter calculates the gradient to be backpropagated.
146    /// The softMax gradient just as the softMax filter, is applied across feature channels and at all spatial locations.
147    /// It computes the gradient for a given output generated by the corresponding softMax (i.e. MPSCNNSoftMax) layer and
148    /// the gradient computed by the previous layer in the back-propagation pass.
149    /// For each feature channel in an image in a feature map, the softMax gradient filter computes the following:
150    /// result gradient channel in pixel
151    /// outputGradient(x,y,k) = softMax(x,y,k) * (inputGradient(x,y,k) -
152    /// sum(inputGradient(x,y,0) * softMax(x,y,0) ... inputGradient(x,y,N-1) * softMax(x,y,N-1)))
153    /// where N is the number of feature channels
154    ///
155    /// The incoming gradient is the primary source.
156    /// The original output of corresponding softMax is the secondary source.
157    ///
158    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnsoftmaxgradient?language=objc)
159    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
160    #[derive(Debug, PartialEq, Eq, Hash)]
161    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
162    pub struct MPSCNNSoftMaxGradient;
163);
164
165#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
166extern_conformance!(
167    unsafe impl NSCoding for MPSCNNSoftMaxGradient {}
168);
169
170#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
171extern_conformance!(
172    unsafe impl NSCopying for MPSCNNSoftMaxGradient {}
173);
174
175#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
176unsafe impl CopyingHelper for MPSCNNSoftMaxGradient {
177    type Result = Self;
178}
179
180#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
181extern_conformance!(
182    unsafe impl NSObjectProtocol for MPSCNNSoftMaxGradient {}
183);
184
185#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
186extern_conformance!(
187    unsafe impl NSSecureCoding for MPSCNNSoftMaxGradient {}
188);
189
190#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
191impl MPSCNNSoftMaxGradient {
192    extern_methods!(
193        /// Initializes a MPSCNNSoftMaxGradient function
194        ///
195        /// Parameter `device`: The MTLDevice on which this MPSCNNSoftMaxGradient filter will be used
196        ///
197        ///
198        /// Returns: A valid MPSCNNSoftMaxGradient object or nil, if failure.
199        #[unsafe(method(initWithDevice:))]
200        #[unsafe(method_family = init)]
201        pub unsafe fn initWithDevice(
202            this: Allocated<Self>,
203            device: &ProtocolObject<dyn MTLDevice>,
204        ) -> Retained<Self>;
205
206        /// NSSecureCoding compatability
207        ///
208        /// While the standard NSSecureCoding/NSCoding method
209        /// -initWithCoder: should work, since the file can't
210        /// know which device your data is allocated on, we
211        /// have to guess and may guess incorrectly.  To avoid
212        /// that problem, use initWithCoder:device instead.
213        ///
214        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
215        ///
216        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
217        ///
218        /// Returns: A new MPSKernel object, or nil if failure.
219        ///
220        /// # Safety
221        ///
222        /// `a_decoder` possibly has further requirements.
223        #[unsafe(method(initWithCoder:device:))]
224        #[unsafe(method_family = init)]
225        pub unsafe fn initWithCoder_device(
226            this: Allocated<Self>,
227            a_decoder: &NSCoder,
228            device: &ProtocolObject<dyn MTLDevice>,
229        ) -> Option<Retained<Self>>;
230    );
231}
232
233/// Methods declared on superclass `MPSKernel`.
234#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
235impl MPSCNNSoftMaxGradient {
236    extern_methods!(
237        /// Called by NSCoder to decode MPSKernels
238        ///
239        /// This isn't the right interface to decode a MPSKernel, but
240        /// it is the one that NSCoder uses. To enable your NSCoder
241        /// (e.g. NSKeyedUnarchiver) to set which device to use
242        /// extend the object to adopt the MPSDeviceProvider
243        /// protocol. Otherwise, the Metal system default device
244        /// will be used.
245        ///
246        /// # Safety
247        ///
248        /// `a_decoder` possibly has further requirements.
249        #[unsafe(method(initWithCoder:))]
250        #[unsafe(method_family = init)]
251        pub unsafe fn initWithCoder(
252            this: Allocated<Self>,
253            a_decoder: &NSCoder,
254        ) -> Option<Retained<Self>>;
255    );
256}
257
258/// Methods declared on superclass `NSObject`.
259#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
260impl MPSCNNSoftMaxGradient {
261    extern_methods!(
262        #[unsafe(method(init))]
263        #[unsafe(method_family = init)]
264        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
265
266        #[unsafe(method(new))]
267        #[unsafe(method_family = new)]
268        pub unsafe fn new() -> Retained<Self>;
269    );
270}
271
272extern_class!(
273    /// Dependencies: This depends on Metal.framework
274    ///
275    /// The logarithmic softMax filter can be achieved by taking the natural logarithm of the
276    /// the result of the softMax filter. The results are often used to construct a loss function to be
277    /// minimized when training neural networks.
278    /// For each feature channel per pixel in an image in a feature map, the logarithmic softMax filter
279    /// computes the following:
280    /// result channel in pixel = pixel(x,y,k)) - ln{sum(exp(pixel(x,y,0)) ... exp(pixel(x,y,N-1))}
281    /// where N is the number of feature channels and y = ln{x} satisfies e^y = x.
282    ///
283    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnlogsoftmax?language=objc)
284    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
285    #[derive(Debug, PartialEq, Eq, Hash)]
286    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
287    pub struct MPSCNNLogSoftMax;
288);
289
290#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
291extern_conformance!(
292    unsafe impl NSCoding for MPSCNNLogSoftMax {}
293);
294
295#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
296extern_conformance!(
297    unsafe impl NSCopying for MPSCNNLogSoftMax {}
298);
299
300#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
301unsafe impl CopyingHelper for MPSCNNLogSoftMax {
302    type Result = Self;
303}
304
305#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
306extern_conformance!(
307    unsafe impl NSObjectProtocol for MPSCNNLogSoftMax {}
308);
309
310#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
311extern_conformance!(
312    unsafe impl NSSecureCoding for MPSCNNLogSoftMax {}
313);
314
315#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
316impl MPSCNNLogSoftMax {
317    extern_methods!();
318}
319
320/// Methods declared on superclass `MPSCNNKernel`.
321#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
322impl MPSCNNLogSoftMax {
323    extern_methods!(
324        /// Standard init with default properties per filter type
325        ///
326        /// Parameter `device`: The device that the filter will be used on. May not be NULL.
327        ///
328        /// Returns: A pointer to the newly initialized object. This will fail, returning
329        /// nil if the device is not supported. Devices must be
330        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
331        #[unsafe(method(initWithDevice:))]
332        #[unsafe(method_family = init)]
333        pub unsafe fn initWithDevice(
334            this: Allocated<Self>,
335            device: &ProtocolObject<dyn MTLDevice>,
336        ) -> Retained<Self>;
337
338        /// NSSecureCoding compatability
339        ///
340        /// While the standard NSSecureCoding/NSCoding method
341        /// -initWithCoder: should work, since the file can't
342        /// know which device your data is allocated on, we
343        /// have to guess and may guess incorrectly.  To avoid
344        /// that problem, use initWithCoder:device instead.
345        ///
346        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
347        ///
348        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
349        ///
350        /// Returns: A new MPSKernel object, or nil if failure.
351        ///
352        /// # Safety
353        ///
354        /// `a_decoder` possibly has further requirements.
355        #[unsafe(method(initWithCoder:device:))]
356        #[unsafe(method_family = init)]
357        pub unsafe fn initWithCoder_device(
358            this: Allocated<Self>,
359            a_decoder: &NSCoder,
360            device: &ProtocolObject<dyn MTLDevice>,
361        ) -> Option<Retained<Self>>;
362    );
363}
364
365/// Methods declared on superclass `MPSKernel`.
366#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
367impl MPSCNNLogSoftMax {
368    extern_methods!(
369        /// Called by NSCoder to decode MPSKernels
370        ///
371        /// This isn't the right interface to decode a MPSKernel, but
372        /// it is the one that NSCoder uses. To enable your NSCoder
373        /// (e.g. NSKeyedUnarchiver) to set which device to use
374        /// extend the object to adopt the MPSDeviceProvider
375        /// protocol. Otherwise, the Metal system default device
376        /// will be used.
377        ///
378        /// # Safety
379        ///
380        /// `a_decoder` possibly has further requirements.
381        #[unsafe(method(initWithCoder:))]
382        #[unsafe(method_family = init)]
383        pub unsafe fn initWithCoder(
384            this: Allocated<Self>,
385            a_decoder: &NSCoder,
386        ) -> Option<Retained<Self>>;
387    );
388}
389
390/// Methods declared on superclass `NSObject`.
391#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
392impl MPSCNNLogSoftMax {
393    extern_methods!(
394        #[unsafe(method(init))]
395        #[unsafe(method_family = init)]
396        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
397
398        #[unsafe(method(new))]
399        #[unsafe(method_family = new)]
400        pub unsafe fn new() -> Retained<Self>;
401    );
402}
403
404extern_class!(
405    /// Dependencies: This depends on Metal.framework
406    ///
407    /// The logSoftMax gradient filter calculates the gradient to be backpropagated.
408    /// The logSoftMax gradient just as the log softMax filter, is applied across feature channels and at all spatial locations.
409    /// It computes the gradient for a given output generated by the corresponding logSoftMax (i.e. MPSCNNLogSoftMax) layer and
410    /// the gradient computed by the previous layer in the back-propagation pass.
411    /// For each feature channel per pixel in an image in a feature map, the logSoftMax gradient filter computes the following:
412    /// result gradient channel in pixel
413    /// outputGradient(x,y,k) = inputGradient(x,y,k) - exp(logSoftMax(x,y,k)) * sum(inputGradient(x,y,0) ... inputGradient(x,y,N-1))
414    /// where N is the number of feature channels
415    ///
416    /// The incoming gradient is the primary source.
417    /// The original output of corresponding logSoftMax is the secondary source.
418    ///
419    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnnlogsoftmaxgradient?language=objc)
420    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
421    #[derive(Debug, PartialEq, Eq, Hash)]
422    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
423    pub struct MPSCNNLogSoftMaxGradient;
424);
425
426#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
427extern_conformance!(
428    unsafe impl NSCoding for MPSCNNLogSoftMaxGradient {}
429);
430
431#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
432extern_conformance!(
433    unsafe impl NSCopying for MPSCNNLogSoftMaxGradient {}
434);
435
436#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
437unsafe impl CopyingHelper for MPSCNNLogSoftMaxGradient {
438    type Result = Self;
439}
440
441#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
442extern_conformance!(
443    unsafe impl NSObjectProtocol for MPSCNNLogSoftMaxGradient {}
444);
445
446#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
447extern_conformance!(
448    unsafe impl NSSecureCoding for MPSCNNLogSoftMaxGradient {}
449);
450
451#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
452impl MPSCNNLogSoftMaxGradient {
453    extern_methods!(
454        /// Initializes a MPSCNNLogSoftMaxGradient function
455        ///
456        /// Parameter `device`: The MTLDevice on which this MPSCNNLogSoftMaxGradient filter will be used
457        ///
458        ///
459        /// Returns: A valid MPSCNNLogSoftMaxGradient object or nil, if failure.
460        #[unsafe(method(initWithDevice:))]
461        #[unsafe(method_family = init)]
462        pub unsafe fn initWithDevice(
463            this: Allocated<Self>,
464            device: &ProtocolObject<dyn MTLDevice>,
465        ) -> Retained<Self>;
466
467        /// NSSecureCoding compatability
468        ///
469        /// While the standard NSSecureCoding/NSCoding method
470        /// -initWithCoder: should work, since the file can't
471        /// know which device your data is allocated on, we
472        /// have to guess and may guess incorrectly.  To avoid
473        /// that problem, use initWithCoder:device instead.
474        ///
475        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
476        ///
477        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
478        ///
479        /// Returns: A new MPSKernel object, or nil if failure.
480        ///
481        /// # Safety
482        ///
483        /// `a_decoder` possibly has further requirements.
484        #[unsafe(method(initWithCoder:device:))]
485        #[unsafe(method_family = init)]
486        pub unsafe fn initWithCoder_device(
487            this: Allocated<Self>,
488            a_decoder: &NSCoder,
489            device: &ProtocolObject<dyn MTLDevice>,
490        ) -> Option<Retained<Self>>;
491    );
492}
493
494/// Methods declared on superclass `MPSKernel`.
495#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
496impl MPSCNNLogSoftMaxGradient {
497    extern_methods!(
498        /// Called by NSCoder to decode MPSKernels
499        ///
500        /// This isn't the right interface to decode a MPSKernel, but
501        /// it is the one that NSCoder uses. To enable your NSCoder
502        /// (e.g. NSKeyedUnarchiver) to set which device to use
503        /// extend the object to adopt the MPSDeviceProvider
504        /// protocol. Otherwise, the Metal system default device
505        /// will be used.
506        ///
507        /// # Safety
508        ///
509        /// `a_decoder` possibly has further requirements.
510        #[unsafe(method(initWithCoder:))]
511        #[unsafe(method_family = init)]
512        pub unsafe fn initWithCoder(
513            this: Allocated<Self>,
514            a_decoder: &NSCoder,
515        ) -> Option<Retained<Self>>;
516    );
517}
518
519/// Methods declared on superclass `NSObject`.
520#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
521impl MPSCNNLogSoftMaxGradient {
522    extern_methods!(
523        #[unsafe(method(init))]
524        #[unsafe(method_family = init)]
525        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
526
527        #[unsafe(method(new))]
528        #[unsafe(method_family = new)]
529        pub unsafe fn new() -> Retained<Self>;
530    );
531}