Skip to main content
Log in

Mojo function

external_memory

external_memory[type: AnyTrivialRegType, *, address_space: AddressSpace, alignment: Int, name: StringLiteral = "extern_ptr_syml"]() -> UnsafePointer[type, address_space=address_space, alignment=alignment]

Gets a pointer to dynamically allocated external memory.

This function returns a pointer to external memory that can be used for dynamic shared memory allocations in GPU kernels. The memory is allocated in the specified address space with the given alignment requirements.

Note: - The memory is not initialized and must be explicitly written before reading. - The allocation size is determined at kernel launch time. - The pointer is only valid within the GPU kernel execution context. - Care must be taken to respect alignment requirements when accessing the memory.

Parameters:

  • type (AnyTrivialRegType): The type of elements stored in the memory. Must be a trivial register type.
  • address_space (AddressSpace): The memory address space to allocate in (e.g. shared, global).
  • alignment (Int): The minimum alignment requirement in bytes for the allocated memory.
  • name (StringLiteral): Optional symbolic name for the external memory allocation. Defaults to "extern_ptr_syml".

Returns:

A properly aligned pointer to the allocated external memory in the specified address space.