For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo struct
Device
struct Device[target: CompilationTarget, origin: ImmOrigin]
A view of the accelerator device behind a DeviceContext.
Mirrors the legacy backend's Device. The view is valid for as long as the
context it came from is.
Parameters
- target (
CompilationTarget): The compilation target of the owning context. - origin (
ImmOrigin): The origin of the owning context.
Fields
- id (
Int64): The ID of this device among the devices of its API.
Implemented traits
Methods
__init__
def __init__(out self, *, var _impl: LegacyDevice[target, origin] if use_legacy_backend() else _HALDevice[target, origin])
Wraps an already-constructed backend view.
Args:
- _impl (
LegacyDevice[target, origin] if use_legacy_backend() else _HALDevice[target, origin]): The backend view to take ownership of.
unwrap_legacy
def unwrap_legacy(self) -> LegacyDevice[target, origin]
Returns the underlying legacy view.
Returns:
LegacyDevice[target, origin]: The legacy device view this wrapper holds.
unwrap_hal
def unwrap_hal(self) -> _HALDevice[target, origin]
Returns the underlying HAL view.
Returns:
_HALDevice[target, origin]: The HAL device view this wrapper holds.
get_name
def get_name(self) -> String
Returns the device name, as reported by the native device API.
Returns:
String: A string identifying the device.
Raises:
If the device name cannot be queried.
get_attribute
def get_attribute(self, attr: DeviceAttribute) -> Int
Returns the specified attribute for this device.
Args:
- attr (
DeviceAttribute): The device attribute to query.
Returns:
Int: The value of attr on this device.
Raises:
If the attribute cannot be queried.
multiprocessor_count
def multiprocessor_count(self) -> Int
Returns the number of multiprocessors on this device.
On a GPU, this is the number of streaming multiprocessors (NVIDIA) or compute units (AMD) that run thread blocks concurrently. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The number of multiprocessors.
Raises:
If the driver cannot answer the query.
max_threads_per_block
def max_threads_per_block(self) -> Int
Returns the maximum number of threads in one thread block.
On a GPU, a kernel launch whose block has more threads than this fails. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The maximum number of threads per block.
Raises:
If the driver cannot answer the query.
max_shared_memory_per_block
def max_shared_memory_per_block(self) -> Int
Returns the shared memory one thread block can use by default.
On a GPU, this is the per-block limit without opting in to a larger dynamic allocation. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The maximum shared memory per block in bytes.
Raises:
If the driver cannot answer the query.
max_grid_dim_x
def max_grid_dim_x(self) -> Int
Returns the maximum number of blocks along x in a launch grid.
On a GPU, a launch whose grid is larger than this along x fails. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The maximum grid size along x.
Raises:
If the driver cannot answer the query.
max_grid_dim_y
def max_grid_dim_y(self) -> Int
Returns the maximum number of blocks along y in a launch grid.
On a GPU, a launch whose grid is larger than this along y fails. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The maximum grid size along y.
Raises:
If the driver cannot answer the query.
max_grid_dim_z
def max_grid_dim_z(self) -> Int
Returns the maximum number of blocks along z in a launch grid.
On a GPU, a launch whose grid is larger than this along z fails. A device that isn't a GPU reports whatever its driver provides.
Returns:
Int: The maximum grid size along z.
Raises:
If the driver cannot answer the query.
max_grid_dim
def max_grid_dim(self) -> Dim
Returns the maximum grid dimensions for a kernel launch.
On a GPU, a launch whose grid exceeds this in any dimension fails.
Makes one driver query per dimension; to read a single limit, use
max_grid_dim_x(), max_grid_dim_y(), or max_grid_dim_z(). A
device that isn't a GPU reports whatever its driver provides.
Returns:
Dim: The maximum number of blocks along x, y, and z.
Raises:
If the driver cannot answer the query.
is_host_unified
def is_host_unified(self) -> Bool
Returns True if this device and the host share one physical memory pool.
Returns:
Bool: True if device and host memory are one physical pool.
Raises:
If the device cannot be queried.
get_arch
def get_arch(self) -> String
Returns the compilation target architecture of this device.
Returns:
String: The architecture name, such as sm_100a or gfx942.
Raises:
If the plugin does not report an architecture.
can_access_peer
def can_access_peer[peer_target: CompilationTarget, peer_origin: ImmOrigin, //](self, peer: Device[peer_target, peer_origin]) -> Bool
Returns True if this device can directly access memory on peer.
Parameters:
- peer_target (
CompilationTarget): The compilation target of the peer's context. - peer_origin (
ImmOrigin): The origin of the peer's context.
Args:
- peer (
Device[peer_target, peer_origin]): The device to check access to.
Returns:
Bool: False for this device itself, a peer on another driver, or a build
without peer access; otherwise the plugin's answer.
Raises:
If the plugin query fails.