IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

staging_workspace

def staging_workspace[dtype: DType](ctx: DeviceContext, elements: Int) -> MutPointer[Scalar[dtype], MutUntrackedOrigin]

Returns this device's staging workspace, holding at least elements.

The buffer outlives every caller (see the module docstring), so the pointer is safe to hand to a kernel and to keep in a captured graph. A request larger than the workspace grows it to at least twice its old size, and the old buffer is left mapped rather than freed: a launch still holding its address cannot be told apart from one that is not. Doubling bounds what a rising sequence of requests parks to under the final size again.

Parameters:

  • โ€‹dtype (DType): Element type the caller reads and writes the region as.

Args:

  • โ€‹ctx (DeviceContext): Device context the caller's launches run on.
  • โ€‹elements (Int): Elements of dtype the caller needs.

Returns:

MutPointer[Scalar[dtype], MutUntrackedOrigin]: The workspace's first element, on ctx's device, at the allocator's own alignment.

Raises:

If the device cannot allocate the workspace.

Was this page helpful?