//! This file has been automatically generated by `objc2`'s `header-translator`. //! DO NOT EDIT use core::ffi::*; use core::ptr::NonNull; use objc2::__framework_prelude::*; use objc2_foundation::*;
extern_class!( /// An array of length matching the rank, holding the dimensions of a tensor. /// /// Supports rank up to ``MTL_TENSOR_MAX_RANK``. /// /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltensorextents?language=objc) #[unsafe(super(NSObject))] #[derive(Debug, PartialEq, Eq, Hash)] pubstruct MTLTensorExtents;
);
extern_conformance!( unsafeimpl NSObjectProtocol for MTLTensorExtents {}
);
impl MTLTensorExtents {
extern_methods!( /// Creates a new tensor extents with the rank and extent values you provide. /// /// Zero rank extents represent scalars. `values` can only be `nil`if `rank` is 0. /// - Parameters: /// - rank: the number of dimensions. /// - values: an array of length `rank` that specifies the size of each dimension. The first dimension is the innermost dimension. /// - Returns: Tensor extents with the rank and extent values you provide. Returns `nil` if `rank` exceeds 0 and `values` is nil or if `rank` exceeds ``MTL_TENSOR_MAX_RANK``. /// /// # Safety /// /// `values` must be a valid pointer or null. #[unsafe(method(initWithRank:values:))] #[unsafe(method_family = init)] pubunsafefn initWithRank_values(
this: Allocated<Self>,
rank: NSUInteger,
values: *const NSInteger,
) -> Option<Retained<Self>>;
/// Obtains the rank of the tensor. /// /// The rank represents the number of dimensions. #[unsafe(method(rank))] #[unsafe(method_family = none)] pubfn rank(&self) -> NSUInteger;
/// Returns the extent at an index. /// /// - Parameters: /// - dimensionIndex: the index of the dimension. The first dimension is the innermost dimension. /// - Returns: the extent at `dimensionIndex`. This method returns -1 if `dimensionIndex` is greater than or equal to `rank`. /// /// # Safety /// /// `dimensionIndex` might not be bounds-checked. #[unsafe(method(extentAtDimensionIndex:))] #[unsafe(method_family = none)] pubunsafefn extentAtDimensionIndex(&self, dimension_index: NSUInteger) -> NSInteger;
);
}
/// The type that represents the different contexts for a tensor. /// /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltensorusage?language=objc) // NS_OPTIONS #[repr(transparent)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pubstruct MTLTensorUsage(pub NSUInteger);
bitflags::bitflags! { impl MTLTensorUsage: NSUInteger { /// A tensor context that applies to compute encoders. /// /// You can use tensors with this context in ``MTL4ComputeCommandEncoder`` or ``MTLComputeCommandEncoder`` instances. #[doc(alias = "MTLTensorUsageCompute")] const Compute = 1<<0; /// A tensor context that applies to render encoders. /// /// You can use tensors with this context in ``MTL4RenderCommandEncoder`` or ``MTLRenderCommandEncoder`` instances. #[doc(alias = "MTLTensorUsageRender")] const Render = 1<<1; /// A tensor context that applies to machine learning encoders. /// /// You can use tensors with this context in ``MTL4MachineLearningCommandEncoder`` instances. #[doc(alias = "MTLTensorUsageMachineLearning")] const MachineLearning = 1<<2;
}
}
extern_conformance!( unsafeimpl NSCopying for MTLTensorDescriptor {}
);
unsafeimpl CopyingHelper for MTLTensorDescriptor { type Result = Self;
}
extern_conformance!( unsafeimpl NSObjectProtocol for MTLTensorDescriptor {}
);
impl MTLTensorDescriptor {
extern_methods!( /// An array of sizes, in elements, one for each dimension of the tensors you create with this descriptor. /// /// The default value of this property is a rank one extents with size one. #[unsafe(method(dimensions))] #[unsafe(method_family = none)] pubfn dimensions(&self) -> Retained<MTLTensorExtents>;
/// Setter for [`dimensions`][Self::dimensions]. /// /// This is [copied][objc2_foundation::NSCopying::copy] when set. #[unsafe(method(setDimensions:))] #[unsafe(method_family = none)] pubfn setDimensions(&self, dimensions: &MTLTensorExtents);
/// An array of strides, in elements, one for each dimension in the tensors you create with this descriptor, if applicable. /// /// This property only applies to tensors you create from a buffer, otherwise it is nil. You are responsible for ensuring `strides` meets the following requirements: /// - Elements of `strides`are in monotonically non-decreasing order. /// - The first element of `strides` is one. /// - For any `i` larger than zero, `strides[i]` is greater than or equal to `strides[i-1] * dimensions[i-1]`. /// - If `usage` contains ``MTLTensorUsage/MTLTensorUsageMachineLearning``, the second element of `strides` is aligned to 64 bytes, and for any `i` larger than one, `strides[i]` is equal to `strides[i-1] * dimensions[i-1]`. #[unsafe(method(strides))] #[unsafe(method_family = none)] pubfn strides(&self) -> Option<Retained<MTLTensorExtents>>;
/// Setter for [`strides`][Self::strides]. /// /// This is [copied][objc2_foundation::NSCopying::copy] when set. #[unsafe(method(setStrides:))] #[unsafe(method_family = none)] pubfn setStrides(&self, strides: Option<&MTLTensorExtents>);
/// A data format for the tensors you create with this descriptor. /// /// The default value of this property is ``MTLTensorDataType/MTLTensorDataTypeFloat32``. #[unsafe(method(dataType))] #[unsafe(method_family = none)] pubfn dataType(&self) -> MTLTensorDataType;
/// A set of contexts in which you can use tensors you create with this descriptor. /// /// The default value for this property is a bitwise `OR` of: /// - ``MTLTensorUsage/MTLTensorUsageRender`` /// - ``MTLTensorUsage/MTLTensorUsageCompute`` #[unsafe(method(usage))] #[unsafe(method_family = none)] pubfn usage(&self) -> MTLTensorUsage;
#[cfg(feature = "MTLResource")] /// A packed set of the `storageMode`, `cpuCacheMode` and `hazardTrackingMode` properties. #[unsafe(method(resourceOptions))] #[unsafe(method_family = none)] pubfn resourceOptions(&self) -> MTLResourceOptions;
#[cfg(feature = "MTLResource")] /// A value that configures the cache mode of CPU mapping of tensors you create with this descriptor. /// /// The default value of this property is ``MTLCPUCacheMode/MTLCPUCacheModeDefaultCache``. #[unsafe(method(cpuCacheMode))] #[unsafe(method_family = none)] pubfn cpuCacheMode(&self) -> MTLCPUCacheMode;
#[cfg(feature = "MTLResource")] /// A value that configures the memory location and access permissions of tensors you create with this descriptor. /// /// The default value of this property defaults to ``MTLStorageMode/MTLStorageModeShared``. #[unsafe(method(storageMode))] #[unsafe(method_family = none)] pubfn storageMode(&self) -> MTLStorageMode;
#[cfg(feature = "MTLResource")] /// A value that configures the hazard tracking of tensors you create with this descriptor. /// /// The default value of this property is ``MTLHazardTrackingMode/MTLHazardTrackingModeDefault``. #[unsafe(method(hazardTrackingMode))] #[unsafe(method_family = none)] pubfn hazardTrackingMode(&self) -> MTLHazardTrackingMode;
extern_protocol!( /// A resource representing a multi-dimensional array that you can use with machine learning workloads. /// /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtltensor?language=objc) #[cfg(all(feature = "MTLAllocation", feature = "MTLResource"))] pubunsafetrait MTLTensor: MTLResource { #[cfg(feature = "MTLTypes")] /// A handle that represents the GPU resource, which you can store in an argument buffer. #[unsafe(method(gpuResourceID))] #[unsafe(method_family = none)] fn gpuResourceID(&self) -> MTLResourceID;
#[cfg(feature = "MTLBuffer")] /// A buffer instance this tensor shares its storage with or nil if this tensor does not wrap an underlying buffer. #[unsafe(method(buffer))] #[unsafe(method_family = none)] fn buffer(&self) -> Option<Retained<ProtocolObject<dyn MTLBuffer>>>;
/// An offset, in bytes, into the buffer instance this tensor shares its storage with, or zero if this tensor does not wrap an underlying buffer. #[unsafe(method(bufferOffset))] #[unsafe(method_family = none)] fn bufferOffset(&self) -> NSUInteger;
/// An array of strides, in elements, one for each dimension of this tensor. /// /// This property only applies if this tensor shares its storage with a buffer, otherwise it's nil. #[unsafe(method(strides))] #[unsafe(method_family = none)] fn strides(&self) -> Option<Retained<MTLTensorExtents>>;
/// An array of sizes, in elements, one for each dimension of this tensor. #[unsafe(method(dimensions))] #[unsafe(method_family = none)] fn dimensions(&self) -> Retained<MTLTensorExtents>;
/// An underlying data format of this tensor. #[unsafe(method(dataType))] #[unsafe(method_family = none)] fn dataType(&self) -> MTLTensorDataType;
/// A set of contexts in which you can use this tensor. #[unsafe(method(usage))] #[unsafe(method_family = none)] fn usage(&self) -> MTLTensorUsage;
/// Replaces the contents of a slice of this tensor with data you provide. /// /// - Parameters: /// - sliceOrigin: An array of offsets, in elements, to the first element of the slice that this method writes data to. /// - sliceDimensions: An array of sizes, in elements, of the slice this method writes data to. /// - bytes: A pointer to bytes of data that this method copies into the slice you specify with `sliceOrigin` and `sliceDimensions`. /// - strides: An array of strides, in elements, that describes the layout of the data in `bytes`. You are responsible for ensuring `strides` meets the following requirements: /// - Elements of `strides`are in monotonically non-decreasing order. /// - For any `i` larger than zero, `strides[i]` is greater than or equal to `strides[i-1] * dimensions[i-1]`. /// /// # Safety /// /// `bytes` must be a valid pointer. #[unsafe(method(replaceSliceOrigin:sliceDimensions:withBytes:strides:))] #[unsafe(method_family = none)] unsafefn replaceSliceOrigin_sliceDimensions_withBytes_strides(
&self,
slice_origin: &MTLTensorExtents,
slice_dimensions: &MTLTensorExtents,
bytes: NonNull<c_void>,
strides: &MTLTensorExtents,
);
/// Copies the data corresponding to a slice of this tensor into a pointer you provide. /// /// - Parameters: /// - bytes: A pointer to bytes of data that this method copies into the slice you specify with `sliceOrigin` and `sliceDimensions`. /// - strides: An array of strides, in elements, that describes the layout of the data in `bytes`. You are responsible for ensuring `strides` meets the following requirements: /// - Elements of `strides`are in monotonically non-decreasing order. /// - For any `i` larger than zero, `strides[i]` is greater than or equal to `strides[i-1] * dimensions[i-1]`. /// - sliceOrigin: An array of offsets, in elements, to the first element of the slice that this method reads data from. /// - sliceDimensions: An array of sizes, in elements, of the slice this method reads data from. /// /// # Safety /// /// `bytes` must be a valid pointer. #[unsafe(method(getBytes:strides:fromSliceOrigin:sliceDimensions:))] #[unsafe(method_family = none)] unsafefn getBytes_strides_fromSliceOrigin_sliceDimensions(
&self,
bytes: NonNull<c_void>,
strides: &MTLTensorExtents,
slice_origin: &MTLTensorExtents,
slice_dimensions: &MTLTensorExtents,
);
}
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.