objc2_metal_performance_shaders/generated/MPSMatrix/MPSMatrixSoftMax.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 softmax kernel that operates on matrices.
16 ///
17 ///
18 /// A MPSMatrixSoftMax object computes:
19 ///
20 /// B_ij = Exp { A_ij } / ( Sum_k Exp { A_ik } )
21 ///
22 /// A and B are matrices which are represented by MPSMatrix
23 /// objects. This filter computes the same result for MPSMatrices as
24 /// MPSCNNSoftMax filter does for MPSImages by interpreting the columns
25 /// of the matrix as feature channels, that is the sum runs over column indices.
26 ///
27 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixsoftmax?language=objc)
28 #[unsafe(super(MPSMatrixUnaryKernel, MPSKernel, NSObject))]
29 #[derive(Debug, PartialEq, Eq, Hash)]
30 #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
31 pub struct MPSMatrixSoftMax;
32);
33
34#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
35extern_conformance!(
36 unsafe impl NSCoding for MPSMatrixSoftMax {}
37);
38
39#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
40extern_conformance!(
41 unsafe impl NSCopying for MPSMatrixSoftMax {}
42);
43
44#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
45unsafe impl CopyingHelper for MPSMatrixSoftMax {
46 type Result = Self;
47}
48
49#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
50extern_conformance!(
51 unsafe impl NSObjectProtocol for MPSMatrixSoftMax {}
52);
53
54#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
55extern_conformance!(
56 unsafe impl NSSecureCoding for MPSMatrixSoftMax {}
57);
58
59#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
60impl MPSMatrixSoftMax {
61 extern_methods!(
62 /// The number of rows to consider from the source in the operation.
63 /// This property is modifiable and defaults to NSUIntegerMax and the number is
64 /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
65 /// fit into the source matrix available starting from sourceMatrixOrigin.x,
66 /// indicating that by default the whole source matrix is used.
67 /// If a different size is desired then this should be modified prior to
68 /// encoding the kernel. It is the user's responsibility to ensure that the
69 /// resultMatrix parameter in encodeToCommandBuffer is large enough
70 /// to accommodate the results of this operation, otherwise the results of
71 /// the encode call are undefined.
72 /// NOTE: sourceMatrixOrigin and resultMatrixOrigin from MPSMatrixUnaryKernel
73 /// can be used to control the starting points in the source and destination
74 /// at kernel encode time (see encodeToCommandBuffer).
75 #[unsafe(method(sourceRows))]
76 #[unsafe(method_family = none)]
77 pub unsafe fn sourceRows(&self) -> NSUInteger;
78
79 /// Setter for [`sourceRows`][Self::sourceRows].
80 #[unsafe(method(setSourceRows:))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn setSourceRows(&self, source_rows: NSUInteger);
83
84 /// The number of columns to consider from the source in the operation.
85 /// This property is modifiable and defaults to NSUIntegerMax and the number is
86 /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
87 /// fit into the source matrix available starting from sourceMatrixOrigin.y,
88 /// indicating that by default the whole source matrix is used.
89 /// If a different size is desired then this should be modified prior to
90 /// encoding the kernel. It is the user's responsibility to ensure that the
91 /// resultMatrix parameter in encodeToCommandBuffer is large enough
92 /// to accommodate the results of this operation, otherwise the results of
93 /// the encode call are undefined.
94 /// NOTE: sourceMatrixOrigin and resultMatrixOrigin from MPSMatrixUnaryKernel
95 /// can be used to control the starting points in the source and destination
96 /// at kernel encode time (see encodeToCommandBuffer).
97 #[unsafe(method(sourceColumns))]
98 #[unsafe(method_family = none)]
99 pub unsafe fn sourceColumns(&self) -> NSUInteger;
100
101 /// Setter for [`sourceColumns`][Self::sourceColumns].
102 #[unsafe(method(setSourceColumns:))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn setSourceColumns(&self, source_columns: NSUInteger);
105
106 /// Initialize an MPSMatrixSoftMax object on a device for a given size.
107 ///
108 ///
109 /// Parameter `device`: The device on which the kernel will execute.
110 ///
111 ///
112 /// Returns: A valid MPSMatrixSoftMax object or nil, if failure.
113 #[unsafe(method(initWithDevice:))]
114 #[unsafe(method_family = init)]
115 pub unsafe fn initWithDevice(
116 this: Allocated<Self>,
117 device: &ProtocolObject<dyn MTLDevice>,
118 ) -> Retained<Self>;
119
120 /// Encode a MPSMatrixSoftMax object to a command buffer.
121 ///
122 ///
123 /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
124 ///
125 ///
126 /// Parameter `inputMatrix`: A valid MPSMatrix object which specifies the input matrix.
127 ///
128 ///
129 /// Parameter `resultMatrix`: A valid MPSMatrix object which specifies the matrix which will
130 /// be overwritten by the result.
131 ///
132 ///
133 /// Certain constraints apply to the sizes of the matrices depending on the sizes requested at
134 /// initialization time as well as the origins at the time this routine is called:
135 ///
136 /// The result matrix must be large enough to hold a two dimensional array of 'sourceRows' rows and
137 /// 'sourceColumns' columns beginning at resultMatrixOrigin.
138 ///
139 /// Each matrix within the range specified by batchStart and batchSize, which also specifies
140 /// a valid set of matrices within inputMatrix and resultMatrix, will
141 /// be processed.
142 ///
143 /// The datatypes of the matrices inputMatrix and resultMatrix must match and be either
144 /// MPSDataTypeFloat32 or MPSDataTypeFloat16.
145 #[unsafe(method(encodeToCommandBuffer:inputMatrix:resultMatrix:))]
146 #[unsafe(method_family = none)]
147 pub unsafe fn encodeToCommandBuffer_inputMatrix_resultMatrix(
148 &self,
149 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
150 input_matrix: &MPSMatrix,
151 result_matrix: &MPSMatrix,
152 );
153
154 /// NSSecureCoding compatability
155 ///
156 /// See
157 /// MPSKernel#initWithCoder.
158 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixSoftMax
159 ///
160 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixSoftMax
161 ///
162 /// Returns: A new MPSMatrixSoftMax object, or nil if failure.
163 ///
164 /// # Safety
165 ///
166 /// `a_decoder` possibly has further requirements.
167 #[unsafe(method(initWithCoder:device:))]
168 #[unsafe(method_family = init)]
169 pub unsafe fn initWithCoder_device(
170 this: Allocated<Self>,
171 a_decoder: &NSCoder,
172 device: &ProtocolObject<dyn MTLDevice>,
173 ) -> Option<Retained<Self>>;
174
175 /// Make a copy of this kernel for a new device -
176 ///
177 /// See: MPSKernel
178 ///
179 /// Parameter `zone`: The NSZone in which to allocate the object
180 ///
181 /// Parameter `device`: The device for the new MPSKernel. If nil, then use
182 /// self.device.
183 ///
184 /// Returns: a pointer to a copy of this MPSKernel. This will fail, returning
185 /// nil if the device is not supported. Devices must be
186 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
187 ///
188 /// # Safety
189 ///
190 /// `zone` must be a valid pointer or null.
191 #[unsafe(method(copyWithZone:device:))]
192 #[unsafe(method_family = copy)]
193 pub unsafe fn copyWithZone_device(
194 &self,
195 zone: *mut NSZone,
196 device: Option<&ProtocolObject<dyn MTLDevice>>,
197 ) -> Retained<Self>;
198 );
199}
200
201/// Methods declared on superclass `MPSKernel`.
202#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
203impl MPSMatrixSoftMax {
204 extern_methods!(
205 /// Called by NSCoder to decode MPSKernels
206 ///
207 /// This isn't the right interface to decode a MPSKernel, but
208 /// it is the one that NSCoder uses. To enable your NSCoder
209 /// (e.g. NSKeyedUnarchiver) to set which device to use
210 /// extend the object to adopt the MPSDeviceProvider
211 /// protocol. Otherwise, the Metal system default device
212 /// will be used.
213 ///
214 /// # Safety
215 ///
216 /// `a_decoder` possibly has further requirements.
217 #[unsafe(method(initWithCoder:))]
218 #[unsafe(method_family = init)]
219 pub unsafe fn initWithCoder(
220 this: Allocated<Self>,
221 a_decoder: &NSCoder,
222 ) -> Option<Retained<Self>>;
223 );
224}
225
226/// Methods declared on superclass `NSObject`.
227#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
228impl MPSMatrixSoftMax {
229 extern_methods!(
230 #[unsafe(method(init))]
231 #[unsafe(method_family = init)]
232 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
233
234 #[unsafe(method(new))]
235 #[unsafe(method_family = new)]
236 pub unsafe fn new() -> Retained<Self>;
237 );
238}
239
240extern_class!(
241 /// Dependencies: This depends on Metal.framework.
242 ///
243 ///
244 /// A logarithmic softmax kernel that operates on matrices.
245 ///
246 ///
247 /// A MPSMatrixLogSoftMax object computes:
248 ///
249 /// B_ij = ln { Exp { A_ij } / ( Sum_k Exp { A_ik } ) } = A_ij - ln { Sum_k Exp { A_ik } }
250 ///
251 /// A and B are matrices which are represented by MPSMatrix
252 /// objects. This filter computes the same result for MPSMatrices as
253 /// MPSCNNLogSoftMax filter does for MPSImages by interpreting the columns
254 /// of the matrix as feature channels, that is the sum runs over column indices.
255 ///
256 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixlogsoftmax?language=objc)
257 #[unsafe(super(MPSMatrixSoftMax, MPSMatrixUnaryKernel, MPSKernel, NSObject))]
258 #[derive(Debug, PartialEq, Eq, Hash)]
259 #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
260 pub struct MPSMatrixLogSoftMax;
261);
262
263#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
264extern_conformance!(
265 unsafe impl NSCoding for MPSMatrixLogSoftMax {}
266);
267
268#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
269extern_conformance!(
270 unsafe impl NSCopying for MPSMatrixLogSoftMax {}
271);
272
273#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
274unsafe impl CopyingHelper for MPSMatrixLogSoftMax {
275 type Result = Self;
276}
277
278#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
279extern_conformance!(
280 unsafe impl NSObjectProtocol for MPSMatrixLogSoftMax {}
281);
282
283#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
284extern_conformance!(
285 unsafe impl NSSecureCoding for MPSMatrixLogSoftMax {}
286);
287
288#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
289impl MPSMatrixLogSoftMax {
290 extern_methods!();
291}
292
293/// Methods declared on superclass `MPSMatrixSoftMax`.
294#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
295impl MPSMatrixLogSoftMax {
296 extern_methods!(
297 /// Initialize an MPSMatrixSoftMax object on a device for a given size.
298 ///
299 ///
300 /// Parameter `device`: The device on which the kernel will execute.
301 ///
302 ///
303 /// Returns: A valid MPSMatrixSoftMax object or nil, if failure.
304 #[unsafe(method(initWithDevice:))]
305 #[unsafe(method_family = init)]
306 pub unsafe fn initWithDevice(
307 this: Allocated<Self>,
308 device: &ProtocolObject<dyn MTLDevice>,
309 ) -> Retained<Self>;
310
311 /// NSSecureCoding compatability
312 ///
313 /// See
314 /// MPSKernel#initWithCoder.
315 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixSoftMax
316 ///
317 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixSoftMax
318 ///
319 /// Returns: A new MPSMatrixSoftMax object, or nil if failure.
320 ///
321 /// # Safety
322 ///
323 /// `a_decoder` possibly has further requirements.
324 #[unsafe(method(initWithCoder:device:))]
325 #[unsafe(method_family = init)]
326 pub unsafe fn initWithCoder_device(
327 this: Allocated<Self>,
328 a_decoder: &NSCoder,
329 device: &ProtocolObject<dyn MTLDevice>,
330 ) -> Option<Retained<Self>>;
331 );
332}
333
334/// Methods declared on superclass `MPSKernel`.
335#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
336impl MPSMatrixLogSoftMax {
337 extern_methods!(
338 /// Called by NSCoder to decode MPSKernels
339 ///
340 /// This isn't the right interface to decode a MPSKernel, but
341 /// it is the one that NSCoder uses. To enable your NSCoder
342 /// (e.g. NSKeyedUnarchiver) to set which device to use
343 /// extend the object to adopt the MPSDeviceProvider
344 /// protocol. Otherwise, the Metal system default device
345 /// will be used.
346 ///
347 /// # Safety
348 ///
349 /// `a_decoder` possibly has further requirements.
350 #[unsafe(method(initWithCoder:))]
351 #[unsafe(method_family = init)]
352 pub unsafe fn initWithCoder(
353 this: Allocated<Self>,
354 a_decoder: &NSCoder,
355 ) -> Option<Retained<Self>>;
356 );
357}
358
359/// Methods declared on superclass `NSObject`.
360#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
361impl MPSMatrixLogSoftMax {
362 extern_methods!(
363 #[unsafe(method(init))]
364 #[unsafe(method_family = init)]
365 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
366
367 #[unsafe(method(new))]
368 #[unsafe(method_family = new)]
369 pub unsafe fn new() -> Retained<Self>;
370 );
371}
372
373extern_class!(
374 /// Dependencies: This depends on Metal.framework.
375 ///
376 ///
377 /// Computes the gradient corresponding to a forward MPSMatrixSoftMax object.
378 ///
379 ///
380 /// A MPSMatrixSoftMaxGradient object computes:
381 ///
382 /// dL_dX_ij = Y_ij * (dL_dY_ij - sum_k(dL_dY_ik * Y_ik)
383 ///
384 /// Where dL_dX is the resulting gradient of the loss function with respect to
385 /// the original input to the forward MPSMatrixSoftMax operation, Y is
386 /// the output of the forward MPSMatrixSoftMax operation, and dL_dY is the
387 /// gradient of the loss function with respect to Y.
388 ///
389 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixsoftmaxgradient?language=objc)
390 #[unsafe(super(MPSMatrixBinaryKernel, MPSKernel, NSObject))]
391 #[derive(Debug, PartialEq, Eq, Hash)]
392 #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
393 pub struct MPSMatrixSoftMaxGradient;
394);
395
396#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
397extern_conformance!(
398 unsafe impl NSCoding for MPSMatrixSoftMaxGradient {}
399);
400
401#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
402extern_conformance!(
403 unsafe impl NSCopying for MPSMatrixSoftMaxGradient {}
404);
405
406#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
407unsafe impl CopyingHelper for MPSMatrixSoftMaxGradient {
408 type Result = Self;
409}
410
411#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
412extern_conformance!(
413 unsafe impl NSObjectProtocol for MPSMatrixSoftMaxGradient {}
414);
415
416#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
417extern_conformance!(
418 unsafe impl NSSecureCoding for MPSMatrixSoftMaxGradient {}
419);
420
421#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
422impl MPSMatrixSoftMaxGradient {
423 extern_methods!(
424 /// The number of rows to consider from the sources in the operation.
425 /// This property is modifiable and defaults to NSUIntegerMax and the number is
426 /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
427 /// fit into the source matrices available starting from
428 /// [primary/secondary]SourceMatrixOrigin.x, indicating that by default the
429 /// whole source matrix is used. If a different size is desired then this should
430 /// be modified prior to encoding the kernel. It is the user's responsibility to
431 /// ensure that the resultMatrix parameter in encodeToCommandBuffer is large enough
432 /// to accommodate the results of this operation, otherwise the results of
433 /// the encode call are undefined.
434 /// NOTE: primarySourceMatrixOrigin, secondarySourceMatrixOrigin and resultMatrixOrigin
435 /// from MPSMatrixBinaryKernel can be used to control the starting points in the primary
436 /// source, secondary source, and result matrices respectively.
437 #[unsafe(method(sourceRows))]
438 #[unsafe(method_family = none)]
439 pub unsafe fn sourceRows(&self) -> NSUInteger;
440
441 /// Setter for [`sourceRows`][Self::sourceRows].
442 #[unsafe(method(setSourceRows:))]
443 #[unsafe(method_family = none)]
444 pub unsafe fn setSourceRows(&self, source_rows: NSUInteger);
445
446 /// The number of columns to consider from the sources in the operation.
447 /// This property is modifiable and defaults to NSUIntegerMax and the number is
448 /// adjusted dynamically at kernel encode time (see encodeToCommandBuffer) to
449 /// fit into the source matrices available starting from [primary/secondary]SourceMatrixOrigin.y,
450 /// indicating that by default the whole source matrix is used.
451 /// If a different size is desired then this should be modified prior to
452 /// encoding the kernel. It is the user's responsibility to ensure that the
453 /// resultMatrix parameter in encodeToCommandBuffer is large enough
454 /// to accommodate the results of this operation, otherwise the results of
455 /// the encode call are undefined.
456 /// NOTE: primarySourceMatrixOrigin, secondarySourceMatrixOrigin and resultMatrixOrigin
457 /// from MPSMatrixBinaryKernel can be used to control the starting points in the primary
458 /// source, secondary source, and result matrices respectively.
459 #[unsafe(method(sourceColumns))]
460 #[unsafe(method_family = none)]
461 pub unsafe fn sourceColumns(&self) -> NSUInteger;
462
463 /// Setter for [`sourceColumns`][Self::sourceColumns].
464 #[unsafe(method(setSourceColumns:))]
465 #[unsafe(method_family = none)]
466 pub unsafe fn setSourceColumns(&self, source_columns: NSUInteger);
467
468 /// Initialize an MPSMatrixSoftMaxGradient object on a device.
469 ///
470 ///
471 /// Parameter `device`: The device on which the kernel will execute.
472 ///
473 ///
474 /// Returns: A valid MPSMatrixSoftMaxGradient object or nil, if failure.
475 #[unsafe(method(initWithDevice:))]
476 #[unsafe(method_family = init)]
477 pub unsafe fn initWithDevice(
478 this: Allocated<Self>,
479 device: &ProtocolObject<dyn MTLDevice>,
480 ) -> Retained<Self>;
481
482 /// Encode a MPSMatrixSoftMaxGradient object to a command buffer.
483 ///
484 ///
485 /// Parameter `commandBuffer`: A valid MTLCommandBuffer to receive the encoded kernel.
486 ///
487 ///
488 /// Parameter `gradientMatrix`: A MPSMatrix object containing gradient values with respect
489 /// to the forward operation's output. dL_dY in the class
490 /// description.
491 ///
492 ///
493 /// Parameter `forwardOutputMatrix`: A MPSMatrix object containing the output values from the
494 /// forward operation. Y in the class description.
495 ///
496 ///
497 /// Parameter `resultMatrix`: The MPSMatrix object to hold the resulting gradient values
498 /// with respect to the forward operation's input. dL_dX in the
499 /// class description.
500 #[unsafe(method(encodeToCommandBuffer:gradientMatrix:forwardOutputMatrix:resultMatrix:))]
501 #[unsafe(method_family = none)]
502 pub unsafe fn encodeToCommandBuffer_gradientMatrix_forwardOutputMatrix_resultMatrix(
503 &self,
504 command_buffer: &ProtocolObject<dyn MTLCommandBuffer>,
505 gradient_matrix: &MPSMatrix,
506 forward_output_matrix: &MPSMatrix,
507 result_matrix: &MPSMatrix,
508 );
509
510 /// NSSecureCoding compatability
511 ///
512 /// See
513 /// MPSKernel#initWithCoder.
514 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixSoftMaxGradient
515 ///
516 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixSoftMaxGradient
517 ///
518 /// Returns: A new MPSMatrixSoftMaxGradient object, or nil if failure.
519 ///
520 /// # Safety
521 ///
522 /// `a_decoder` possibly has further requirements.
523 #[unsafe(method(initWithCoder:device:))]
524 #[unsafe(method_family = init)]
525 pub unsafe fn initWithCoder_device(
526 this: Allocated<Self>,
527 a_decoder: &NSCoder,
528 device: &ProtocolObject<dyn MTLDevice>,
529 ) -> Option<Retained<Self>>;
530
531 /// Make a copy of this kernel for a new device -
532 ///
533 /// See: MPSKernel
534 ///
535 /// Parameter `zone`: The NSZone in which to allocate the object
536 ///
537 /// Parameter `device`: The device for the new MPSKernel. If nil, then use
538 /// self.device.
539 ///
540 /// Returns: a pointer to a copy of this MPSKernel. This will fail, returning
541 /// nil if the device is not supported. Devices must be
542 /// MTLFeatureSet_iOS_GPUFamily2_v1 or later.
543 ///
544 /// # Safety
545 ///
546 /// `zone` must be a valid pointer or null.
547 #[unsafe(method(copyWithZone:device:))]
548 #[unsafe(method_family = copy)]
549 pub unsafe fn copyWithZone_device(
550 &self,
551 zone: *mut NSZone,
552 device: Option<&ProtocolObject<dyn MTLDevice>>,
553 ) -> Retained<Self>;
554 );
555}
556
557/// Methods declared on superclass `MPSKernel`.
558#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
559impl MPSMatrixSoftMaxGradient {
560 extern_methods!(
561 /// Called by NSCoder to decode MPSKernels
562 ///
563 /// This isn't the right interface to decode a MPSKernel, but
564 /// it is the one that NSCoder uses. To enable your NSCoder
565 /// (e.g. NSKeyedUnarchiver) to set which device to use
566 /// extend the object to adopt the MPSDeviceProvider
567 /// protocol. Otherwise, the Metal system default device
568 /// will be used.
569 ///
570 /// # Safety
571 ///
572 /// `a_decoder` possibly has further requirements.
573 #[unsafe(method(initWithCoder:))]
574 #[unsafe(method_family = init)]
575 pub unsafe fn initWithCoder(
576 this: Allocated<Self>,
577 a_decoder: &NSCoder,
578 ) -> Option<Retained<Self>>;
579 );
580}
581
582/// Methods declared on superclass `NSObject`.
583#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
584impl MPSMatrixSoftMaxGradient {
585 extern_methods!(
586 #[unsafe(method(init))]
587 #[unsafe(method_family = init)]
588 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
589
590 #[unsafe(method(new))]
591 #[unsafe(method_family = new)]
592 pub unsafe fn new() -> Retained<Self>;
593 );
594}
595
596extern_class!(
597 /// Dependencies: This depends on Metal.framework.
598 ///
599 ///
600 /// Computes the gradient corresponding to a forward MPSMatrixLogSoftMax object.
601 ///
602 ///
603 /// A MPSMatrixLogSoftMaxGradient object computes:
604 ///
605 /// dL_dX_ij = dL_dY_ij - exp(Y_ij * sum_k(dL_dY_ik))
606 ///
607 /// Where dL_dX is the resulting gradient of the loss function with respect to
608 /// the original input to the forward MPSMatrixLogSoftMax operation, Y is
609 /// the output of the forward MPSMatrixLogSoftMax operation, and dL_dY is the
610 /// gradient of the loss function with respect to Y.
611 ///
612 /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixlogsoftmaxgradient?language=objc)
613 #[unsafe(super(MPSMatrixSoftMaxGradient, MPSMatrixBinaryKernel, MPSKernel, NSObject))]
614 #[derive(Debug, PartialEq, Eq, Hash)]
615 #[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
616 pub struct MPSMatrixLogSoftMaxGradient;
617);
618
619#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
620extern_conformance!(
621 unsafe impl NSCoding for MPSMatrixLogSoftMaxGradient {}
622);
623
624#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
625extern_conformance!(
626 unsafe impl NSCopying for MPSMatrixLogSoftMaxGradient {}
627);
628
629#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
630unsafe impl CopyingHelper for MPSMatrixLogSoftMaxGradient {
631 type Result = Self;
632}
633
634#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
635extern_conformance!(
636 unsafe impl NSObjectProtocol for MPSMatrixLogSoftMaxGradient {}
637);
638
639#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
640extern_conformance!(
641 unsafe impl NSSecureCoding for MPSMatrixLogSoftMaxGradient {}
642);
643
644#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
645impl MPSMatrixLogSoftMaxGradient {
646 extern_methods!();
647}
648
649/// Methods declared on superclass `MPSMatrixSoftMaxGradient`.
650#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
651impl MPSMatrixLogSoftMaxGradient {
652 extern_methods!(
653 /// Initialize an MPSMatrixSoftMaxGradient object on a device.
654 ///
655 ///
656 /// Parameter `device`: The device on which the kernel will execute.
657 ///
658 ///
659 /// Returns: A valid MPSMatrixSoftMaxGradient object or nil, if failure.
660 #[unsafe(method(initWithDevice:))]
661 #[unsafe(method_family = init)]
662 pub unsafe fn initWithDevice(
663 this: Allocated<Self>,
664 device: &ProtocolObject<dyn MTLDevice>,
665 ) -> Retained<Self>;
666
667 /// NSSecureCoding compatability
668 ///
669 /// See
670 /// MPSKernel#initWithCoder.
671 /// Parameter `aDecoder`: The NSCoder subclass with your serialized MPSMatrixSoftMaxGradient
672 ///
673 /// Parameter `device`: The MTLDevice on which to make the MPSMatrixSoftMaxGradient
674 ///
675 /// Returns: A new MPSMatrixSoftMaxGradient object, or nil if failure.
676 ///
677 /// # Safety
678 ///
679 /// `a_decoder` possibly has further requirements.
680 #[unsafe(method(initWithCoder:device:))]
681 #[unsafe(method_family = init)]
682 pub unsafe fn initWithCoder_device(
683 this: Allocated<Self>,
684 a_decoder: &NSCoder,
685 device: &ProtocolObject<dyn MTLDevice>,
686 ) -> Option<Retained<Self>>;
687 );
688}
689
690/// Methods declared on superclass `MPSKernel`.
691#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
692impl MPSMatrixLogSoftMaxGradient {
693 extern_methods!(
694 /// Called by NSCoder to decode MPSKernels
695 ///
696 /// This isn't the right interface to decode a MPSKernel, but
697 /// it is the one that NSCoder uses. To enable your NSCoder
698 /// (e.g. NSKeyedUnarchiver) to set which device to use
699 /// extend the object to adopt the MPSDeviceProvider
700 /// protocol. Otherwise, the Metal system default device
701 /// will be used.
702 ///
703 /// # Safety
704 ///
705 /// `a_decoder` possibly has further requirements.
706 #[unsafe(method(initWithCoder:))]
707 #[unsafe(method_family = init)]
708 pub unsafe fn initWithCoder(
709 this: Allocated<Self>,
710 a_decoder: &NSCoder,
711 ) -> Option<Retained<Self>>;
712 );
713}
714
715/// Methods declared on superclass `NSObject`.
716#[cfg(all(feature = "MPSCore", feature = "MPSKernel", feature = "MPSMatrixTypes"))]
717impl MPSMatrixLogSoftMaxGradient {
718 extern_methods!(
719 #[unsafe(method(init))]
720 #[unsafe(method_family = init)]
721 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
722
723 #[unsafe(method(new))]
724 #[unsafe(method_family = new)]
725 pub unsafe fn new() -> Retained<Self>;
726 );
727}