Skip to main content
Log in

Mojo struct

DeviceContext

@register_passable struct DeviceContext

DeviceContext backed by a C++ implementation.

Aliases

  • device_info = from_name[::StringLiteral]():
  • device_api = from_name[::StringLiteral]().api:

Implemented traits

AnyType, CollectionElement, Copyable, Movable, UnknownDestructibility

Methods

__init__

__init__(out self, device_id: Int = 0, *, api: String = String(from_name[::StringLiteral]().api), buffer_cache_size: UInt = 0)

@implicit __init__(handle: UnsafePointer[NoneType]) -> Self

Create a Mojo DeviceContext from a pointer to an existing C++ object.

__copyinit__

__copyinit__(existing: Self) -> Self

__del__

__del__(owned self)

copy

copy(self) -> Self

Explicitly construct a copy of self.

Returns:

A copy of this value.

__enter__

__enter__(owned self) -> Self

name

name(self) -> String

api

api(self) -> String

malloc_host

malloc_host[type: AnyType](self, size: Int) -> UnsafePointer[type]

free_host

free_host[type: AnyType](self, ptr: UnsafePointer[type])

enqueue_create_buffer

enqueue_create_buffer[type: DType](self, size: Int) -> DeviceBuffer[type]

Enqueues a buffer creation using the DeviceBuffer constructor.

create_buffer_sync

create_buffer_sync[type: DType](self, size: Int) -> DeviceBuffer[type]

Creates a buffer synchronously using the DeviceBuffer constructor.

compile_function

compile_function[func_type: AnyTrivialRegType, //, func: $0, *, dump_asm: Variant[Bool, Path, fn() capturing -> Path] = __init__[::CollectionElement](False), dump_llvm: Variant[Bool, Path, fn() capturing -> Path] = __init__[::CollectionElement](False), _dump_sass: Variant[Bool, Path, fn() capturing -> Path] = __init__[::CollectionElement](False), _target: target = from_name[::StringLiteral]().target[::Int](), _ptxas_info_verbose: Bool = False](self, *, func_attribute: OptionalReg[FuncAttribute] = OptionalReg(None), out result: DeviceFunction[func, target=_target, _ptxas_info_verbose=_ptxas_info_verbose])

enqueue_function

enqueue_function[*Ts: AnyType](self, f: DeviceFunction[func, target=target, _ptxas_info_verbose=_ptxas_info_verbose], *args: *Ts, *, grid_dim: Dim, block_dim: Dim, cluster_dim: OptionalReg[Dim] = OptionalReg(None), shared_mem_bytes: OptionalReg[Int] = OptionalReg(None), owned attributes: List[LaunchAttribute] = List(), owned constant_memory: List[ConstantMemoryMapping] = List())

execution_time

execution_time[: origin.set, //, func: fn(DeviceContext) raises capturing -> None](self, num_iters: Int) -> Int

execution_time_iter

execution_time_iter[: origin.set, //, func: fn(DeviceContext, Int) raises capturing -> None](self, num_iters: Int) -> Int

enqueue_copy_to_device

enqueue_copy_to_device[type: DType](self, buf: DeviceBuffer[type], ptr: UnsafePointer[SIMD[type, 1]])

enqueue_copy_from_device

enqueue_copy_from_device[type: DType](self, ptr: UnsafePointer[SIMD[type, 1]], buf: DeviceBuffer[type])

enqueue_copy_from_device[type: DType](self, dst: UnsafePointer[SIMD[type, 1]], src: UnsafePointer[SIMD[type, 1]], size: Int)

enqueue_copy_device_to_device

enqueue_copy_device_to_device[type: DType](self, dst: DeviceBuffer[type], src: DeviceBuffer[type])

enqueue_copy_device_to_device[type: DType](self, dst: UnsafePointer[SIMD[type, 1]], src: UnsafePointer[SIMD[type, 1]], size: Int)

copy_to_device_sync

copy_to_device_sync[type: DType](self, buf: DeviceBuffer[type], ptr: UnsafePointer[SIMD[type, 1]])

copy_from_device_sync

copy_from_device_sync[type: DType](self, ptr: UnsafePointer[SIMD[type, 1]], buf: DeviceBuffer[type])

copy_device_to_device_sync

copy_device_to_device_sync[type: DType](self, dst: DeviceBuffer[type], src: DeviceBuffer[type])

enqueue_memset

enqueue_memset[type: DType](self, dst: DeviceBuffer[type], val: SIMD[type, 1])

memset_sync

memset_sync[type: DType](self, dst: DeviceBuffer[type], val: SIMD[type, 1])

memset

memset[type: DType](self, dst: DeviceBuffer[type], val: SIMD[type, 1])

stream

stream(self) -> DeviceStream

synchronize

synchronize(self)

get_driver_version

get_driver_version(self) -> Int

get_attribute

get_attribute(self, attr: DeviceAttribute) -> Int

is_compatible

is_compatible(self)

id

id(self) -> SIMD[int64, 1]

compute_capability

compute_capability(self) -> Int

get_memory_info

get_memory_info(self) -> Tuple[UInt, UInt]

can_access

can_access(self, peer: Self) -> Bool

enable_peer_access

enable_peer_access(self, peer: Self)

number_of_devices

static number_of_devices(*, api: String = String(from_name[::StringLiteral]().api)) -> Int