objc2_metal_performance_shaders/generated/MPSMatrix/
MPSMatrixMultiplication.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 matrix multiplication kernel.
16    ///
17    ///
18    /// A MPSMatrixMultiplication object computes:
19    ///
20    /// C = alpha * op(A) * op(B) + beta * C
21    ///
22    /// A, B, and C are matrices which are represented by MPSMatrix
23    /// objects. alpha and beta are scalar values (of the same data type
24    /// as values of C) which are applied as shown above.  A and B may
25    /// each have an optional transposition operation applied.
26    ///
27    /// A, B, and C (also referred to in later discussions as the left input
28    /// matrix, the right input matrix, and the result matrix respectively).
29    ///
30    /// A MPSMatrixMultiplication object is initialized with the transpose
31    /// operators to apply to A and B, sizes for the operation to perform,
32    /// and the scalar values alpha and beta.
33    ///
34    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixmultiplication?language=objc)
35    #[unsafe(super(MPSKernel, NSObject))]
36    #[derive(Debug, PartialEq, Eq, Hash)]
37    #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
38    pub struct MPSMatrixMultiplication;
39);
40
41#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
42extern_conformance!(
43    unsafe impl NSCoding for MPSMatrixMultiplication {}
44);
45
46#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
47extern_conformance!(
48    unsafe impl NSCopying for MPSMatrixMultiplication {}
49);
50
51#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
52unsafe impl CopyingHelper for MPSMatrixMultiplication {
53    type Result = Self;
54}
55
56#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
57extern_conformance!(
58    unsafe impl NSObjectProtocol for MPSMatrixMultiplication {}
59);
60
61#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
62extern_conformance!(
63    unsafe impl NSSecureCoding for MPSMatrixMultiplication {}
64);
65
66#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
67impl MPSMatrixMultiplication {
68    extern_methods!(
69        /// The origin, relative to [0, 0] in the result matrix, at which to
70        /// start writing (and reading if necessary) results.  This property is
71        /// modifiable and defaults to [0, 0] at initialization time.  If a
72        /// different origin is desired then this should be modified prior to
73        /// encoding the kernel.  The z value must be 0.
74        #[unsafe(method(resultMatrixOrigin))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn resultMatrixOrigin(&self) -> MTLOrigin;
77
78        /// Setter for [`resultMatrixOrigin`][Self::resultMatrixOrigin].
79        #[unsafe(method(setResultMatrixOrigin:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn setResultMatrixOrigin(&self, result_matrix_origin: MTLOrigin);
82
83        /// The origin, relative to [0, 0] in the left input matrix, at which to
84        /// start reading values.  This property is modifiable and defaults to
85        /// [0, 0] at initialization time.  If a different origin is desired then
86        /// this should be modified prior to encoding the kernel.  The z value
87        /// must be 0.
88        #[unsafe(method(leftMatrixOrigin))]
89        #[unsafe(method_family = none)]
90        pub unsafe fn leftMatrixOrigin(&self) -> MTLOrigin;
91
92        /// Setter for [`leftMatrixOrigin`][Self::leftMatrixOrigin].
93        #[unsafe(method(setLeftMatrixOrigin:))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn setLeftMatrixOrigin(&self, left_matrix_origin: MTLOrigin);
96
97        /// The origin, relative to [0, 0] in the right input matrix, at which to
98        /// start reading values.  This property is modifiable and defaults to
99        /// [0, 0] at initialization time.  If a different origin is desired then
100        /// this should be modified prior to encoding the kernel.  The z value
101        /// must be 0.
102        #[unsafe(method(rightMatrixOrigin))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn rightMatrixOrigin(&self) -> MTLOrigin;
105
106        /// Setter for [`rightMatrixOrigin`][Self::rightMatrixOrigin].
107        #[unsafe(method(setRightMatrixOrigin:))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn setRightMatrixOrigin(&self, right_matrix_origin: MTLOrigin);
110
111        /// The index of the first matrix in the batch.  This property is
112        /// modifiable and defaults to 0 at initialization time.  If
113        /// batch processing should begin at a different matrix this value
114        /// should be modified prior to encoding the kernel.
115        #[unsafe(method(batchStart))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn batchStart(&self) -> NSUInteger;
118
119        /// Setter for [`batchStart`][Self::batchStart].
120        #[unsafe(method(setBatchStart:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn setBatchStart(&self, batch_start: NSUInteger);
123
124        /// The number of matrices in the batch to process.  This property
125        /// is modifiable and by default allows all matrices available at
126        /// encoding time to be processed.
127        #[unsafe(method(batchSize))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn batchSize(&self) -> NSUInteger;
130
131        /// Setter for [`batchSize`][Self::batchSize].
132        #[unsafe(method(setBatchSize:))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn setBatchSize(&self, batch_size: NSUInteger);
135
136        /// Initialize an MPSMatrixMultiplication object on a device for a given size
137        /// and desired transpose and scale values.
138        ///
139        ///
140        /// Parameter `device`: The device on which the kernel will execute.
141        ///
142        ///
143        /// Parameter `transposeLeft`: A boolean value which indicates if the left input matrix should be
144        /// used in transposed form.  If 'YES' then op(A) = A**T, otherwise
145        /// op(A) = A.
146        ///
147        ///
148        /// Parameter `transposeRight`: A boolean value which indicates if the right input matrix should be
149        /// used in transposed form.  If 'YES' then op(B) = B**T, otherwise
150        /// op(B) = B.
151        ///
152        ///
153        /// Parameter `resultRows`: The number of rows in the result matrix, M in BLAS GEMM description.
154        ///
155        ///
156        /// Parameter `resultColumns`: The number of columns in the result matrix, N in BLAS GEMM description.
157        ///
158        ///
159        /// Parameter `interiorColumns`: The number of columns of the left input matrix after the
160        /// appropriate transpose operation has been applied. K in BLAS
161        /// GEMM description.
162        ///
163        ///
164        /// Parameter `alpha`: The scale factor to apply to the product.  Specified in double
165        /// precision.  Will be converted to the appropriate precision in the
166        /// implementation subject to rounding and/or clamping as necessary.
167        ///
168        ///
169        /// Parameter `beta`: The scale factor to apply to the initial values of C.  Specified
170        /// in double precision.  Will be converted to the appropriate precision in the
171        /// implementation subject to rounding and/or clamping as necessary.
172        ///
173        ///
174        /// Returns: A valid MPSMatrixMultiplication object or nil, if failure.
175        #[unsafe(method(initWithDevice:transposeLeft:transposeRight:resultRows:resultColumns:interiorColumns:alpha:beta:))]
176        #[unsafe(method_family = init)]
177        pub unsafe fn initWithDevice_transposeLeft_transposeRight_resultRows_resultColumns_interiorColumns_alpha_beta(
178            this: Allocated<Self>,
179            device: &ProtocolObject<dyn MTLDevice>,
180            transpose_left: bool,
181            transpose_right: bool,
182            result_rows: NSUInteger,
183            result_columns: NSUInteger,
184            interior_columns: NSUInteger,
185            alpha: c_double,
186            beta: c_double,
187        ) -> Retained<Self>;
188
189        /// Convenience initialization for a matrix-matrix multiplication
190        /// with no transpositions, unit scaling of the product, and no
191        /// accumulation of the result.  The scaling factors alpha and beta
192        /// are taken to be 1.0 and 0.0 respectively.
193        ///
194        ///
195        /// Parameter `device`: The device on which the kernel will execute.
196        ///
197        ///
198        /// Parameter `resultRows`: The number of rows in the result matrix, M in BLAS GEMM description.
199        ///
200        ///
201        /// Parameter `resultColumns`: The number of columns in the result matrix, N in BLAS GEMM description.
202        ///
203        ///
204        /// Parameter `interiorColumns`: The number of columns of the left input matrix. K in BLAS
205        /// GEMM description.
206        ///
207        ///
208        /// Returns: A valid MPSMatrixMultiplication object or nil, if failure.
209        #[unsafe(method(initWithDevice:resultRows:resultColumns:interiorColumns:))]
210        #[unsafe(method_family = init)]
211        pub unsafe fn initWithDevice_resultRows_resultColumns_interiorColumns(
212            this: Allocated<Self>,
213            device: &ProtocolObject<dyn MTLDevice>,
214            result_rows: NSUInteger,
215            result_columns: NSUInteger,
216            interior_columns: NSUInteger,
217        ) -> Retained<Self>;
218
219        /// Use the above initialization method instead.
220        #[unsafe(method(initWithDevice:))]
221        #[unsafe(method_family = init)]
222        pub unsafe fn initWithDevice(
223            this: Allocated<Self>,
224            device: &ProtocolObject<dyn MTLDevice>,
225        ) -> Retained<Self>;
226
227        /// Encode a MPSMatrixMultiplication object to a command buffer.
228        ///
229        ///
230        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
231        ///
232        ///
233        /// Parameter `leftMatrix`: A valid MPSMatrix object which specifies the left input matrix.
234        ///
235        ///
236        /// Parameter `rightMatrix`: A valid MPSMatrix object which specifies the right input matrix.
237        ///
238        ///
239        /// Parameter `resultMatrix`: A valid MPSMatrix object which specifies the addend matrix which will
240        /// also be overwritten by the result.
241        ///
242        ///
243        /// Certain constraints apply to the sizes of the matrices depending on the transposition
244        /// operations and sizes requested at initialization time as well as the origins at the time
245        /// this routine is called:
246        ///
247        /// The left input matrix must be large enough to hold an array of size resultRows x interiorColumns
248        /// elements beginning at leftMatrixOrigin.
249        ///
250        /// The right input matrix must be large enough to hold an array of size interiorColumns x resultColumns
251        /// elements beginning at rightMatrixOrigin.
252        ///
253        /// The result matrix must be large enough to hold an array of size resultRows x resultColumns
254        /// elements beginning at resultMatrixOrigin.
255        ///
256        /// Each matrix within the range specified by batchStart and batchSize, which also specifies
257        /// a valid set of matrices within leftMatrix, rightMatrix, and resultMatrix, will
258        /// be processed.
259        #[unsafe(method(encodeToCommandBuffer:leftMatrix:rightMatrix:resultMatrix:))]
260        #[unsafe(method_family = none)]
261        pub unsafe fn encodeToCommandBuffer_leftMatrix_rightMatrix_resultMatrix(
262            &self,
263            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
264            left_matrix: &MPSMatrix,
265            right_matrix: &MPSMatrix,
266            result_matrix: &MPSMatrix,
267        );
268    );
269}
270
271/// Methods declared on superclass `MPSKernel`.
272#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
273impl MPSMatrixMultiplication {
274    extern_methods!(
275        /// Called by NSCoder to decode MPSKernels
276        ///
277        /// This isn't the right interface to decode a MPSKernel, but
278        /// it is the one that NSCoder uses. To enable your NSCoder
279        /// (e.g. NSKeyedUnarchiver) to set which device to use
280        /// extend the object to adopt the MPSDeviceProvider
281        /// protocol. Otherwise, the Metal system default device
282        /// will be used.
283        ///
284        /// # Safety
285        ///
286        /// `a_decoder` possibly has further requirements.
287        #[unsafe(method(initWithCoder:))]
288        #[unsafe(method_family = init)]
289        pub unsafe fn initWithCoder(
290            this: Allocated<Self>,
291            a_decoder: &NSCoder,
292        ) -> Option<Retained<Self>>;
293
294        /// NSSecureCoding compatability
295        ///
296        /// While the standard NSSecureCoding/NSCoding method
297        /// -initWithCoder: should work, since the file can't
298        /// know which device your data is allocated on, we
299        /// have to guess and may guess incorrectly.  To avoid
300        /// that problem, use initWithCoder:device instead.
301        ///
302        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
303        ///
304        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
305        ///
306        /// Returns: A new MPSKernel object, or nil if failure.
307        ///
308        /// # Safety
309        ///
310        /// `a_decoder` possibly has further requirements.
311        #[unsafe(method(initWithCoder:device:))]
312        #[unsafe(method_family = init)]
313        pub unsafe fn initWithCoder_device(
314            this: Allocated<Self>,
315            a_decoder: &NSCoder,
316            device: &ProtocolObject<dyn MTLDevice>,
317        ) -> Option<Retained<Self>>;
318    );
319}
320
321/// Methods declared on superclass `NSObject`.
322#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
323impl MPSMatrixMultiplication {
324    extern_methods!(
325        #[unsafe(method(init))]
326        #[unsafe(method_family = init)]
327        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
328
329        #[unsafe(method(new))]
330        #[unsafe(method_family = new)]
331        pub unsafe fn new() -> Retained<Self>;
332    );
333}
334
335extern_class!(
336    /// Dependencies: This depends on Metal.framework.
337    ///
338    ///
339    /// A matrix-vector multiplication kernel.
340    ///
341    ///
342    /// A MPSMatrixVectorMultiplication object computes:
343    ///
344    /// y = alpha * op(A) * x + beta * y
345    ///
346    /// A is a matrix represented by a MPSMatrix object. alpha and beta
347    /// are scalar values (of the same data type as values of y) which are
348    /// applied as shown above.  A may have an optional transposition
349    /// operation applied.
350    ///
351    /// A MPSMatrixVectorMultiplication object is initialized with the transpose
352    /// operator to apply to A, sizes for the operation to perform,
353    /// and the scalar values alpha and beta.
354    ///
355    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixvectormultiplication?language=objc)
356    #[unsafe(super(MPSMatrixBinaryKernel, MPSKernel, NSObject))]
357    #[derive(Debug, PartialEq, Eq, Hash)]
358    #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
359    pub struct MPSMatrixVectorMultiplication;
360);
361
362#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
363extern_conformance!(
364    unsafe impl NSCoding for MPSMatrixVectorMultiplication {}
365);
366
367#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
368extern_conformance!(
369    unsafe impl NSCopying for MPSMatrixVectorMultiplication {}
370);
371
372#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
373unsafe impl CopyingHelper for MPSMatrixVectorMultiplication {
374    type Result = Self;
375}
376
377#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
378extern_conformance!(
379    unsafe impl NSObjectProtocol for MPSMatrixVectorMultiplication {}
380);
381
382#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
383extern_conformance!(
384    unsafe impl NSSecureCoding for MPSMatrixVectorMultiplication {}
385);
386
387#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
388impl MPSMatrixVectorMultiplication {
389    extern_methods!(
390        /// Initialize an MPSMatrixVectorMultiplication object on a device for a given size
391        /// and desired transpose and scale values.
392        ///
393        ///
394        /// Parameter `device`: The device on which the kernel will execute.
395        ///
396        ///
397        /// Parameter `transpose`: A boolean value which indicates if the input matrix should be
398        /// used in transposed form.  if 'YES' then op(A) == A**T, otherwise
399        /// op(A) == A.
400        ///
401        ///
402        /// Parameter `rows`: The number of rows in the input matrix op(A), and the number of elements
403        /// in the vector y.
404        ///
405        ///
406        /// Parameter `columns`: The number of columns in the input matrix op(A), and the number of
407        /// elements in the input vector x.
408        ///
409        ///
410        /// Parameter `alpha`: The scale factor to apply to the product.  Specified in double
411        /// precision.  Will be converted to the appropriate precision in the
412        /// implementation subject to rounding and/or clamping as necessary.
413        ///
414        ///
415        /// Parameter `beta`: The scale factor to apply to the initial values of y.  Specified
416        /// in double precision.  Will be converted to the appropriate precision in the
417        /// implementation subject to rounding and/or clamping as necessary.
418        ///
419        ///
420        /// Returns: A valid MPSMatrixVectorMultiplication object or nil, if failure.
421        #[unsafe(method(initWithDevice:transpose:rows:columns:alpha:beta:))]
422        #[unsafe(method_family = init)]
423        pub unsafe fn initWithDevice_transpose_rows_columns_alpha_beta(
424            this: Allocated<Self>,
425            device: &ProtocolObject<dyn MTLDevice>,
426            transpose: bool,
427            rows: NSUInteger,
428            columns: NSUInteger,
429            alpha: c_double,
430            beta: c_double,
431        ) -> Retained<Self>;
432
433        /// Convenience initialization for a matrix-vector multiplication
434        /// with no transposition, unit scaling of the product, and no
435        /// accumulation of the result.  The scaling factors alpha and beta
436        /// are taken to be 1.0 and 0.0 respectively.
437        ///
438        ///
439        /// Parameter `device`: The device on which the kernel will execute.
440        ///
441        ///
442        /// Parameter `rows`: The number of rows in the input matrix A, and the number of elements
443        /// in the vector y.
444        ///
445        ///
446        /// Parameter `columns`: The number of columns in the input matrix A, and the number of
447        /// elements in the input vector x.
448        ///
449        ///
450        /// Returns: A valid MPSMatrixVectorMultiplication object or nil, if failure.
451        #[unsafe(method(initWithDevice:rows:columns:))]
452        #[unsafe(method_family = init)]
453        pub unsafe fn initWithDevice_rows_columns(
454            this: Allocated<Self>,
455            device: &ProtocolObject<dyn MTLDevice>,
456            rows: NSUInteger,
457            columns: NSUInteger,
458        ) -> Retained<Self>;
459
460        /// Use the above initialization method instead.
461        #[unsafe(method(initWithDevice:))]
462        #[unsafe(method_family = init)]
463        pub unsafe fn initWithDevice(
464            this: Allocated<Self>,
465            device: &ProtocolObject<dyn MTLDevice>,
466        ) -> Retained<Self>;
467
468        /// Encode a MPSMatrixVectorMultiplication object to a command buffer.
469        ///
470        ///
471        /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
472        ///
473        ///
474        /// Parameter `inputMatrix`: A valid MPSMatrix object which specifies the input matrix A.
475        ///
476        ///
477        /// Parameter `inputVector`: A valid MPSVector object which specifies the input vector x.
478        ///
479        ///
480        /// Parameter `resultVector`: A valid MPSVector object which specifies the addend vector which will
481        /// also be overwritten by the result.
482        ///
483        ///
484        /// The left input matrix must be large enough to hold an array of size (rows x columns)
485        /// elements beginning at primarySourceMatrixOrigin.
486        ///
487        /// The input vector must be large enough to hold an array of size (columns)
488        /// elements beginning at secondarySourceMatrixOrigin.x  secondarySourceMatrixOrigin.y and
489        /// secondarySourceMatrixOrigin.z must be zero.
490        ///
491        /// The result vector must be large enough to hold an array of size (rows)
492        /// elements beginning at resultMatrixOrigin.x.  resultMatrixOrigin.y and
493        /// resultMatrixOrigin.z must be zero.
494        #[unsafe(method(encodeToCommandBuffer:inputMatrix:inputVector:resultVector:))]
495        #[unsafe(method_family = none)]
496        pub unsafe fn encodeToCommandBuffer_inputMatrix_inputVector_resultVector(
497            &self,
498            command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
499            input_matrix: &MPSMatrix,
500            input_vector: &MPSVector,
501            result_vector: &MPSVector,
502        );
503    );
504}
505
506/// Methods declared on superclass `MPSKernel`.
507#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
508impl MPSMatrixVectorMultiplication {
509    extern_methods!(
510        /// Called by NSCoder to decode MPSKernels
511        ///
512        /// This isn't the right interface to decode a MPSKernel, but
513        /// it is the one that NSCoder uses. To enable your NSCoder
514        /// (e.g. NSKeyedUnarchiver) to set which device to use
515        /// extend the object to adopt the MPSDeviceProvider
516        /// protocol. Otherwise, the Metal system default device
517        /// will be used.
518        ///
519        /// # Safety
520        ///
521        /// `a_decoder` possibly has further requirements.
522        #[unsafe(method(initWithCoder:))]
523        #[unsafe(method_family = init)]
524        pub unsafe fn initWithCoder(
525            this: Allocated<Self>,
526            a_decoder: &NSCoder,
527        ) -> Option<Retained<Self>>;
528
529        /// NSSecureCoding compatability
530        ///
531        /// While the standard NSSecureCoding/NSCoding method
532        /// -initWithCoder: should work, since the file can't
533        /// know which device your data is allocated on, we
534        /// have to guess and may guess incorrectly.  To avoid
535        /// that problem, use initWithCoder:device instead.
536        ///
537        /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSKernel
538        ///
539        /// Parameter `device`: The MTLDevice on which to make the MPSKernel
540        ///
541        /// Returns: A new MPSKernel object, or nil if failure.
542        ///
543        /// # Safety
544        ///
545        /// `a_decoder` possibly has further requirements.
546        #[unsafe(method(initWithCoder:device:))]
547        #[unsafe(method_family = init)]
548        pub unsafe fn initWithCoder_device(
549            this: Allocated<Self>,
550            a_decoder: &NSCoder,
551            device: &ProtocolObject<dyn MTLDevice>,
552        ) -> Option<Retained<Self>>;
553    );
554}
555
556/// Methods declared on superclass `NSObject`.
557#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
558impl MPSMatrixVectorMultiplication {
559    extern_methods!(
560        #[unsafe(method(init))]
561        #[unsafe(method_family = init)]
562        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
563
564        #[unsafe(method(new))]
565        #[unsafe(method_family = new)]
566        pub unsafe fn new() -> Retained<Self>;
567    );
568}