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,
ImplicitlyDestructible,
Movable
comptime members
device_type
comptime device_type
Indicate the type being used on accelerator devices.
Required methods
__init__
__init__(out self: _Self, *, copy: _Self)
Create a new instance of the value by copying an existing one.
Args:
- copy (
_Self): The value to copy.
Returns:
_Self
__init__(out self: _Self, *, deinit take: _Self)
Create a new instance of the value by moving the value of another.
Args:
- take (
_Self): The value to move.
Returns:
_Self
verify_source_tensor
static verify_source_tensor(src: LayoutTensor[src.dtype, src.layout, src.origin, address_space=src.address_space, element_layout=src.element_layout, layout_int_type=src.layout_int_type, linear_idx_type=src.linear_idx_type, masked=src.masked, alignment=src.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[dst.dtype, dst.layout, dst.origin, address_space=dst.address_space, element_layout=dst.element_layout, layout_int_type=dst.layout_int_type, linear_idx_type=dst.linear_idx_type, masked=dst.masked, alignment=dst.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.
Provided methods
copy
copy(self: _Self) -> _Self
Explicitly construct a copy of self, a convenience method for Self(copy=self) when the type is inconvenient to write out.
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!