Skip to main content
Log in

Mojo struct

ConstantMemoryMapping

@register_passable(trivial) struct ConstantMemoryMapping

Represents a mapping of constant memory between host and device.

This struct encapsulates the information needed to manage constant memory that can be accessed by GPU kernels. Constant memory provides a fast, read-only cache accessible by all threads on the GPU device.

Attributes: name: A string identifier for the constant memory mapping. ptr: Pointer to the memory location. byte_count: Size of the memory mapping in bytes.

Fields

  • name (StringSlice[StaticConstantOrigin]): A string identifier for the constant memory mapping. This name is used to uniquely identify the constant memory region in the GPU programming model, allowing the runtime to properly associate the memory with kernel references to constant memory symbols.
  • ptr (UnsafePointer[NoneType]): Pointer to the host memory location that will be mapped to device constant memory. This raw pointer represents the starting address of the memory region that will be accessible as constant memory on the GPU. The memory should remain valid for the lifetime of any kernels that access it.
  • byte_count (Int): Size of the memory mapping in bytes. Specifies the total size of the constant memory region. This value is used by the runtime to determine how much data to transfer between host and device. The size must be sufficient to hold all data needed by GPU kernels.

Implemented traits

AnyType, CollectionElement, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

__init__

__init__(name: StringSlice[StaticConstantOrigin], ptr: UnsafePointer[NoneType], byte_count: Int) -> Self

Initializes a new constant memory mapping.

Args:

  • name (StringSlice[StaticConstantOrigin]): A string identifier for the constant memory mapping.
  • ptr (UnsafePointer[NoneType]): Pointer to the memory location to be mapped.
  • byte_count (Int): Size of the memory mapping in bytes.