objc2_metal_performance_shaders/generated/MPSNeuralNetwork/
MPSCNNDropout.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 MPSCNNDropoutGradientState is used to hold the mask used by both
15    /// MPSCNNDropout forward filter and MPSCNNDropoutGradient backward filter.
16    /// The MPSCNNDropout forward filter populates the MPSCNNDropoutGradientState
17    /// object and the MPSCNNDropoutGradient backward filter consumes the state
18    /// object.
19    ///
20    /// While the mask is stored internally, the mask data is accessible by the
21    /// user for debugging purposes via an accessor method.
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnndropoutgradientstate?language=objc)
24    #[unsafe(super(MPSNNGradientState, MPSState, NSObject))]
25    #[derive(Debug, PartialEq, Eq, Hash)]
26    #[cfg(all(
27        feature = "MPSCore",
28        feature = "MPSNNGradientState",
29        feature = "MPSState"
30    ))]
31    pub struct MPSCNNDropoutGradientState;
32);
33
34#[cfg(all(
35    feature = "MPSCore",
36    feature = "MPSNNGradientState",
37    feature = "MPSState"
38))]
39extern_conformance!(
40    unsafe impl NSObjectProtocol for MPSCNNDropoutGradientState {}
41);
42
43#[cfg(all(
44    feature = "MPSCore",
45    feature = "MPSNNGradientState",
46    feature = "MPSState"
47))]
48impl MPSCNNDropoutGradientState {
49    extern_methods!(
50        #[unsafe(method(init))]
51        #[unsafe(method_family = init)]
52        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
53
54        /// Mask data accessor method.
55        ///
56        /// Returns: An autoreleased NSData object, containing the mask data.
57        /// The mask data is populated in the -encode call, thus the contents
58        /// are undefined until you -encode the filter.
59        /// Use for debugging purposes only.
60        ///
61        /// In order to gaurantee that the mask data is correctly synchronized for CPU side access,
62        /// it is the application's responsibility to call the [gradientState synchronizeOnCommandBuffer:]
63        /// method before accessing the mask data.
64        #[unsafe(method(maskData))]
65        #[unsafe(method_family = none)]
66        pub unsafe fn maskData(&self) -> Retained<NSData>;
67    );
68}
69
70/// Methods declared on superclass `MPSState`.
71#[cfg(all(
72    feature = "MPSCore",
73    feature = "MPSNNGradientState",
74    feature = "MPSState"
75))]
76impl MPSCNNDropoutGradientState {
77    extern_methods!(
78        /// Create a MPSState holding a temporary MTLBuffer
79        ///
80        /// Parameter `cmdBuf`: The command buffer against which the temporary resource is allocated
81        ///
82        /// Parameter `bufferSize`: The size of the buffer in bytes
83        #[unsafe(method(temporaryStateWithCommandBuffer:bufferSize:))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn temporaryStateWithCommandBuffer_bufferSize(
86            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
87            buffer_size: usize,
88        ) -> Retained<Self>;
89
90        /// Create a MPSState holding a temporary MTLTexture
91        ///
92        /// Parameter `cmdBuf`: The command buffer against which the temporary resource is allocated
93        ///
94        /// Parameter `descriptor`: A descriptor for the new temporary texture
95        #[unsafe(method(temporaryStateWithCommandBuffer:textureDescriptor:))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn temporaryStateWithCommandBuffer_textureDescriptor(
98            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
99            descriptor: &MTLTextureDescriptor,
100        ) -> Retained<Self>;
101
102        /// Create a new autoreleased temporary state object without underlying resource
103        ///
104        /// Parameter `cmdBuf`: The command buffer with which the temporary resource is associated
105        #[unsafe(method(temporaryStateWithCommandBuffer:))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn temporaryStateWithCommandBuffer(
108            cmd_buf: &ProtocolObject<dyn MTLCommandBuffer>,
109        ) -> Retained<Self>;
110
111        #[unsafe(method(initWithDevice:bufferSize:))]
112        #[unsafe(method_family = init)]
113        pub unsafe fn initWithDevice_bufferSize(
114            this: Allocated<Self>,
115            device: &ProtocolObject<dyn MTLDevice>,
116            buffer_size: usize,
117        ) -> Retained<Self>;
118
119        #[unsafe(method(initWithDevice:textureDescriptor:))]
120        #[unsafe(method_family = init)]
121        pub unsafe fn initWithDevice_textureDescriptor(
122            this: Allocated<Self>,
123            device: &ProtocolObject<dyn MTLDevice>,
124            descriptor: &MTLTextureDescriptor,
125        ) -> Retained<Self>;
126
127        /// Create a MPSState with a non-temporary MTLResource
128        ///
129        /// Parameter `resource`: A MTLBuffer or MTLTexture. May be nil.
130        ///
131        /// # Safety
132        ///
133        /// - `resource` may need to be synchronized.
134        /// - `resource` may be unretained, you must ensure it is kept alive while in use.
135        #[unsafe(method(initWithResource:))]
136        #[unsafe(method_family = init)]
137        pub unsafe fn initWithResource(
138            this: Allocated<Self>,
139            resource: Option<&ProtocolObject<dyn MTLResource>>,
140        ) -> Retained<Self>;
141
142        /// Initialize a non-temporary state to hold a number of textures and buffers
143        ///
144        /// The allocation of each resource will be deferred  until it is needed.
145        /// This occurs when -resource or -resourceAtIndex: is called.
146        ///
147        /// Parameter `resourceList`: The list of resources to create.
148        #[unsafe(method(initWithDevice:resourceList:))]
149        #[unsafe(method_family = init)]
150        pub unsafe fn initWithDevice_resourceList(
151            this: Allocated<Self>,
152            device: &ProtocolObject<dyn MTLDevice>,
153            resource_list: &MPSStateResourceList,
154        ) -> Retained<Self>;
155
156        /// Initialize a temporary state to hold a number of textures and buffers
157        ///
158        /// The textures occur first in sequence
159        #[unsafe(method(temporaryStateWithCommandBuffer:resourceList:))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn temporaryStateWithCommandBuffer_resourceList(
162            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
163            resource_list: &MPSStateResourceList,
164        ) -> Retained<Self>;
165
166        /// Create a state object with a list of MTLResources
167        ///
168        /// Because MPS prefers deferred allocation of resources
169        /// your application should use -initWithTextures:bufferSizes:bufferCount:
170        /// whenever possible. This method is useful for cases when the
171        /// MTLResources must be initialized by the CPU.
172        ///
173        /// # Safety
174        ///
175        /// - `resources` generic may need to be synchronized.
176        /// - `resources` generic may be unretained, you must ensure it is kept alive while in use.
177        #[unsafe(method(initWithResources:))]
178        #[unsafe(method_family = init)]
179        pub unsafe fn initWithResources(
180            this: Allocated<Self>,
181            resources: Option<&NSArray<ProtocolObject<dyn MTLResource>>>,
182        ) -> Retained<Self>;
183    );
184}
185
186/// Methods declared on superclass `NSObject`.
187#[cfg(all(
188    feature = "MPSCore",
189    feature = "MPSNNGradientState",
190    feature = "MPSState"
191))]
192impl MPSCNNDropoutGradientState {
193    extern_methods!(
194        #[unsafe(method(new))]
195        #[unsafe(method_family = new)]
196        pub unsafe fn new() -> Retained<Self>;
197    );
198}
199
200/// [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnndropoutgradientstatebatch?language=objc)
201#[cfg(all(
202    feature = "MPSCore",
203    feature = "MPSNNGradientState",
204    feature = "MPSState"
205))]
206pub type MPSCNNDropoutGradientStateBatch = NSArray<MPSCNNDropoutGradientState>;
207
208extern_class!(
209    /// Dependencies: This depends on Metal.framework
210    ///
211    /// Dropout is a regularization technique used to prevent neural networks from
212    /// overfitting during training. With probability keepProbability, this filter
213    /// outputs the input element scaled by 1 / keepProbability. Otherwise, it
214    /// outputs 0. Each input element is kept or dropped independently. The scaling
215    /// is performed to keep the energy of the output unchanged.
216    ///
217    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnndropout?language=objc)
218    #[unsafe(super(MPSCNNKernel, MPSKernel, NSObject))]
219    #[derive(Debug, PartialEq, Eq, Hash)]
220    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
221    pub struct MPSCNNDropout;
222);
223
224#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
225extern_conformance!(
226    unsafe impl NSCoding for MPSCNNDropout {}
227);
228
229#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
230extern_conformance!(
231    unsafe impl NSCopying for MPSCNNDropout {}
232);
233
234#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
235unsafe impl CopyingHelper for MPSCNNDropout {
236    type Result = Self;
237}
238
239#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
240extern_conformance!(
241    unsafe impl NSObjectProtocol for MPSCNNDropout {}
242);
243
244#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
245extern_conformance!(
246    unsafe impl NSSecureCoding for MPSCNNDropout {}
247);
248
249#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
250impl MPSCNNDropout {
251    extern_methods!(
252        /// The probability that each element in the input is kept.
253        /// The valid range is (0.0f, 1.0f).
254        #[unsafe(method(keepProbability))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn keepProbability(&self) -> c_float;
257
258        /// The seed used to generate random numbers.
259        #[unsafe(method(seed))]
260        #[unsafe(method_family = none)]
261        pub unsafe fn seed(&self) -> NSUInteger;
262
263        /// The mask stride in the x, y, and x dimensions, which
264        /// allows for the broadcasting the mask data.
265        ///
266        /// The only valid values are 0 and 1 for each dimension.
267        /// For no broadcasting, set the values for each dimension
268        /// to 1. For broadcasting, set desired values to 0.
269        #[unsafe(method(maskStrideInPixels))]
270        #[unsafe(method_family = none)]
271        pub unsafe fn maskStrideInPixels(&self) -> MTLSize;
272
273        #[unsafe(method(initWithDevice:))]
274        #[unsafe(method_family = init)]
275        pub unsafe fn initWithDevice(
276            this: Allocated<Self>,
277            device: &ProtocolObject<dyn MTLDevice>,
278        ) -> Retained<Self>;
279
280        /// <NSSecureCoding
281        /// > support
282        ///
283        /// # Safety
284        ///
285        /// `a_decoder` possibly has further requirements.
286        #[unsafe(method(initWithCoder:device:))]
287        #[unsafe(method_family = init)]
288        pub unsafe fn initWithCoder_device(
289            this: Allocated<Self>,
290            a_decoder: &NSCoder,
291            device: &ProtocolObject<dyn MTLDevice>,
292        ) -> Option<Retained<Self>>;
293
294        /// Standard init with default properties per filter type.
295        ///
296        /// Parameter `device`: The device that the filter will be used on.
297        ///
298        /// Parameter `keepProbability`: The probability that each element in the input is kept.
299        /// The valid range is (0.0f, 1.0f).
300        ///
301        /// Parameter `seed`: The seed used to generate random numbers.
302        ///
303        /// Parameter `maskStrideInPixels`: The mask stride in the x, y, and z dimensions, which
304        /// allows for the broadcasting of mask data. The only valid
305        /// values are 0 and 1 for each dimension. For no
306        /// broadcasting, set the values for each dimension to 1.
307        /// For broadcasting, set desired values to 0.
308        ///
309        /// Returns: A valid MPSCNNDropout object or nil, if failure.
310        #[unsafe(method(initWithDevice:keepProbability:seed:maskStrideInPixels:))]
311        #[unsafe(method_family = init)]
312        pub unsafe fn initWithDevice_keepProbability_seed_maskStrideInPixels(
313            this: Allocated<Self>,
314            device: &ProtocolObject<dyn MTLDevice>,
315            keep_probability: c_float,
316            seed: NSUInteger,
317            mask_stride_in_pixels: MTLSize,
318        ) -> Retained<Self>;
319
320        #[cfg(all(
321            feature = "MPSImage",
322            feature = "MPSNNGradientState",
323            feature = "MPSState"
324        ))]
325        #[unsafe(method(resultStateForSourceImage:sourceStates:destinationImage:))]
326        #[unsafe(method_family = none)]
327        pub unsafe fn resultStateForSourceImage_sourceStates_destinationImage(
328            &self,
329            source_image: &MPSImage,
330            source_states: Option<&NSArray<MPSState>>,
331            destination_image: &MPSImage,
332        ) -> Option<Retained<MPSCNNDropoutGradientState>>;
333
334        #[cfg(all(
335            feature = "MPSImage",
336            feature = "MPSNDArray",
337            feature = "MPSNNGradientState",
338            feature = "MPSState"
339        ))]
340        #[unsafe(method(resultStateBatchForSourceImage:sourceStates:destinationImage:))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn resultStateBatchForSourceImage_sourceStates_destinationImage(
343            &self,
344            source_image: &MPSImageBatch,
345            source_states: Option<&NSArray<MPSStateBatch>>,
346            destination_image: &MPSImageBatch,
347        ) -> Option<Retained<MPSCNNDropoutGradientState>>;
348
349        #[cfg(all(
350            feature = "MPSImage",
351            feature = "MPSNNGradientState",
352            feature = "MPSState"
353        ))]
354        #[unsafe(method(temporaryResultStateForCommandBuffer:sourceImage:sourceStates:destinationImage:))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn temporaryResultStateForCommandBuffer_sourceImage_sourceStates_destinationImage(
357            &self,
358            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
359            source_image: &MPSImage,
360            source_states: Option<&NSArray<MPSState>>,
361            destination_image: &MPSImage,
362        ) -> Option<Retained<MPSCNNDropoutGradientState>>;
363
364        #[cfg(all(
365            feature = "MPSImage",
366            feature = "MPSNDArray",
367            feature = "MPSNNGradientState",
368            feature = "MPSState"
369        ))]
370        #[unsafe(method(temporaryResultStateBatchForCommandBuffer:sourceImage:sourceStates:destinationImage:))]
371        #[unsafe(method_family = none)]
372        pub unsafe fn temporaryResultStateBatchForCommandBuffer_sourceImage_sourceStates_destinationImage(
373            &self,
374            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
375            source_image: &MPSImageBatch,
376            source_states: Option<&NSArray<MPSStateBatch>>,
377            destination_image: &MPSImageBatch,
378        ) -> Option<Retained<MPSCNNDropoutGradientStateBatch>>;
379    );
380}
381
382/// Methods declared on superclass `MPSKernel`.
383#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
384impl MPSCNNDropout {
385    extern_methods!(
386        /// Called by NSCoder to decode MPSKernels
387        ///
388        /// This isn't the right interface to decode a MPSKernel, but
389        /// it is the one that NSCoder uses. To enable your NSCoder
390        /// (e.g. NSKeyedUnarchiver) to set which device to use
391        /// extend the object to adopt the MPSDeviceProvider
392        /// protocol. Otherwise, the Metal system default device
393        /// will be used.
394        ///
395        /// # Safety
396        ///
397        /// `a_decoder` possibly has further requirements.
398        #[unsafe(method(initWithCoder:))]
399        #[unsafe(method_family = init)]
400        pub unsafe fn initWithCoder(
401            this: Allocated<Self>,
402            a_decoder: &NSCoder,
403        ) -> Option<Retained<Self>>;
404    );
405}
406
407/// Methods declared on superclass `NSObject`.
408#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
409impl MPSCNNDropout {
410    extern_methods!(
411        #[unsafe(method(init))]
412        #[unsafe(method_family = init)]
413        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
414
415        #[unsafe(method(new))]
416        #[unsafe(method_family = new)]
417        pub unsafe fn new() -> Retained<Self>;
418    );
419}
420
421extern_class!(
422    /// Dependencies: This depends on Metal.framework
423    ///
424    /// This filter is the backward filter for the MPSCNNDropout forward filter.
425    /// It requires the mask data, along with all the associated parameters used
426    /// to generate the mask, from the forward pass. The mask is associated with
427    /// a MPSCNNDropoutGradientState object.
428    ///
429    /// In this kernel, use the secondaryOffset to apply an offset to the mask data.
430    ///
431    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpscnndropoutgradient?language=objc)
432    #[unsafe(super(MPSCNNGradientKernel, MPSCNNBinaryKernel, MPSKernel, NSObject))]
433    #[derive(Debug, PartialEq, Eq, Hash)]
434    #[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
435    pub struct MPSCNNDropoutGradient;
436);
437
438#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
439extern_conformance!(
440    unsafe impl NSCoding for MPSCNNDropoutGradient {}
441);
442
443#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
444extern_conformance!(
445    unsafe impl NSCopying for MPSCNNDropoutGradient {}
446);
447
448#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
449unsafe impl CopyingHelper for MPSCNNDropoutGradient {
450    type Result = Self;
451}
452
453#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
454extern_conformance!(
455    unsafe impl NSObjectProtocol for MPSCNNDropoutGradient {}
456);
457
458#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
459extern_conformance!(
460    unsafe impl NSSecureCoding for MPSCNNDropoutGradient {}
461);
462
463#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
464impl MPSCNNDropoutGradient {
465    extern_methods!(
466        /// The probability that each element in the input is kept.
467        /// The valid range is (0.0f, 1.0f).
468        #[unsafe(method(keepProbability))]
469        #[unsafe(method_family = none)]
470        pub unsafe fn keepProbability(&self) -> c_float;
471
472        /// The seed used to generate random numbers.
473        #[unsafe(method(seed))]
474        #[unsafe(method_family = none)]
475        pub unsafe fn seed(&self) -> NSUInteger;
476
477        /// The mask stride in the x, y, and x dimensions, which
478        /// allows for the broadcasting the mask data.
479        ///
480        /// The only valid values are 0 and 1 for each dimension.
481        /// For no broadcasting, set the values for each dimension
482        /// to 1. For broadcasting, set desired values to 0.
483        #[unsafe(method(maskStrideInPixels))]
484        #[unsafe(method_family = none)]
485        pub unsafe fn maskStrideInPixels(&self) -> MTLSize;
486
487        #[unsafe(method(initWithDevice:))]
488        #[unsafe(method_family = init)]
489        pub unsafe fn initWithDevice(
490            this: Allocated<Self>,
491            device: &ProtocolObject<dyn MTLDevice>,
492        ) -> Retained<Self>;
493
494        /// <NSSecureCoding
495        /// > support
496        ///
497        /// # Safety
498        ///
499        /// `a_decoder` possibly has further requirements.
500        #[unsafe(method(initWithCoder:device:))]
501        #[unsafe(method_family = init)]
502        pub unsafe fn initWithCoder_device(
503            this: Allocated<Self>,
504            a_decoder: &NSCoder,
505            device: &ProtocolObject<dyn MTLDevice>,
506        ) -> Option<Retained<Self>>;
507
508        /// Standard init with default properties per filter type.
509        ///
510        /// Parameter `device`: The device that the filter will be used on.
511        ///
512        /// Parameter `keepProbability`: The probability that each element in the input is kept.
513        /// The valid range is (0.0f, 1.0f).
514        ///
515        /// Parameter `seed`: The seed used to generate random numbers.
516        ///
517        /// Parameter `maskStrideInPixels`: The mask stride in the x, y, and z dimensions, which
518        /// allows for the broadcasting of mask data. The only valid
519        /// values are 0 and 1 for each dimension. For no
520        /// broadcasting, set the values for each dimension to 1.
521        /// For broadcasting, set desired values to 0.
522        ///
523        /// Returns: A valid MPSCNNDropoutGradient object or nil, if failure.
524        #[unsafe(method(initWithDevice:keepProbability:seed:maskStrideInPixels:))]
525        #[unsafe(method_family = init)]
526        pub unsafe fn initWithDevice_keepProbability_seed_maskStrideInPixels(
527            this: Allocated<Self>,
528            device: &ProtocolObject<dyn MTLDevice>,
529            keep_probability: c_float,
530            seed: NSUInteger,
531            mask_stride_in_pixels: MTLSize,
532        ) -> Retained<Self>;
533    );
534}
535
536/// Methods declared on superclass `MPSKernel`.
537#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
538impl MPSCNNDropoutGradient {
539    extern_methods!(
540        /// Called by NSCoder to decode MPSKernels
541        ///
542        /// This isn't the right interface to decode a MPSKernel, but
543        /// it is the one that NSCoder uses. To enable your NSCoder
544        /// (e.g. NSKeyedUnarchiver) to set which device to use
545        /// extend the object to adopt the MPSDeviceProvider
546        /// protocol. Otherwise, the Metal system default device
547        /// will be used.
548        ///
549        /// # Safety
550        ///
551        /// `a_decoder` possibly has further requirements.
552        #[unsafe(method(initWithCoder:))]
553        #[unsafe(method_family = init)]
554        pub unsafe fn initWithCoder(
555            this: Allocated<Self>,
556            a_decoder: &NSCoder,
557        ) -> Option<Retained<Self>>;
558    );
559}
560
561/// Methods declared on superclass `NSObject`.
562#[cfg(all(feature = "MPSCNNKernel", feature = "MPSCore", feature = "MPSKernel"))]
563impl MPSCNNDropoutGradient {
564    extern_methods!(
565        #[unsafe(method(init))]
566        #[unsafe(method_family = init)]
567        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
568
569        #[unsafe(method(new))]
570        #[unsafe(method_family = new)]
571        pub unsafe fn new() -> Retained<Self>;
572    );
573}