objc2_ml_compute/generated/MLCTensor.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::*;
7
8use crate::*;
9
10extern_class!(
11 /// A tensor object
12 ///
13 /// See also [Apple's documentation](https://developer.apple.com/documentation/mlcompute/mlctensor?language=objc)
14 #[unsafe(super(NSObject))]
15 #[derive(Debug, PartialEq, Eq, Hash)]
16 #[deprecated]
17 pub struct MLCTensor;
18);
19
20extern_conformance!(
21 unsafe impl NSCopying for MLCTensor {}
22);
23
24unsafe impl CopyingHelper for MLCTensor {
25 type Result = Self;
26}
27
28extern_conformance!(
29 unsafe impl NSObjectProtocol for MLCTensor {}
30);
31
32impl MLCTensor {
33 extern_methods!(
34 /// The tensor ID
35 ///
36 /// A unique number to identify each tensor. Assigned when the tensor is created.
37 #[deprecated]
38 #[unsafe(method(tensorID))]
39 #[unsafe(method_family = none)]
40 pub unsafe fn tensorID(&self) -> NSUInteger;
41
42 #[cfg(feature = "MLCTensorDescriptor")]
43 /// The tensor descriptor
44 #[deprecated]
45 #[unsafe(method(descriptor))]
46 #[unsafe(method_family = none)]
47 pub unsafe fn descriptor(&self) -> Retained<MLCTensorDescriptor>;
48
49 /// The tensor data
50 #[deprecated]
51 #[unsafe(method(data))]
52 #[unsafe(method_family = none)]
53 pub unsafe fn data(&self) -> Option<Retained<NSData>>;
54
55 /// A string to help identify this object.
56 #[deprecated]
57 #[unsafe(method(label))]
58 #[unsafe(method_family = none)]
59 pub unsafe fn label(&self) -> Retained<NSString>;
60
61 /// Setter for [`label`][Self::label].
62 ///
63 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
64 #[deprecated]
65 #[unsafe(method(setLabel:))]
66 #[unsafe(method_family = none)]
67 pub unsafe fn setLabel(&self, label: &NSString);
68
69 #[cfg(feature = "MLCDevice")]
70 /// The device associated with this tensor.
71 #[deprecated]
72 #[unsafe(method(device))]
73 #[unsafe(method_family = none)]
74 pub unsafe fn device(&self) -> Option<Retained<MLCDevice>>;
75
76 #[cfg(feature = "MLCTensorData")]
77 /// These are the host side optimizer (momentum and velocity) buffers which developers can query and initialize
78 ///
79 /// When customizing optimizer data, the contents of these buffers must be initialized before executing optimizer
80 /// update for a graph.
81 #[deprecated]
82 #[unsafe(method(optimizerData))]
83 #[unsafe(method_family = none)]
84 pub unsafe fn optimizerData(&self) -> Retained<NSArray<MLCTensorData>>;
85
86 #[cfg(feature = "MLCTensorOptimizerDeviceData")]
87 /// These are the device side optimizer (momentum and velocity) buffers which developers can query
88 #[deprecated]
89 #[unsafe(method(optimizerDeviceData))]
90 #[unsafe(method_family = none)]
91 pub unsafe fn optimizerDeviceData(&self)
92 -> Retained<NSArray<MLCTensorOptimizerDeviceData>>;
93
94 #[deprecated]
95 #[unsafe(method(new))]
96 #[unsafe(method_family = new)]
97 pub unsafe fn new() -> Retained<Self>;
98
99 #[deprecated]
100 #[unsafe(method(init))]
101 #[unsafe(method_family = init)]
102 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
103
104 #[cfg(feature = "MLCTensorDescriptor")]
105 /// Create a MLCTensor object
106 ///
107 /// Create a tensor object without any data
108 ///
109 /// Returns: A new MLCTensor object
110 #[deprecated]
111 #[unsafe(method(tensorWithDescriptor:))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn tensorWithDescriptor(
114 tensor_descriptor: &MLCTensorDescriptor,
115 ) -> Retained<Self>;
116
117 #[cfg(all(feature = "MLCTensorDescriptor", feature = "MLCTypes"))]
118 /// Create a MLCTensor object
119 ///
120 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
121 ///
122 /// Parameter `tensorDescriptor`: The tensor descriptor
123 ///
124 /// Parameter `randomInitializerType`: The random initializer type
125 ///
126 /// Returns: A new MLCTensor object
127 #[deprecated]
128 #[unsafe(method(tensorWithDescriptor:randomInitializerType:))]
129 #[unsafe(method_family = none)]
130 pub unsafe fn tensorWithDescriptor_randomInitializerType(
131 tensor_descriptor: &MLCTensorDescriptor,
132 random_initializer_type: MLCRandomInitializerType,
133 ) -> Retained<Self>;
134
135 #[cfg(feature = "MLCTensorDescriptor")]
136 /// Create a MLCTensor object
137 ///
138 /// Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
139 ///
140 /// Parameter `tensorDescriptor`: The tensor descriptor
141 ///
142 /// Parameter `fillData`: The scalar data to fill to tensor with
143 ///
144 /// Returns: A new MLCTensor object
145 #[deprecated]
146 #[unsafe(method(tensorWithDescriptor:fillWithData:))]
147 #[unsafe(method_family = none)]
148 pub unsafe fn tensorWithDescriptor_fillWithData(
149 tensor_descriptor: &MLCTensorDescriptor,
150 fill_data: &NSNumber,
151 ) -> Retained<Self>;
152
153 #[cfg(all(feature = "MLCTensorData", feature = "MLCTensorDescriptor"))]
154 /// Create a MLCTensor object
155 ///
156 /// Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
157 ///
158 /// Parameter `tensorDescriptor`: The tensor descriptor
159 ///
160 /// Parameter `data`: The random initializer type
161 ///
162 /// Returns: A new MLCTensor object
163 #[deprecated]
164 #[unsafe(method(tensorWithDescriptor:data:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn tensorWithDescriptor_data(
167 tensor_descriptor: &MLCTensorDescriptor,
168 data: &MLCTensorData,
169 ) -> Retained<Self>;
170
171 /// Create a MLCTensor object
172 ///
173 /// Create a tensor object without any data. The tensor data type is MLCDataTypeFloat32.
174 ///
175 /// Parameter `shape`: The tensor shape
176 ///
177 /// Returns: A new MLCTensor object
178 #[deprecated]
179 #[unsafe(method(tensorWithShape:))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn tensorWithShape(shape: &NSArray<NSNumber>) -> Retained<Self>;
182
183 #[cfg(feature = "MLCTypes")]
184 /// Create a MLCTensor object
185 ///
186 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
187 /// The tensor data type is MLCDataTypeFloat32
188 ///
189 /// Parameter `shape`: The tensor shape
190 ///
191 /// Parameter `randomInitializerType`: The random initializer type
192 ///
193 /// Returns: A new MLCTensor object
194 #[deprecated]
195 #[unsafe(method(tensorWithShape:randomInitializerType:))]
196 #[unsafe(method_family = none)]
197 pub unsafe fn tensorWithShape_randomInitializerType(
198 shape: &NSArray<NSNumber>,
199 random_initializer_type: MLCRandomInitializerType,
200 ) -> Retained<Self>;
201
202 #[cfg(feature = "MLCTypes")]
203 /// Create a MLCTensor object
204 ///
205 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
206 /// The tensor data type is MLCDataTypeFloat32
207 ///
208 /// Parameter `shape`: The tensor shape
209 ///
210 /// Parameter `randomInitializerType`: The random initializer type
211 ///
212 /// Parameter `dataType`: The tensor data type
213 ///
214 /// Returns: A new MLCTensor object
215 #[deprecated]
216 #[unsafe(method(tensorWithShape:randomInitializerType:dataType:))]
217 #[unsafe(method_family = none)]
218 pub unsafe fn tensorWithShape_randomInitializerType_dataType(
219 shape: &NSArray<NSNumber>,
220 random_initializer_type: MLCRandomInitializerType,
221 data_type: MLCDataType,
222 ) -> Retained<Self>;
223
224 #[cfg(feature = "MLCTypes")]
225 /// Create a MLCTensor object
226 ///
227 /// Create a tensor object without any data
228 ///
229 /// Parameter `shape`: The tensor shape
230 ///
231 /// Parameter `dataType`: The tensor data type
232 ///
233 /// Returns: A new MLCTensor object
234 #[deprecated]
235 #[unsafe(method(tensorWithShape:dataType:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn tensorWithShape_dataType(
238 shape: &NSArray<NSNumber>,
239 data_type: MLCDataType,
240 ) -> Retained<Self>;
241
242 #[cfg(all(feature = "MLCTensorData", feature = "MLCTypes"))]
243 /// Create a MLCTensor object
244 ///
245 /// Create a tensor object with data
246 ///
247 /// Parameter `shape`: The tensor shape
248 ///
249 /// Parameter `data`: The tensor data
250 ///
251 /// Parameter `dataType`: The tensor data type
252 ///
253 /// Returns: A new MLCTensor object
254 #[deprecated]
255 #[unsafe(method(tensorWithShape:data:dataType:))]
256 #[unsafe(method_family = none)]
257 pub unsafe fn tensorWithShape_data_dataType(
258 shape: &NSArray<NSNumber>,
259 data: &MLCTensorData,
260 data_type: MLCDataType,
261 ) -> Retained<Self>;
262
263 #[cfg(feature = "MLCTypes")]
264 /// Create a MLCTensor object
265 ///
266 /// Create a tensor object with data
267 ///
268 /// Parameter `shape`: The tensor shape
269 ///
270 /// Parameter `fillData`: The scalar value to initialize the tensor data with
271 ///
272 /// Parameter `dataType`: The tensor data type
273 ///
274 /// Returns: A new MLCTensor object
275 #[deprecated]
276 #[unsafe(method(tensorWithShape:fillWithData:dataType:))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn tensorWithShape_fillWithData_dataType(
279 shape: &NSArray<NSNumber>,
280 fill_data: &NSNumber,
281 data_type: MLCDataType,
282 ) -> Retained<Self>;
283
284 /// Create a MLCTensor object
285 ///
286 /// Create a NCHW tensor object with tensor data type = MLCDataTypeFloat32
287 ///
288 /// Parameter `width`: The tensor width
289 ///
290 /// Parameter `height`: The tensor height
291 ///
292 /// Parameter `featureChannelCount`: Number of feature channels
293 ///
294 /// Parameter `batchSize`: The tensor batch size
295 ///
296 /// Returns: A new MLCTensor object
297 #[deprecated]
298 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:))]
299 #[unsafe(method_family = none)]
300 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize(
301 width: NSUInteger,
302 height: NSUInteger,
303 feature_channel_count: NSUInteger,
304 batch_size: NSUInteger,
305 ) -> Retained<Self>;
306
307 #[cfg(feature = "MLCTypes")]
308 /// Create a MLCTensor object
309 ///
310 /// Create a NCHW tensor object initialized with a scalar value
311 ///
312 /// Parameter `width`: The tensor width
313 ///
314 /// Parameter `height`: The tensor height
315 ///
316 /// Parameter `featureChannelCount`: Number of feature channels
317 ///
318 /// Parameter `batchSize`: The tensor batch size
319 ///
320 /// Parameter `fillData`: The scalar value to initialize the tensor data with
321 ///
322 /// Parameter `dataType`: The tensor data type
323 ///
324 /// Returns: A new MLCTensorData object
325 #[deprecated]
326 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:fillWithData:dataType:))]
327 #[unsafe(method_family = none)]
328 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_fillWithData_dataType(
329 width: NSUInteger,
330 height: NSUInteger,
331 feature_channel_count: NSUInteger,
332 batch_size: NSUInteger,
333 fill_data: c_float,
334 data_type: MLCDataType,
335 ) -> Retained<Self>;
336
337 #[cfg(feature = "MLCTypes")]
338 /// Create a MLCTensor object
339 ///
340 /// Create a NCHW tensor object initialized with a random initializer type.
341 /// The tensor data type is MLCDataTypeFloat32
342 ///
343 /// Parameter `width`: The tensor width
344 ///
345 /// Parameter `height`: The tensor height
346 ///
347 /// Parameter `featureChannelCount`: Number of feature channels
348 ///
349 /// Parameter `batchSize`: The tensor batch size
350 ///
351 /// Parameter `randomInitializerType`: The random initializer type
352 ///
353 /// Returns: A new MLCTensor object
354 #[deprecated]
355 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:randomInitializerType:))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_randomInitializerType(
358 width: NSUInteger,
359 height: NSUInteger,
360 feature_channel_count: NSUInteger,
361 batch_size: NSUInteger,
362 random_initializer_type: MLCRandomInitializerType,
363 ) -> Retained<Self>;
364
365 #[cfg(feature = "MLCTensorData")]
366 /// Create a MLCTensor object
367 ///
368 /// Create a NCHW tensor object with a tensor data object
369 /// The tensor data type is MLCDataTypeFloat32.
370 ///
371 /// Parameter `width`: The tensor width
372 ///
373 /// Parameter `height`: The tensor height
374 ///
375 /// Parameter `featureChannelCount`: Number of feature channels
376 ///
377 /// Parameter `batchSize`: The tensor batch size
378 ///
379 /// Parameter `data`: The tensor data
380 ///
381 /// Returns: A new MLCTensor object
382 #[deprecated]
383 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:data:))]
384 #[unsafe(method_family = none)]
385 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data(
386 width: NSUInteger,
387 height: NSUInteger,
388 feature_channel_count: NSUInteger,
389 batch_size: NSUInteger,
390 data: &MLCTensorData,
391 ) -> Retained<Self>;
392
393 #[cfg(all(feature = "MLCTensorData", feature = "MLCTypes"))]
394 /// Create a MLCTensor object
395 ///
396 /// Create a NCHW tensor object with a tensor data object
397 /// The tensor data type is MLCDataTypeFloat32.
398 ///
399 /// Parameter `width`: The tensor width
400 ///
401 /// Parameter `height`: The tensor height
402 ///
403 /// Parameter `featureChannelCount`: Number of feature channels
404 ///
405 /// Parameter `batchSize`: The tensor batch size
406 ///
407 /// Parameter `data`: The tensor data
408 ///
409 /// Parameter `dataType`: The tensor data type
410 ///
411 /// Returns: A new MLCTensor object
412 #[deprecated]
413 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:data:dataType:))]
414 #[unsafe(method_family = none)]
415 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data_dataType(
416 width: NSUInteger,
417 height: NSUInteger,
418 feature_channel_count: NSUInteger,
419 batch_size: NSUInteger,
420 data: &MLCTensorData,
421 data_type: MLCDataType,
422 ) -> Retained<Self>;
423
424 /// Create a MLCTensor object
425 ///
426 /// Create a tensor typically used by a recurrent layer
427 /// The tensor data type is MLCDataTypeFloat32.
428 ///
429 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
430 ///
431 /// Parameter `featureChannelCount`: Number of feature channels
432 ///
433 /// Parameter `batchSize`: The tensor batch size
434 ///
435 /// Returns: A new MLCTensor object
436 #[deprecated]
437 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:))]
438 #[unsafe(method_family = none)]
439 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize(
440 sequence_length: NSUInteger,
441 feature_channel_count: NSUInteger,
442 batch_size: NSUInteger,
443 ) -> Retained<Self>;
444
445 #[cfg(feature = "MLCTypes")]
446 /// Create a MLCTensor object
447 ///
448 /// Create a tensor typically used by a recurrent layer
449 /// The tensor data type is MLCDataTypeFloat32.
450 ///
451 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
452 ///
453 /// Parameter `featureChannelCount`: Number of feature channels
454 ///
455 /// Parameter `batchSize`: The tensor batch size
456 ///
457 /// Parameter `randomInitializerType`: The random initializer type
458 ///
459 /// Returns: A new MLCTensor object
460 #[deprecated]
461 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:randomInitializerType:))]
462 #[unsafe(method_family = none)]
463 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_randomInitializerType(
464 sequence_length: NSUInteger,
465 feature_channel_count: NSUInteger,
466 batch_size: NSUInteger,
467 random_initializer_type: MLCRandomInitializerType,
468 ) -> Retained<Self>;
469
470 #[cfg(feature = "MLCTensorData")]
471 /// Create a MLCTensor object
472 ///
473 /// Create a tensor typically used by a recurrent layer
474 /// The tensor data type is MLCDataTypeFloat32.
475 ///
476 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
477 ///
478 /// Parameter `featureChannelCount`: Number of feature channels
479 ///
480 /// Parameter `batchSize`: The tensor batch size
481 ///
482 /// Parameter `data`: The tensor data
483 ///
484 /// Returns: A new MLCTensor object
485 #[deprecated]
486 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:data:))]
487 #[unsafe(method_family = none)]
488 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_data(
489 sequence_length: NSUInteger,
490 feature_channel_count: NSUInteger,
491 batch_size: NSUInteger,
492 data: Option<&MLCTensorData>,
493 ) -> Retained<Self>;
494
495 #[cfg(feature = "MLCTypes")]
496 /// Create a MLCTensor object
497 ///
498 /// Create a tensor of variable length sequences typically used by a recurrent layer
499 /// The tensor data type is MLCDataTypeFloat32.
500 ///
501 /// Parameter `sequenceLengths`: An array of sequence lengths
502 ///
503 /// Parameter `sortedSequences`: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
504 ///
505 /// Parameter `featureChannelCount`: Number of feature channels
506 ///
507 /// Parameter `batchSize`: The tensor batch size
508 ///
509 /// Parameter `randomInitializerType`: The random initializer type
510 ///
511 /// Returns: A new MLCTensor object
512 #[deprecated]
513 #[unsafe(method(tensorWithSequenceLengths:sortedSequences:featureChannelCount:batchSize:randomInitializerType:))]
514 #[unsafe(method_family = none)]
515 pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_randomInitializerType(
516 sequence_lengths: &NSArray<NSNumber>,
517 sorted_sequences: bool,
518 feature_channel_count: NSUInteger,
519 batch_size: NSUInteger,
520 random_initializer_type: MLCRandomInitializerType,
521 ) -> Option<Retained<Self>>;
522
523 #[cfg(feature = "MLCTensorData")]
524 /// Create a MLCTensor object
525 ///
526 /// Create a tensor of variable length sequences typically used by a recurrent layer
527 /// The tensor data type is MLCDataTypeFloat32.
528 ///
529 /// Parameter `sequenceLengths`: An array of sequence lengths
530 ///
531 /// Parameter `sortedSequences`: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
532 ///
533 /// Parameter `featureChannelCount`: Number of feature channels
534 ///
535 /// Parameter `batchSize`: The tensor batch size
536 ///
537 /// Parameter `data`: The tensor data
538 ///
539 /// Returns: A new MLCTensor object
540 #[deprecated]
541 #[unsafe(method(tensorWithSequenceLengths:sortedSequences:featureChannelCount:batchSize:data:))]
542 #[unsafe(method_family = none)]
543 pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_data(
544 sequence_lengths: &NSArray<NSNumber>,
545 sorted_sequences: bool,
546 feature_channel_count: NSUInteger,
547 batch_size: NSUInteger,
548 data: Option<&MLCTensorData>,
549 ) -> Option<Retained<Self>>;
550
551 /// Returns a Boolean value indicating whether the underlying data has valid floating-point numerics, i.e. it
552 /// does not contain NaN or INF floating-point values.
553 #[deprecated]
554 #[unsafe(method(hasValidNumerics))]
555 #[unsafe(method_family = none)]
556 pub unsafe fn hasValidNumerics(&self) -> bool;
557
558 /// Synchronize the data in host memory.
559 ///
560 /// Synchronize the data in host memory i.e. tensor.data with latest contents in device memory
561 /// This should only be called once the graph that this tensor is used with has finished execution;
562 /// Otherwise the results in device memory may not be up to date.
563 /// NOTE: This method should not be called from a completion callback when device is the GPU.
564 ///
565 /// Returns: Returns YES if success, NO if there is a failure to synchronize
566 #[deprecated]
567 #[unsafe(method(synchronizeData))]
568 #[unsafe(method_family = none)]
569 pub unsafe fn synchronizeData(&self) -> bool;
570
571 /// Synchronize the optimizer data in host memory.
572 ///
573 /// Synchronize the optimizer data in host memory with latest contents in device memory
574 /// This should only be called once the graph that this tensor is used with has finished execution;
575 /// Otherwise the results in device memory may not be up to date.
576 /// NOTE: This method should not be called from a completion callback when device is the GPU.
577 ///
578 /// Returns: Returns YES if success, NO if there is a failure to synchronize
579 #[deprecated]
580 #[unsafe(method(synchronizeOptimizerData))]
581 #[unsafe(method_family = none)]
582 pub unsafe fn synchronizeOptimizerData(&self) -> bool;
583
584 /// Copy tensor data from device memory to user specified memory
585 ///
586 /// Before copying tensor data from device memory, one may need to synchronize the device memory for example
587 /// when device is the GPU. The synchronizeWithDevice argumet can be set appropraitely to indicate this.
588 /// For CPU this is ignored. If the tensor has been specified in outputs of a graph using addOutputs,
589 /// synchronizeWithDevice should be set to NO.
590 /// NOTE: This method should only be called once the graph that this tensor is used with has finished execution;
591 /// Otherwise the results in device memory may not be up to date. synchronizeWithDevice must be set to NO
592 /// when this method is called from a completion callback for GPU.
593 ///
594 /// Parameter `bytes`: The user specified data in which to copy
595 ///
596 /// Parameter `length`: The size in bytes to copy
597 ///
598 /// Parameter `synchronizeWithDevice`: Whether to synchronize device memory if device is GPU
599 ///
600 /// Returns: Returns YES if success, NO if there is a failure to synchronize
601 ///
602 /// # Safety
603 ///
604 /// `bytes` must be a valid pointer.
605 #[deprecated]
606 #[unsafe(method(copyDataFromDeviceMemoryToBytes:length:synchronizeWithDevice:))]
607 #[unsafe(method_family = none)]
608 pub unsafe fn copyDataFromDeviceMemoryToBytes_length_synchronizeWithDevice(
609 &self,
610 bytes: NonNull<c_void>,
611 length: NSUInteger,
612 synchronize_with_device: bool,
613 ) -> bool;
614
615 #[cfg(all(feature = "MLCDevice", feature = "MLCTensorData"))]
616 /// Associates the given data to the tensor. If the device is GPU, also copies the data to the device memory.
617 /// Returns true if the data is successfully associated with the tensor and copied to the device.
618 ///
619 /// The caller must guarantee the lifetime of the underlying memory of
620 /// `data`for the entirety of the tensor's
621 /// lifetime. For input tensors, we recommend that the bindAndwriteData method provided by MLCTrainingGraph
622 /// and MLCInferenceGraph be used. This method should only be used to allocate and copy data to device memory
623 /// for tensors that are typically layer parameters such as weights, bias for convolution layers, beta, gamma for
624 /// normalization layers.
625 ///
626 /// Parameter `data`: The data to associated with the tensor
627 ///
628 /// Parameter `device`: The compute device
629 ///
630 /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor and copied to the device.
631 #[deprecated]
632 #[unsafe(method(bindAndWriteData:toDevice:))]
633 #[unsafe(method_family = none)]
634 pub unsafe fn bindAndWriteData_toDevice(
635 &self,
636 data: &MLCTensorData,
637 device: &MLCDevice,
638 ) -> bool;
639
640 #[cfg(all(feature = "MLCTensorData", feature = "MLCTensorOptimizerDeviceData"))]
641 /// Associates the given optimizer data and device data buffers to the tensor.
642 /// Returns true if the data is successfully associated with the tensor and copied to the device.
643 ///
644 /// The caller must guarantee the lifetime of the underlying memory of
645 /// `data`for the entirety of the tensor's
646 /// lifetime. The
647 /// `deviceData`buffers are allocated by MLCompute. This method must be called
648 /// before executeOptimizerUpdateWithOptions or executeWithInputsData is called for the training graph.
649 ///
650 /// Parameter `data`: The optimizer data to be associated with the tensor
651 ///
652 /// Parameter `deviceData`: The optimizer device data to be associated with the tensor
653 ///
654 /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor .
655 #[deprecated]
656 #[unsafe(method(bindOptimizerData:deviceData:))]
657 #[unsafe(method_family = none)]
658 pub unsafe fn bindOptimizerData_deviceData(
659 &self,
660 data: &NSArray<MLCTensorData>,
661 device_data: Option<&NSArray<MLCTensorOptimizerDeviceData>>,
662 ) -> bool;
663
664 #[cfg(feature = "MLCTypes")]
665 /// Converts a 32-bit floating-point tensor with given scale and a zero point
666 /// Returns a quantized tensor
667 ///
668 /// Parameter `type`: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
669 ///
670 /// Parameter `scale`: The scale to apply in quantization
671 ///
672 /// Parameter `bias`: The offset value that maps to float zero
673 ///
674 /// Returns: A quantized tensor
675 #[unsafe(method(tensorByQuantizingToType:scale:bias:))]
676 #[unsafe(method_family = none)]
677 pub unsafe fn tensorByQuantizingToType_scale_bias(
678 &self,
679 r#type: MLCDataType,
680 scale: c_float,
681 bias: NSInteger,
682 ) -> Option<Retained<MLCTensor>>;
683
684 #[cfg(feature = "MLCTypes")]
685 /// Converts a 32-bit floating-point tensor with given scale and a zero point
686 /// Returns a quantized tensor
687 ///
688 /// Parameter `type`: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
689 ///
690 /// Parameter `scale`: The scale to apply in quantization
691 ///
692 /// Parameter `bias`: The offset value that maps to float zero
693 ///
694 /// Parameter `axis`: The dimension on which to apply per-channel quantization
695 ///
696 /// Returns: A quantized tensor
697 #[unsafe(method(tensorByQuantizingToType:scale:bias:axis:))]
698 #[unsafe(method_family = none)]
699 pub unsafe fn tensorByQuantizingToType_scale_bias_axis(
700 &self,
701 r#type: MLCDataType,
702 scale: &MLCTensor,
703 bias: &MLCTensor,
704 axis: NSInteger,
705 ) -> Option<Retained<MLCTensor>>;
706
707 #[cfg(feature = "MLCTypes")]
708 /// Converts a quantized tensor to a 32-bit floating-point tensor
709 /// Returns a de-quantized tensor
710 ///
711 /// Parameter `type`: The de-quantized data type. Must be MLCFloat32
712 ///
713 /// Parameter `scale`: The scale thst was used for the quantized data
714 ///
715 /// Parameter `bias`: The offset value that maps to float zero used for the quantized data
716 ///
717 /// Parameter `axis`: The dimension on which to apply per-channel quantization
718 ///
719 /// Returns: A quantized tensor
720 #[unsafe(method(tensorByDequantizingToType:scale:bias:axis:))]
721 #[unsafe(method_family = none)]
722 pub unsafe fn tensorByDequantizingToType_scale_bias_axis(
723 &self,
724 r#type: MLCDataType,
725 scale: &MLCTensor,
726 bias: &MLCTensor,
727 axis: NSInteger,
728 ) -> Option<Retained<MLCTensor>>;
729 );
730}