fhelium.backend.runner
Build exec schedules into libfhelium Runners and execute them.
A Schedule is the Runner construction of one exec block: its buffers with storage classes and layouts, its host integer and float registers, and the ordered builder calls that append operations and structured control flow, held natively. Translating a block resolves operator arguments, kernel launch parameters, loop-carried values and results once; realizing the schedule encodes the builder calls as an artifact entry does, and libfhelium decodes them and builds a torch.classes.fhelium.Runner with the kernels, called Runners and process groups they name and the materials, link-time constants and mutable resource state bound to their buffers. Execution passes the Tensor, integer and float inputs to the Runner and returns its output buffers. Python implementations run between Runner instructions: an execution pauses at each exec.python_call, the driver calls the function with the instruction's operands and resumes the execution with its results.
release_groups
function View source
def release_groups(name: str | None=None) -> None: ...Release the process groups held by compiled schedules.
Each Runner bound to the group registered as name, or to any group for None, drops its captured graphs and group references; a released schedule function binds its groups again at its next execution. A process group whose collectives a live graph captured cannot be destroyed, so fhelium.distributed.shutdown and interpreter exit call this first.
ArtifactFunction
class View source
ArtifactFunction(loaded: LoadedArtifact, name: str, *, graphs: bool=False, adaptive: bool=False)Bases: ScheduleFunction
Execute one entry of a LoadedArtifact.
The entry's planned schedule, kernels, constants and materials come from the artifact, whose Runners share them; schedule carries only the entry's inputs and outputs. The entry named <name>.graphs, when present, holds the same schedule planned with Graph segments, which graphed runs.
with_materials
method
def with_materials(materials: Mapping[str, object]) -> ArtifactFunction: ...Bind materials in the artifact and return a function whose Runners read them.
Runners built before keep the materials they were built with.
graphed
method
def graphed(key: object=None, *, adaptive: bool=False) -> ScheduleFunction: ...runner
method
def runner(*, private: bool=False) -> Any: ...CalledSchedule
class View source
CalledSchedule(module: Any, name: str, destinations: tuple[int, ...] = ())Callee of exec.call: the function name of a translated exec module, in destination form for destinations.
module returns the schedule function of a function name and destination positions; the destination form writes the results at those positions into storage the caller passes as trailing Tensor arguments.
Attributes
| Name | Type | Default/value |
|---|---|---|
module | Any | |
name | str | |
destinations | tuple[int, ...] | () |
function
property
function: ScheduleFunctionschedule
property
schedule: Schedulerunner
method
def runner() -> Any: ...Constant
class View source
Constant(tensor: torch.Tensor)A buffer bound to a link-time constant Tensor.
Attributes
| Name | Type | Default/value |
|---|---|---|
tensor | torch.Tensor |
LoadedArtifact
class View source
LoadedArtifact(path: str, device: torch.device | Mapping[torch.device | str, torch.device | str])A loaded artifact (torch.classes.fhelium.Artifact) with its decoded manifest.
device places the artifact's execution device, or maps artifact CUDA devices to CUDA devices (fhelium.native.artifact.load_artifact). devices maps each device the artifact uses to the device it is placed on, the execution device first, and device is the placed execution device.
place
method
def place(device: torch.device | str) -> torch.device: ...The device that artifact device device is placed on.
bind
method
def bind(materials: Mapping[str, object]) -> None: ...Bind the Tensors of the declared material symbols in materials.
bind_group
method
def bind_group(symbol: str, name: str) -> None: ...Bind the group symbol of the artifact's entries to the c10d group registered as name.
release_groups
method
def release_groups() -> None: ...Release the group references and captured graphs of the Runners built from the artifact; the groups are bound again with bind_group.
function
method
def function(name: str) -> ArtifactFunction: ...Material
class View source
Material(symbol: str)A buffer bound to the material of symbol.
Attributes
| Name | Type | Default/value |
|---|---|---|
symbol | str |
PythonCallee
class View source
PythonCallee(function: Callable[..., Sequence[torch.Tensor]], kinds: tuple[int, ...])Python function of one exec.python_call and its operand order.
kinds lists the operand kinds in call order (BUFFER, INT_REGISTER or FLOAT_REGISTER); the Runner passes each kind as a separate list.
Attributes
| Name | Type | Default/value |
|---|---|---|
function | Callable[..., Sequence[torch.Tensor]] | |
kinds | tuple[int, ...] |
Resources
class View source
Resources(indices: tuple[int, ...], single: bool = False, value: bool = False)Linked resources selected by requirement position.
Attributes
| Name | Type | Default/value |
|---|---|---|
indices | tuple[int, ...] | |
single | bool | False |
value | bool | False |
Schedule
class View source
Schedule(code: Any, int_registers: int, float_registers: int, inputs: tuple[tuple[str, int], ...], output_buffers: tuple[int, ...], outputs: tuple[tuple[str, object], ...], bindings: tuple[tuple[int, object], ...], objects: tuple[Any, ...], graphs: bool = False, groups: tuple[Group, ...] = (), fixed_rank: bool = False, read_in_place: tuple[int, ...] = ())Runner construction of one exec block.
code is the native construction (fhelium._mlir._mlir_libs._fhelium_schedule.Code): buffers with storage classes and optional layouts, and builder calls in block order whose kernels, called schedules and Python callees are indices of objects. inputs lists the kind and buffer or register of each argument, outputs the result of each schedule result (("buffer", position) among the Runner outputs, ("input", index) or ("value", object)), and bindings the bound value of material and state buffers.
Attributes
| Name | Type | Default/value |
|---|---|---|
code | Any | |
int_registers | int | |
float_registers | int | |
inputs | tuple[tuple[str, int], ...] | |
output_buffers | tuple[int, ...] | |
outputs | tuple[tuple[str, object], ...] | |
bindings | tuple[tuple[int, object], ...] | |
objects | tuple[Any, ...] | |
graphs | bool | False |
groups | tuple[Group, ...] | () |
fixed_rank | bool | False |
read_in_place | tuple[int, ...] | () |
python_calls
property
python_calls: boolScheduleFunction
class View source
ScheduleFunction(schedule: Schedule, materials: Mapping[str, object]={}, resources: Sequence[object]=(), *, arena: bool=False, graphs: bool=False, adaptive: bool=False, shared: bool=False)Execute one schedule on a Runner built at the first call.
materials supplies material Tensors by symbol and resources the linked resources that Resources selections name. Kernels compile or load from Triton's cache when the Runner is built, so a caller that compiles them concurrently beforehand only loads them.
With arena the Runner keeps the schedule's non-escaping allocations in one region per device, planned natively when the Runner is built (fhelium.backend.schedule.NativeScheduleFunction); the buffer stays allocated while the Runner lives. With shared as well, that buffer is the device's shared_arena, which every shared function on the device uses for its temporaries one execution at a time. An execution that starts while another shared execution on the device has not returned, such as one made by a Python implementation inside a schedule or by another thread, runs on a Runner with a private arena instead. Eager fragments leave arena off, so their temporaries return to the caching allocator after each call. graphed returns the function that runs the same schedule with CUDA Graph segments.
with_materials
method
def with_materials(materials: Mapping[str, object]) -> ScheduleFunction: ...Return a function of the same schedule with other material bindings.
graphed
method
def graphed(key: object=None, *, adaptive: bool=False) -> ScheduleFunction: ...Return a function of this schedule whose Runner captures Graph segments.
Each key selects its own Runner and captures, for callers that execute the schedule under different conditions such as grad or autocast modes. With adaptive, which the first request for a key fixes, each segment compares the device time of its first direct execution with the median of three replays and keeps its graph only when the replays are faster; otherwise it releases the graph and executes directly from then on. Results the Runner keeps in its output region are returned without a copy; before its next execution overwrites them, the Runner moves the results the caller still references to fresh storage.
runner
method
def runner(*, private: bool=False) -> Any: ...Return the Runner, building it at the first request.
private selects a Runner whose arena no other function shares, for executions nested in another shared execution and for schedule calls.
release_groups
method
def release_groups() -> None: ...Release the group references and captured graphs of this function's Runners; the next execution builds them again.
State
class View source
State(resource: object, field: str)A buffer bound to the Tensor field of a live resource.
resource is a Resources selection or the resource object itself.
Attributes
| Name | Type | Default/value |
|---|---|---|
resource | object | |
field | str |
compiled_execution_bytes
function View source
def compiled_execution_bytes(device: int) -> int: ...Return the device memory that compiled schedules hold on one CUDA device: the shared arena and the CUDA Graph pool of its Runners.
direct_call
function View source
def direct_call(schedule: Schedule) -> Callable[..., tuple[object, ...]] | None: ...Return a function that calls the single operator of schedule directly, or None.
A schedule that consists of one operator call on its inputs and link-time constants and returns that call's results needs no Runner: for such Eager fragments the dispatcher call costs less host time than a Runner execution.