objc2_metal_performance_shaders/generated/MPSMatrix/
MPSMatrixFindTopK.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    ///
15    /// A kernel that find top-K values and their corresponding indices withing a row of a matrix
16    ///
17    ///
18    /// A MPSMatrixFindTopK object computes finds the 'k' largest values within
19    /// a row of a matrix and returns the value found and the index of the entry
20    /// in the source matrix. This operation is performed independently on the
21    /// rows and matrices in batch of the source matrix.
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixfindtopk?language=objc)
24    #[unsafe(super(MPSMatrixUnaryKernel, MPSKernel, NSObject))]
25    #[derive(Debug, PartialEq, Eq, Hash)]
26    #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
27    pub struct MPSMatrixFindTopK;
28);
29
30#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
31extern_conformance!(
32    unsafe impl NSCoding for MPSMatrixFindTopK {}
33);
34
35#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
36extern_conformance!(
37    unsafe impl NSCopying for MPSMatrixFindTopK {}
38);
39
40#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
41unsafe impl CopyingHelper for MPSMatrixFindTopK {
42    type Result = Self;
43}
44
45#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
46extern_conformance!(
47    unsafe impl NSObjectProtocol for MPSMatrixFindTopK {}
48);
49
50#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
51extern_conformance!(
52    unsafe impl NSSecureCoding for MPSMatrixFindTopK {}
53);
54
55#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
56impl MPSMatrixFindTopK {
57    extern_methods!(
58        /// The number of rows to consider from the source in the operation.
59        /// This property is modifiable and defaults to NSUIntegerMax and the number is
60        /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
61        /// fit into the source matrix available starting from sourceMatrixOrigin.x,
62        /// indicating that by default the whole source matrix is used.
63        /// If a different size is desired then this should be modified prior to
64        /// encoding the kernel.
65        /// It is the user's responsibility to ensure that the resultIndexMatrix and resultValueMatrix
66        /// parameters in encodeToCommandBuffer are large enough to accommodate the results of this
67        /// operation, otherwise the results of the encode call are undefined.
68        /// NOTE: sourceMatrixOrigin and resultMatrixOrigin from MPSMatrixUnaryKernel
69        /// can be used to control the starting points in the source and destination
70        /// at kernel encode time (see encodeToCommandBuffer).
71        #[unsafe(method(sourceRows))]
72        #[unsafe(method_family = none)]
73        pub unsafe fn sourceRows(&self) -> NSUInteger;
74
75        /// Setter for [`sourceRows`][Self::sourceRows].
76        #[unsafe(method(setSourceRows:))]
77        #[unsafe(method_family = none)]
78        pub unsafe fn setSourceRows(&self, source_rows: NSUInteger);
79
80        /// The number of columns to consider from the source in the operation.
81        /// This property is modifiable and defaults to NSUIntegerMax and the number is
82        /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
83        /// fit into the source matrix available starting from sourceMatrixOrigin.y,
84        /// indicating that by default the whole source matrix is used.
85        /// If a different size is desired then this should be modified prior to
86        /// encoding the kernel.
87        /// It is the user's responsibility to ensure that the resultIndexMatrix and resultValueMatrix
88        /// parameters in encodeToCommandBuffer are large enough to accommodate the results of this
89        /// operation, otherwise the results of the encode call are undefined.
90        /// NOTE: sourceMatrixOrigin and resultMatrixOrigin from MPSMatrixUnaryKernel
91        /// can be used to control the starting points in the source and destination
92        /// at kernel encode time (see encodeToCommandBuffer).
93        #[unsafe(method(sourceColumns))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn sourceColumns(&self) -> NSUInteger;
96
97        /// Setter for [`sourceColumns`][Self::sourceColumns].
98        #[unsafe(method(setSourceColumns:))]
99        #[unsafe(method_family = none)]
100        pub unsafe fn setSourceColumns(&self, source_columns: NSUInteger);
101
102        /// Specifies a number that will be added to all the indices written to
103        /// resultIndexMatrix in encodeToCommandBuffer. This value can be used
104        /// to offset later computations for example by adding the value for
105        /// the source matrix column offset sourceMatrixOrigin.y.
106        /// Example: Let numberOfTopKValues be 3, let the source be the following:
107        ///
108        /// source = [ 6.0, 3.0, 8.0, 1.0, 9.0, 4.0, 5.0 ]
109        ///
110        /// and let the sourceMatrixOrigin.y = 2.
111        ///
112        /// Then if indexOffset = 2 then the result value and result index matrices will be:
113        ///
114        /// result values  = [ 9.0, 8.0, 5.0 ]
115        /// result indices = [  4 ,  2 ,  6  ],
116        ///
117        /// which gives the user indices into the original source matrix.
118        ///
119        /// On the other hand if the indexOffset = 0 then the results  are as follows:
120        ///
121        /// result values  = [ 9.0, 8.0, 5.0 ]
122        /// result indices = [  2 ,  0 ,  4  ],
123        ///
124        /// which on the other hand gives the user indices into the submatrix starting
125        /// from sourceMatrixOrigin.y == 2.
126        ///
127        /// This property is modifiable and defaults to 0. If a different behavior
128        /// is desired then this should be modified prior to encoding the kernel.
129        #[unsafe(method(indexOffset))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn indexOffset(&self) -> NSUInteger;
132
133        /// Setter for [`indexOffset`][Self::indexOffset].
134        #[unsafe(method(setIndexOffset:))]
135        #[unsafe(method_family = none)]
136        pub unsafe fn setIndexOffset(&self, index_offset: NSUInteger);
137
138        /// The number of highest values (and their indices) to be found in each row
139        /// by the kernel. This property is initialized in the kernel initialization call
140        /// initWithDevice, but can be modified before encoding the kernel.
141        /// Must be less or equal to 16 and requesting more values results in undefined behavior.
142        /// It is the user's responsibility to ensure that the resultIndexMatrix and resultValueMatrix
143        /// parameters in encodeToCommandBuffer are large enough to accommodate the results of this
144        /// operation, otherwise the results of the encode call are undefined.
145        #[unsafe(method(numberOfTopKValues))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn numberOfTopKValues(&self) -> NSUInteger;
148
149        /// Setter for [`numberOfTopKValues`][Self::numberOfTopKValues].
150        #[unsafe(method(setNumberOfTopKValues:))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn setNumberOfTopKValues(&self, number_of_top_k_values: NSUInteger);
153
154        /// Initialize an MPSMatrixFindTopK object on a device for a given size.
155        ///
156        ///
157        /// Parameter `device`: The device on which the kernel will execute.
158        ///
159        /// Parameter `numberOfTopKValues`: The number of largest values to find from each row,
160        /// must be less or equal to 16.
161        ///
162        ///
163        /// Returns: A valid MPSMatrixFindTopK object or nil, if failure.
164        #[unsafe(method(initWithDevice:numberOfTopKValues:))]
165        #[unsafe(method_family = init)]
166        pub unsafe fn initWithDevice_numberOfTopKValues(
167            this: Allocated<Self>,
168            device: &ProtocolObject<dyn MTLDevice>,
169            number_of_top_k_values: NSUInteger,
170        ) -> Retained<Self>;
171
172        /// Use the above initialization method instead.
173        #[unsafe(method(initWithDevice:))]
174        #[unsafe(method_family = init)]
175        pub unsafe fn initWithDevice(
176            this: Allocated<Self>,
177            device: &ProtocolObject<dyn MTLDevice>,
178        ) -> Retained<Self>;
179
180        /// Encode a MPSMatrixFindTopK object to a command buffer.
181        ///
182        ///
183        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
184        ///
185        ///
186        /// Parameter `inputMatrix`: A valid MPSMatrix object which specifies the input matrix.
187        ///
188        ///
189        /// Parameter `resultIndexMatrix`: A valid MPSMatrix object which specifies the matrix which will
190        /// be overwritten by the result indices.
191        /// This matrix must have datatype MPSDataTypeUInt32.
192        ///
193        /// Parameter `resultValueMatrix`: A valid MPSMatrix object which specifies the matrix which will
194        /// be overwritten by the result values.
195        ///
196        ///
197        /// Certain constraints apply to the sizes of the matrices depending on the sizes requested at
198        /// initialization time as well as the origins at the time this routine is called:
199        ///
200        /// Both result matrices must be large enough to hold a two dimensional array of 'sourceRows' rows and
201        /// 'numberOfTopKValues' columns beginning at resultMatrixOrigin.
202        ///
203        /// The source matrix must be large enough to contain at least 'numberOfTopKValues' values
204        /// starting from sourceMatrixOrigin.y.
205        ///
206        /// Each matrix within the range specified by batchStart and batchSize, which also specifies a valid
207        /// set of matrices within inputMatrix, resultIndexMatrix and resultValueMatrix, will be processed.
208        ///
209        /// The datatypes of the matrices inputMatrix and resultValueMatrix must match and be either
210        /// MPSDataTypeFloat32 or MPSDataTypeFloat16.
211        #[unsafe(method(encodeToCommandBuffer:inputMatrix:resultIndexMatrix:resultValueMatrix:))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn encodeToCommandBuffer_inputMatrix_resultIndexMatrix_resultValueMatrix(
214            &self,
215            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
216            input_matrix: &MPSMatrix,
217            result_index_matrix: &MPSMatrix,
218            result_value_matrix: &MPSMatrix,
219        );
220
221        /// NSSecureCoding compatability
222        ///
223        /// See
224        /// MPSKernel#initWithCoder.
225        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixFindTopK
226        ///
227        /// Parameter `device`: The MTLDevice on which to make the MPSMatrixFindTopK
228        ///
229        /// Returns: A new MPSMatrixFindTopK object, or nil if failure.
230        ///
231        /// # Safety
232        ///
233        /// `a_decoder` possibly has further requirements.
234        #[unsafe(method(initWithCoder:device:))]
235        #[unsafe(method_family = init)]
236        pub unsafe fn initWithCoder_device(
237            this: Allocated<Self>,
238            a_decoder: &NSCoder,
239            device: &ProtocolObject<dyn MTLDevice>,
240        ) -> Option<Retained<Self>>;
241
242        /// Make a copy of this kernel for a new device -
243        ///
244        /// See: MPSKernel
245        ///
246        /// Parameter `zone`: The NSZone in which to allocate the object
247        ///
248        /// Parameter `device`: The device for the new MPSKernel. If nil, then use
249        /// self.device.
250        ///
251        /// Returns: a pointer to a copy of this MPSKernel. This will fail, returning
252        /// nil if the device is not supported. Devices must be
253        /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
254        ///
255        /// # Safety
256        ///
257        /// `zone` must be a valid pointer or null.
258        #[unsafe(method(copyWithZone:device:))]
259        #[unsafe(method_family = copy)]
260        pub unsafe fn copyWithZone_device(
261            &self,
262            zone: *mut NSZone,
263            device: Option<&ProtocolObject<dyn MTLDevice>>,
264        ) -> Retained<Self>;
265    );
266}
267
268/// Methods declared on superclass `MPSKernel`.
269#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
270impl MPSMatrixFindTopK {
271    extern_methods!(
272        /// Called by NSCoder to decode MPSKernels
273        ///
274        /// This isn't the right interface to decode a MPSKernel, but
275        /// it is the one that NSCoder uses. To enable your NSCoder
276        /// (e.g. NSKeyedUnarchiver) to set which device to use
277        /// extend the object to adopt the MPSDeviceProvider
278        /// protocol. Otherwise, the Metal system default device
279        /// will be used.
280        ///
281        /// # Safety
282        ///
283        /// `a_decoder` possibly has further requirements.
284        #[unsafe(method(initWithCoder:))]
285        #[unsafe(method_family = init)]
286        pub unsafe fn initWithCoder(
287            this: Allocated<Self>,
288            a_decoder: &NSCoder,
289        ) -> Option<Retained<Self>>;
290    );
291}
292
293/// Methods declared on superclass `NSObject`.
294#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
295impl MPSMatrixFindTopK {
296    extern_methods!(
297        #[unsafe(method(init))]
298        #[unsafe(method_family = init)]
299        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
300
301        #[unsafe(method(new))]
302        #[unsafe(method_family = new)]
303        pub unsafe fn new() -> Retained<Self>;
304    );
305}