IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
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

AnyType

Required methods

encode_device_ptr

def encode_device_ptr(mut self: _Self, value: DevicePointer, target: UnsafePointer[NoneType])

Encodes a DevicePointer into target.

Args:

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:

  • ValueType must conform to DevicePassable.
  • ValueType must be its own leaf device_type (i.e. ValueType._is_convertible_to_device_type[ValueType]() holds).
  • ValueType must conform to ImplicitlyCopyable & ImplicitlyDestructible or to Copyable & ImplicitlyDestructible.

Parameters:

Args:

  • value (ValueType): The variable to encode.
  • target (UnsafePointer[NoneType]): The opaque destination pointer to encode into. Must point to uninitialized storage at least size_of[ValueType]() bytes wide.