Mojo trait
CopyPolicy
The CopyPolicy trait defines requirements needed for a tensor to be copied.
These requirements check the compatibility of the source and destination tensors.
Implemented traits
AnyType,
Copyable,
DevicePassable,
ImplicitlyCopyable,
UnknownDestructibility
Aliases
__copyinit__is_trivial
comptime __copyinit__is_trivial
A flag (often compiler generated) to indicate whether the implementation of __copyinit__ is trivial.
The implementation of __copyinit__ is considered to be trivial if:
- The struct has a compiler-generated trivial
__copyinit__and all its fields have a trivial__copyinit__method.
In practice, it means the value can be copied by copying the bits from one location to another without side effects.
__del__is_trivial
comptime __del__is_trivial
A flag (often compiler generated) to indicate whether the implementation of __del__ is trivial.
The implementation of __del__ is considered to be trivial if:
- The struct has a compiler-generated trivial destructor and all its fields
have a trivial
__del__method.
In practice, it means that the __del__ can be considered as no-op.
device_type
comptime device_type
Indicate the type being used on accelerator devices.
Required methods
__copyinit__
__copyinit__(out self: _Self, existing: _Self, /)
Create a new instance of the value by copying an existing one.
Args:
- existing (
_Self): The value to copy.
Returns:
_Self
verify_source_tensor
static verify_source_tensor(src: LayoutTensor[dtype, layout, origin, address_space=address_space, element_layout=element_layout, layout_int_type=layout_int_type, linear_idx_type=linear_idx_type, masked=masked, alignment=alignment])
A static function that verifies the source tensor is compatible with the copy operation. If the tensor is not valid compilation will fail.
Args:
- src (
LayoutTensor): The source tensor that will be copied from.
verify_destination_tensor
static verify_destination_tensor(dst: LayoutTensor[dtype, layout, origin, address_space=address_space, element_layout=element_layout, layout_int_type=layout_int_type, linear_idx_type=linear_idx_type, masked=masked, alignment=alignment])
A static function that verifies the destination tensor is compatible with the copy operation. If the tensor is not valid compilation will fail.
Args:
- dst (
LayoutTensor): The destination tensor that will be copied to.
get_type_name
static get_type_name() -> String
Gets the name of the host type (the one implementing this trait). For example, Int would return "Int", DeviceBuffer[DType.float32] would return "DeviceBuffer[DType.float32]". This is used for error messages when passing types to the device. TODO: This method will be retired soon when better kernel call error messages arrive.
Returns:
String: The host type's name.
get_device_type_name
static get_device_type_name() -> String
Gets device_type's name. For example, because DeviceBuffer's device_type is UnsafePointer, DeviceBuffer[DType.float32]'s get_device_type_name() should return something like "UnsafePointer[Scalar[DType.float32]]". This is used for error messages when passing types to the device. TODO: This method will be retired soon when better kernel call error messages arrive.
Returns:
String: The device type's name.
Provided methods
copy
copy(self: _Self) -> _Self
Explicitly construct a copy of self.
Returns:
_Self: A copy of this value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!