objc2_metal_performance_shaders/generated/MPSNeuralNetwork/MPSMatrixSum.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 /// MPSMatrixSum performs a pointwise summation of N MPSMatrix
15 /// objects and applies an optional bias term and neuron activation
16 /// function.
17 ///
18 /// MPSMatrix A = empty matrix;
19 /// for (i = 0; i
20 /// <
21 /// N; ++i)
22 /// A += alpha[i]*B[i];
23 ///
24 /// if (bias)
25 /// A += broadcast(bias);
26 ///
27 /// if (neuron)
28 /// A = applyNeuron(A);
29 ///
30 /// Where B is the array of MPSMatrix objects, A is the destination
31 /// MPSMatrix, alpha is an array of scalar values, bias is a vector
32 /// which is broadcast and accumulated across each row of the intermediate
33 /// result, and applyNeuron is a neuron activation function.
34 ///
35 /// Each matrix in the array may have an independent origin.
36 ///
37 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixsum?language=objc)
38 #[unsafe(super(MPSKernel, NSObject))]
39 #[derive(Debug, PartialEq, Eq, Hash)]
40 #[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
41 pub struct MPSMatrixSum;
42);
43
44#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
45extern_conformance!(
46 unsafe impl NSCoding for MPSMatrixSum {}
47);
48
49#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
50extern_conformance!(
51 unsafe impl NSCopying for MPSMatrixSum {}
52);
53
54#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
55unsafe impl CopyingHelper for MPSMatrixSum {
56 type Result = Self;
57}
58
59#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
60extern_conformance!(
61 unsafe impl NSObjectProtocol for MPSMatrixSum {}
62);
63
64#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
65extern_conformance!(
66 unsafe impl NSSecureCoding for MPSMatrixSum {}
67);
68
69#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
70impl MPSMatrixSum {
71 extern_methods!(
72 #[unsafe(method(initWithDevice:))]
73 #[unsafe(method_family = init)]
74 pub unsafe fn initWithDevice(
75 this: Allocated<Self>,
76 device: &ProtocolObject<dyn MTLDevice>,
77 ) -> Retained<Self>;
78
79 /// Initialize a MPSMatrixSum kernel.
80 ///
81 /// Parameter `device`: The device on which to initialize the kernel.
82 ///
83 /// Parameter `count`: The number of matrices to be summed.
84 ///
85 /// Parameter `rows`: The number of rows to use in the input matrices.
86 ///
87 /// Parameter `columns`: The number of columns to use in the input matrices.
88 ///
89 /// Parameter `transpose`: If YES the result of the summation is to be transposed
90 /// prior to applying the bias and activation.
91 #[unsafe(method(initWithDevice:count:rows:columns:transpose:))]
92 #[unsafe(method_family = init)]
93 pub unsafe fn initWithDevice_count_rows_columns_transpose(
94 this: Allocated<Self>,
95 device: &ProtocolObject<dyn MTLDevice>,
96 count: NSUInteger,
97 rows: NSUInteger,
98 columns: NSUInteger,
99 transpose: bool,
100 ) -> Retained<Self>;
101
102 /// The number of rows to sum.
103 #[unsafe(method(rows))]
104 #[unsafe(method_family = none)]
105 pub unsafe fn rows(&self) -> NSUInteger;
106
107 /// The number of columns to sum.
108 #[unsafe(method(columns))]
109 #[unsafe(method_family = none)]
110 pub unsafe fn columns(&self) -> NSUInteger;
111
112 /// The number of matrices to sum.
113 #[unsafe(method(count))]
114 #[unsafe(method_family = none)]
115 pub unsafe fn count(&self) -> NSUInteger;
116
117 /// The transposition used to initialize the kernel.
118 #[unsafe(method(transpose))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn transpose(&self) -> bool;
121
122 /// The origin, relative to [0, 0] in the result matrix, at which to
123 /// start writing results. This property is modifiable and defaults
124 /// to [0, 0] at initialization time. If a different origin is desired
125 /// then this should be modified prior to encoding the kernel.
126 #[unsafe(method(resultMatrixOrigin))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn resultMatrixOrigin(&self) -> MTLOrigin;
129
130 /// Setter for [`resultMatrixOrigin`][Self::resultMatrixOrigin].
131 #[unsafe(method(setResultMatrixOrigin:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn setResultMatrixOrigin(&self, result_matrix_origin: MTLOrigin);
134
135 #[cfg(feature = "MPSCNNNeuronType")]
136 /// Specifies a neuron activation function to be used.
137 ///
138 ///
139 /// This method can be used to add a neuron activation funtion of given type with
140 /// associated scalar parameters A, B, and C that are shared across all output values.
141 /// Note that this method can only be used to specify neurons which are specified by three (or fewer)
142 /// parameters shared across all output values (or channels, in CNN nomenclature). It is an error to call
143 /// this method for neuron activation functions like MPSCNNNeuronTypePReLU,
144 /// which require per-channel parameter values. An MPSMatrixSum kernel is initialized
145 /// with a default neuron function of MPSCNNNeuronTypeNone.
146 ///
147 ///
148 /// Parameter `neuronType`: Type of neuron activation function. For full list see MPSCNNNeuronType.h
149 ///
150 /// Parameter `parameterA`: parameterA of neuron activation that is shared across all output values.
151 ///
152 /// Parameter `parameterB`: parameterB of neuron activation that is shared across all output values.
153 ///
154 /// Parameter `parameterC`: parameterC of neuron activation that is shared across all output values.
155 #[unsafe(method(setNeuronType:parameterA:parameterB:parameterC:))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn setNeuronType_parameterA_parameterB_parameterC(
158 &self,
159 neuron_type: MPSCNNNeuronType,
160 parameter_a: c_float,
161 parameter_b: c_float,
162 parameter_c: c_float,
163 );
164
165 #[cfg(feature = "MPSCNNNeuronType")]
166 /// Getter funtion for neuronType set using setNeuronType:parameterA:parameterB:parameterC method
167 #[unsafe(method(neuronType))]
168 #[unsafe(method_family = none)]
169 pub unsafe fn neuronType(&self) -> MPSCNNNeuronType;
170
171 /// Neuron parameter A.
172 #[unsafe(method(neuronParameterA))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn neuronParameterA(&self) -> c_float;
175
176 /// Neuron parameter B.
177 #[unsafe(method(neuronParameterB))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn neuronParameterB(&self) -> c_float;
180
181 /// Neuron parameter C.
182 #[unsafe(method(neuronParameterC))]
183 #[unsafe(method_family = none)]
184 pub unsafe fn neuronParameterC(&self) -> c_float;
185
186 #[cfg(feature = "MPSMatrix")]
187 /// Encode the operations to the command buffer
188 ///
189 /// Parameter `buffer`: The command buffer in which to encode the operation.
190 ///
191 /// Parameter `sourceMatrices`: A list of matrices from which the matrix data is read.
192 ///
193 /// Parameter `resultMatrix`: The result matrix.
194 ///
195 /// Parameter `scaleVector`: A MPSVector of type MPSDataTypeFloat32 containing the list of
196 /// scale factors, specified in single precision.
197 ///
198 /// Parameter `offsetVector`: A MPSVector of type MPSDataTypeUInt32 containing the list of
199 /// offsets, stored as a packed array of MPSMatrixOffset values.
200 ///
201 /// Parameter `biasVector`: A MPSVector containing the bias terms to add to the result
202 /// prior to applying the neuron function, if any. May be nil.
203 ///
204 /// Parameter `startIndex`: The starting index into the scale and offset vectors.
205 #[unsafe(method(encodeToCommandBuffer:sourceMatrices:resultMatrix:scaleVector:offsetVector:biasVector:startIndex:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn encodeToCommandBuffer_sourceMatrices_resultMatrix_scaleVector_offsetVector_biasVector_startIndex(
208 &self,
209 buffer: &ProtocolObject<dyn MTLCommandBuffer>,
210 source_matrices: &NSArray<MPSMatrix>,
211 result_matrix: &MPSMatrix,
212 scale_vector: Option<&MPSVector>,
213 offset_vector: Option<&MPSVector>,
214 bias_vector: Option<&MPSVector>,
215 start_index: NSUInteger,
216 );
217
218 /// NSSecureCoding compatability
219 ///
220 /// See
221 /// MPSKernel#initWithCoder.
222 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixSum kernel.
223 ///
224 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixSum object.
225 ///
226 /// Returns: A new MPSMatrixSum object, or nil if failure.
227 ///
228 /// # Safety
229 ///
230 /// `a_decoder` possibly has further requirements.
231 #[unsafe(method(initWithCoder:device:))]
232 #[unsafe(method_family = init)]
233 pub unsafe fn initWithCoder_device(
234 this: Allocated<Self>,
235 a_decoder: &NSCoder,
236 device: &ProtocolObject<dyn MTLDevice>,
237 ) -> Option<Retained<Self>>;
238 );
239}
240
241/// Methods declared on superclass `MPSKernel`.
242#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
243impl MPSMatrixSum {
244 extern_methods!(
245 /// Called by NSCoder to decode MPSKernels
246 ///
247 /// This isn't the right interface to decode a MPSKernel, but
248 /// it is the one that NSCoder uses. To enable your NSCoder
249 /// (e.g. NSKeyedUnarchiver) to set which device to use
250 /// extend the object to adopt the MPSDeviceProvider
251 /// protocol. Otherwise, the Metal system default device
252 /// will be used.
253 ///
254 /// # Safety
255 ///
256 /// `a_decoder` possibly has further requirements.
257 #[unsafe(method(initWithCoder:))]
258 #[unsafe(method_family = init)]
259 pub unsafe fn initWithCoder(
260 this: Allocated<Self>,
261 a_decoder: &NSCoder,
262 ) -> Option<Retained<Self>>;
263 );
264}
265
266/// Methods declared on superclass `NSObject`.
267#[cfg(all(feature = "MPSCore", feature = "MPSKernel"))]
268impl MPSMatrixSum {
269 extern_methods!(
270 #[unsafe(method(init))]
271 #[unsafe(method_family = init)]
272 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
273
274 #[unsafe(method(new))]
275 #[unsafe(method_family = new)]
276 pub unsafe fn new() -> Retained<Self>;
277 );
278}