Skip to main content

Module usm

Module usm 

Source
Expand description

Unified Shared Memory (USM) allocation logic for Intel Level Zero.

Level Zero exposes three flavours of Unified Shared Memory:

  • Device USM (zeMemAllocDevice) — resident in device-local memory, not directly CPU-accessible; fastest for kernels.
  • Host USM (zeMemAllocHost) — resident in host memory, accessible by both CPU and GPU (the GPU reads it across the bus).
  • Shared USM (zeMemAllocShared) — migratable between host and device; the driver moves pages on demand.

The device-gated part is the raw zeMemAlloc* call (which lives in crate::memory). Everything in this module is host-side bookkeeping: the suballocation arithmetic, alignment rounding, memory-ordinal selection from a queried property table, and the memory-advise model. All of it is CPU-testable without a physical Intel GPU.

A backend allocates a few large zeMemAlloc* blocks and sub-allocates individual tensors out of them via UsmSuballocator, returning a byte offset into the block. The caller then pointer-offsets the block base — that pointer arithmetic is the only step needing a real allocation.

Structs§

MemoryAdviseState
Accumulates memory-advise hints for a single USM range.
MemoryOrdinalInfo
A single entry of zeDeviceGetMemoryProperties output.
MemoryPropertyTable
A queried memory-property table for one device.
UsmSubAllocation
A sub-allocation carved out of a USM block.
UsmSuballocator
First-fit free-list sub-allocator over a single USM block.

Enums§

MemoryAdvice
Memory-advise hints applied to a shared/device USM range.
UsmKind
The kind of Unified Shared Memory backing an allocation.

Constants§

USM_DEFAULT_ALIGNMENT
Minimum alignment Level Zero guarantees for any USM allocation (bytes).

Functions§

align_up
Round value up to the nearest multiple of alignment (a power of two).