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).

AddressSpace

struct AddressSpace

Address space of the pointer.

This type represents memory address spaces for both CPU and GPU targets. On CPUs, typically only generic is used. On GPUs (NVIDIA/AMD), various address spaces provide access to different memory regions with different performance characteristics.

Implemented traits​

AnyType, Copyable, Deinitable, EnumLike, Equatable, ImplicitlyCopyable, Intable, Movable, RegisterPassable, TrivialRegisterPassable, Writable

comptime members​

buffer_resource​

comptime buffer_resource = AddressSpace(8)

Buffer resource GPU memory address space (AMD-specific).

BUFFER_RESOURCE​

comptime BUFFER_RESOURCE = AddressSpace.buffer_resource

Deprecated: The former name of buffer_resource.

Deprecated: 'BUFFER_RESOURCE' is deprecated, use 'buffer_resource' instead

constant​

comptime constant = AddressSpace(4)

Constant GPU memory address space (read-only).

CONSTANT​

comptime CONSTANT = AddressSpace.constant

Deprecated: The former name of constant.

Deprecated: 'CONSTANT' is deprecated, use 'constant' instead

generic​

comptime generic = AddressSpace.generic

Generic address space. Used for CPU memory and default GPU memory.

GENERIC​

comptime GENERIC = AddressSpace.generic

Deprecated: The former name of generic.

Deprecated: 'GENERIC' is deprecated, use 'generic' instead

global​

comptime global = AddressSpace(1)

Global GPU memory address space.

GLOBAL​

comptime GLOBAL = AddressSpace.global

Deprecated: The former name of global.

Deprecated: 'GLOBAL' is deprecated, use 'global' instead

local​

comptime local = AddressSpace(5)

Local GPU memory address space (per thread, private).

LOCAL​

comptime LOCAL = AddressSpace.local

Deprecated: The former name of local.

Deprecated: 'LOCAL' is deprecated, use 'local' instead

shared​

comptime shared = AddressSpace(3)

Shared GPU memory address space (per thread block/workgroup).

SHARED​

comptime SHARED = AddressSpace.shared

Deprecated: The former name of shared.

Deprecated: 'SHARED' is deprecated, use 'shared' instead

shared_cluster​

comptime shared_cluster = AddressSpace(7)

Shared cluster GPU memory address space (NVIDIA-specific).

SHARED_CLUSTER​

comptime SHARED_CLUSTER = AddressSpace.shared_cluster

Deprecated: The former name of shared_cluster.

Deprecated: 'SHARED_CLUSTER' is deprecated, use 'shared_cluster' instead

Methods​

__init__​

def __init__(value: SIMDLength) -> Self

Initializes the address space from the underlying integral value.

Args:

__eq__​

def __eq__(self, other: Self) -> Bool

Checks if the two address spaces are equal.

Args:

  • ​other (Self): The other address space value.

Returns:

Bool: True if the two address spaces are equal and False otherwise.

__getattr_param__​

static def __getattr_param__[name: StaticString]() -> Self

Resolves a target-specific named address space.

The address spaces above (generic, global, shared, ...) are the built-in GPU set. Accessing any other name as AddressSpace.<NAME> routes here, which consults the active PluginHooks backend. This keeps the set of valid names open and target-extensible — for example an accelerator backend can provide scratchpad-style spaces that do not exist on GPUs — instead of a fixed portable enum.

Constraints:

name must be defined by the active PluginHooks backend; otherwise this is a compile-time error.

Parameters:

  • ​name (StaticString): The address-space name being accessed.

Returns:

Self: The AddressSpace the active backend defines for name.

value​

def value(self) -> SIMDLength

The integral value of the address space.

Returns:

SIMDLength: The integral value of the address space.

__int__​

def __int__(self) -> Int

The integral value of the address space.

Returns:

Int: The integral value of the address space.

write_to​

def write_to(self, mut writer: T)

Formats the address space to the provided Writer.

Args:

  • ​writer (T): The object to write to.

write_repr_to​

def write_repr_to(self, mut writer: T)

Write the string representation of the AddressSpace.

Args:

  • ​writer (T): The object to write to.