For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
DeviceTypeEncoder
This trait marks types as capable of encoding device types.
Used in DevicePassable._to_device_type() to enable target specific
encoding of device types at the boundary where functions are enqueued for
execution on an accelerator device.
Implemented traits
Required methods
encode_device_ptr
def encode_device_ptr(mut self: _Self, value: DevicePointer, target: UnsafePointer[NoneType])
Encodes a DevicePointer into target.
Args:
- value (
DevicePointer): TheDevicePointerinstance to encode intotarget. - target (
UnsafePointer[NoneType]): The opaque destination pointer to encode into.
Provided methods
encode
def encode[ValueType: DevicePassable](mut self: _Self, value: ValueType, target: UnsafePointer[NoneType])
Encodes value into target as its device-side representation.
This is the default implementation for types whose
DevicePassable.device_type is Self, it writes the value's bits into
the storage pointed to by target.
Constraints:
ValueTypemust conform toDevicePassable.ValueTypemust be its own leafdevice_type(i.e.ValueType._is_convertible_to_device_type[ValueType]()holds).ValueTypemust conform toImplicitlyCopyable & ImplicitlyDestructibleor toCopyable & ImplicitlyDestructible.
Parameters:
- ValueType (
DevicePassable): The type ofvalue, see constraints.
Args:
- value (
ValueType): The variable to encode. - target (
UnsafePointer[NoneType]): The opaque destination pointer to encode into. Must point to uninitialized storage at leastsize_of[ValueType]()bytes wide.