objc2_metal_performance_shaders_graph/generated/
MPSGraphTensorData.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6use objc2_metal::*;
7#[cfg(feature = "objc2-metal-performance-shaders")]
8use objc2_metal_performance_shaders::*;
9
10use crate::*;
11
12extern_class!(
13    /// The representation of a compute data type.
14    ///
15    /// Pass data to a graph using a tensor data, a reference will be taken to your data and used just in time when the graph is run.
16    ///
17    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphtensordata?language=objc)
18    #[unsafe(super(MPSGraphObject, NSObject))]
19    #[derive(Debug, PartialEq, Eq, Hash)]
20    #[cfg(feature = "MPSGraphCore")]
21    pub struct MPSGraphTensorData;
22);
23
24#[cfg(feature = "MPSGraphCore")]
25extern_conformance!(
26    unsafe impl NSObjectProtocol for MPSGraphTensorData {}
27);
28
29#[cfg(feature = "MPSGraphCore")]
30impl MPSGraphTensorData {
31    extern_methods!(
32        #[cfg(feature = "objc2-metal-performance-shaders")]
33        /// The shape of the tensor data.
34        #[unsafe(method(shape))]
35        #[unsafe(method_family = none)]
36        pub unsafe fn shape(&self) -> Retained<MPSShape>;
37
38        #[cfg(feature = "objc2-metal-performance-shaders")]
39        /// The data type of the tensor data.
40        #[unsafe(method(dataType))]
41        #[unsafe(method_family = none)]
42        pub unsafe fn dataType(&self) -> MPSDataType;
43
44        #[cfg(feature = "MPSGraphDevice")]
45        /// The device of the tensor data.
46        #[unsafe(method(device))]
47        #[unsafe(method_family = none)]
48        pub unsafe fn device(&self) -> Retained<MPSGraphDevice>;
49
50        #[cfg(all(
51            feature = "MPSGraphDevice",
52            feature = "objc2-metal-performance-shaders"
53        ))]
54        /// Initializes the tensor data with an `NSData` on a device.
55        ///
56        /// - Parameters:
57        /// - device: MPSDevice on which the MPSGraphTensorData exists
58        /// - data: NSData from which to copy the contents
59        /// - shape: shape of the output tensor
60        /// - dataType: dataType of the placeholder tensor
61        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
62        #[unsafe(method(initWithDevice:data:shape:dataType:))]
63        #[unsafe(method_family = init)]
64        pub unsafe fn initWithDevice_data_shape_dataType(
65            this: Allocated<Self>,
66            device: &MPSGraphDevice,
67            data: &NSData,
68            shape: &MPSShape,
69            data_type: MPSDataType,
70        ) -> Retained<Self>;
71
72        #[cfg(feature = "objc2-metal-performance-shaders")]
73        /// Initializes an tensor data with a metal buffer.
74        ///
75        /// The device of the MTLBuffer will be used to get the MPSDevice for this MPSGraphTensorData.
76        ///
77        /// - Parameters:
78        /// - buffer: MTLBuffer to be used within the MPSGraphTensorData
79        /// - shape: shape of the output tensor
80        /// - dataType: dataType of the placeholder tensor
81        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
82        ///
83        /// # Safety
84        ///
85        /// - `buffer` may need to be synchronized.
86        /// - `buffer` may be unretained, you must ensure it is kept alive while in use.
87        /// - `buffer` contents should be of the correct type.
88        #[unsafe(method(initWithMTLBuffer:shape:dataType:))]
89        #[unsafe(method_family = init)]
90        pub unsafe fn initWithMTLBuffer_shape_dataType(
91            this: Allocated<Self>,
92            buffer: &ProtocolObject<dyn MTLBuffer>,
93            shape: &MPSShape,
94            data_type: MPSDataType,
95        ) -> Retained<Self>;
96
97        #[cfg(feature = "objc2-metal-performance-shaders")]
98        /// Initializes an tensor data with a metal buffer.
99        ///
100        /// The device of the MTLBuffer will be used to get the MPSDevice for this MPSGraphTensorData.
101        ///
102        /// - Parameters:
103        /// - buffer: MTLBuffer to be used within the MPSGraphTensorData
104        /// - shape: shape of the output tensor
105        /// - dataType: dataType of the placeholder tensor
106        /// - rowBytes: rowBytes for the fastest moving dimension, must be larger than or equal to sizeOf(dataType)shape[rank - 1] and must be a multiple of sizeOf(dataType)
107        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
108        ///
109        /// # Safety
110        ///
111        /// - `buffer` may need to be synchronized.
112        /// - `buffer` may be unretained, you must ensure it is kept alive while in use.
113        /// - `buffer` contents should be of the correct type.
114        #[unsafe(method(initWithMTLBuffer:shape:dataType:rowBytes:))]
115        #[unsafe(method_family = init)]
116        pub unsafe fn initWithMTLBuffer_shape_dataType_rowBytes(
117            this: Allocated<Self>,
118            buffer: &ProtocolObject<dyn MTLBuffer>,
119            shape: &MPSShape,
120            data_type: MPSDataType,
121            row_bytes: NSUInteger,
122        ) -> Retained<Self>;
123
124        #[cfg(feature = "objc2-metal-performance-shaders")]
125        /// Initializes a tensor data with an MPS matrix.
126        ///
127        /// The device of the MPSMatrix will be used to get the MPSDevice for this MPSGraphTensorData.
128        ///
129        /// - Parameters:
130        /// - matrix: MPSMatrix to be used within the MPSGraphTensorData
131        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
132        #[unsafe(method(initWithMPSMatrix:))]
133        #[unsafe(method_family = init)]
134        pub unsafe fn initWithMPSMatrix(
135            this: Allocated<Self>,
136            matrix: &MPSMatrix,
137        ) -> Retained<Self>;
138
139        #[cfg(feature = "objc2-metal-performance-shaders")]
140        /// Initializes a tensor data with an MPS matrix enforcing rank of the result.
141        ///
142        /// The device of the MPSMatrix will be used to get the MPSDevice for this MPSGraphTensorData.
143        ///
144        /// - Parameters:
145        /// - matrix: MPSMatrix to be used within the MPSGraphTensorData
146        /// - rank: The rank of the resulting TensorData tensor. NOTE: must be within { 1, ... ,16 }.
147        /// - Returns: A valid MPSGraphTensorData of given rank, or nil if allocation failure.
148        #[unsafe(method(initWithMPSMatrix:rank:))]
149        #[unsafe(method_family = init)]
150        pub unsafe fn initWithMPSMatrix_rank(
151            this: Allocated<Self>,
152            matrix: &MPSMatrix,
153            rank: NSUInteger,
154        ) -> Retained<Self>;
155
156        #[cfg(feature = "objc2-metal-performance-shaders")]
157        /// Initializes a tensor data with an MPS vector.
158        ///
159        /// The device of the MPSVector will be used to get the MPSDevice for this MPSGraphTensorData.
160        ///
161        /// - Parameters:
162        /// - vector: MPSVector to be used within the MPSGraphTensorData
163        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
164        #[unsafe(method(initWithMPSVector:))]
165        #[unsafe(method_family = init)]
166        pub unsafe fn initWithMPSVector(
167            this: Allocated<Self>,
168            vector: &MPSVector,
169        ) -> Retained<Self>;
170
171        #[cfg(feature = "objc2-metal-performance-shaders")]
172        /// Initializes a tensor data with an MPS vector enforcing rank of the result.
173        ///
174        /// The device of the MPSVector will be used to get the MPSDevice for this MPSGraphTensorData.
175        ///
176        /// - Parameters:
177        /// - vector: MPSVector to be used within the MPSGraphTensorData
178        /// - rank: The rank of the resulting TensorData tensor. NOTE: must be within { 1, ... ,16 }.
179        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
180        #[unsafe(method(initWithMPSVector:rank:))]
181        #[unsafe(method_family = init)]
182        pub unsafe fn initWithMPSVector_rank(
183            this: Allocated<Self>,
184            vector: &MPSVector,
185            rank: NSUInteger,
186        ) -> Retained<Self>;
187
188        #[cfg(feature = "objc2-metal-performance-shaders")]
189        /// Initializes an MPSGraphTensorData with an MPS ndarray.
190        ///
191        /// The device of the MPSNDArray will be used to get the MPSDevice for this MPSGraphTensorData.
192        ///
193        /// - Parameters:
194        /// - ndarray: MPSNDArray to be used within the MPSGraphTensorData.
195        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
196        #[unsafe(method(initWithMPSNDArray:))]
197        #[unsafe(method_family = init)]
198        pub unsafe fn initWithMPSNDArray(
199            this: Allocated<Self>,
200            ndarray: &MPSNDArray,
201        ) -> Retained<Self>;
202
203        #[cfg(feature = "objc2-metal-performance-shaders")]
204        /// Initializes a tensor data with an MPS image batch.
205        ///
206        /// The dataLayout used will be NHWC, call a transpose or permute to change to a layout of your choice.
207        ///
208        /// - Parameters:
209        /// - imageBatch: The device on which the kernel will run, unorm8 and unorm16 images will create a float32 tensorData
210        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
211        #[unsafe(method(initWithMPSImageBatch:))]
212        #[unsafe(method_family = init)]
213        pub unsafe fn initWithMPSImageBatch(
214            this: Allocated<Self>,
215            image_batch: &MPSImageBatch,
216        ) -> Retained<Self>;
217
218        /// Initializes an MPSGraphTensorData with an MTLTensor.
219        ///
220        /// The internal storage of the MTLTensor will be aliased. Requires tensor to support MTLTensorUsageMachineLearning.
221        ///
222        /// - Parameters:
223        /// - tensor: MTLTensor to be used within the MPSGraphTensorData
224        /// - Returns: A valid MPSGraphTensorData, or nil if allocation failure.
225        ///
226        /// # Safety
227        ///
228        /// - `tensor` may need to be synchronized.
229        /// - `tensor` may be unretained, you must ensure it is kept alive while in use.
230        #[unsafe(method(initWithMTLTensor:))]
231        #[unsafe(method_family = init)]
232        pub unsafe fn initWithMTLTensor(
233            this: Allocated<Self>,
234            tensor: &ProtocolObject<dyn MTLTensor>,
235        ) -> Retained<Self>;
236
237        #[cfg(feature = "objc2-metal-performance-shaders")]
238        /// Return an mpsndarray object will copy contents if the contents are not stored in an MPS ndarray.
239        ///
240        /// - Returns: A valid MPSNDArray, or nil if allocation fails.
241        #[unsafe(method(mpsndarray))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn mpsndarray(&self) -> Retained<MPSNDArray>;
244    );
245}
246
247/// Methods declared on superclass `NSObject`.
248#[cfg(feature = "MPSGraphCore")]
249impl MPSGraphTensorData {
250    extern_methods!(
251        #[unsafe(method(init))]
252        #[unsafe(method_family = init)]
253        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
254
255        #[unsafe(method(new))]
256        #[unsafe(method_family = new)]
257        pub unsafe fn new() -> Retained<Self>;
258    );
259}