Skip to main content
Log in

Mojo struct

DeviceContextPtr

@register_passable(trivial) struct DeviceContextPtr

Exposes a pointer to a C++ DeviceContext to Mojo.

Note: When initializing a DeviceContext from a pointer, the refcount is not incremented. This is considered safe because get_device_context() is only used within kernels and the DeviceContext lifetime is managed by the graph compiler.

Implemented traits

AnyType, UnknownDestructibility

Methods

__init__

__init__() -> Self

Initialize an empty DeviceContextPtr with a null pointer.

This creates a DeviceContextPtr that doesn't point to any device context.

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

Initialize a DeviceContextPtr from a raw pointer.

Args:

  • handle (UnsafePointer[NoneType]): A raw pointer to a C++ DeviceContext.

@implicit __init__(device: DeviceContext) -> Self

Initialize a DeviceContextPtr from a DeviceContext.

This constructor allows implicit conversion from DeviceContext to DeviceContextPtr.

Args:

  • device (DeviceContext): The DeviceContext to wrap in this pointer.

__getitem__

__getitem__(self) -> DeviceContext

Dereference the pointer to get the DeviceContext.

Returns:

The DeviceContext that this pointer points to.

get_device_context

get_device_context(self) -> DeviceContext

Get the DeviceContext that this pointer points to.

This is an alias for the dereference operator.

Returns:

The DeviceContext that this pointer points to.