Mojo struct
Device
struct Device
Represents a logical instance of a device, for eg: CPU. This can be used to allocate and manage memory in a device's address space, and to compile and execute models and graphs on a device.
Implemented traits
AnyType
,
CollectionElement
,
Copyable
,
Movable
,
Stringable
,
UnknownDestructibility
,
Writable
Methods
__init__
__init__(out self)
Constructs a default initialized Device in a state that is only valid for deletion. Can be used to represent a 'moved from' state.
Use cpu() or accelerator() to create a CPU or GPU Device.
__copyinit__
__copyinit__(out self, existing: Self)
Create a copy of the Device (bumping a refcount on the underlying Device).
Args:
- existing (
Self
): Instance from which to copy.
__moveinit__
__moveinit__(out self, owned existing: Self)
Create a new Device and consume existing
.
Args:
- existing (
Self
): Instance from which to move from.
__del__
__del__(owned self)
Destroys the device.
Note that any DeviceBuffer allocated on the Device will contain a reference to the Device, and the Device will only be de-allocated when all of its DeviceBuffers have also been destroyed.
__eq__
__eq__(self, other: Self) -> Bool
Check if self
and other
point to the same underlying Device.
Args:
- other (
Self
): Instance to compare against.
copy
copy(self) -> Self
Explicitly construct a copy of self.
Returns:
A copy of this value.
allocate
allocate(self, spec: TensorSpec, name: Optional[String] = Optional(None)) -> DeviceTensor
Creates tensor allocated in the Device's address space.
Args:
- spec (
TensorSpec
): TensorSpec descripting the shape and type of the tensor to allocate. - name (
Optional[String]
): An optional name for the DeviceTensor.
allocate(self, bytecount: Int, name: Optional[String] = Optional(None)) -> DeviceMemory
Allocates a DeviceMemory object in the Device's address space.
Args:
- bytecount (
Int
): The size of the memory to allocate in bytes. - name (
Optional[String]
): An optional name for the DeviceMemory.
Returns:
A DeviceMemory object allocated in the Device's address space.
unsafe_ptr
unsafe_ptr(self) -> UnsafePointer[NoneType]
Gets the underlying pointer to the Device.
Returns:
The underlying pointer of the Device.
__str__
__str__(self) -> String
Returns a descriptor of the device.
Returns:
String representation of device.
write_to
write_to[W: Writer](self, mut writer: W)
Formats this Device to the provided Writer.
Parameters:
- W (
Writer
): A type conforming to the Writable trait.
Args:
- writer (
W
): The object to write to.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!