fhelium.backend.schedule
Translate MLIR exec functions into Runner schedules.
An exec function is the lowered form of one linked function of a compiled module or of one Eager operation call: its arguments are Tensor buffers and host scalars, and its operations call operators, launch kernels, allocate, view, copy and zero buffers, read materials, constants and resource state, run collectives and call other exec functions or Python implementations. Kernels, launch signatures, Python callables, live resources and link-time constant Tensors are entries of an ObjectTable that the operations reference by index.
instantiate composes lowered fragment bodies and calls of other functions into one function per linked function. schedule_functions translates functions into fhelium.backend.runner.Schedule tables in native code and returns one NativeScheduleFunction per function; fragment_function does the same for one Eager fragment. A schedule's asynchronous transfers, CPU worker tasks, storage classes, arena offsets and Graph segments are planned natively when its function first builds an arena Runner.
HOST_READS
constant View source
HOST_READS = frozenset({'aten::item', 'aten::_local_scalar_dense', 'aten::nonzero', 'aten::nonzero_static', 'aten::masked_select', 'aten::unique', 'aten::_unique', 'aten::_unique2', 'aten::unique_consecutive', 'aten::unique_dim', 'aten::equal', 'aten::is_nonzero', 'aten::allclose', 'aten::_assert_async'})NativeScheduleFunction
class View source
NativeScheduleFunction(module: _Module, key: tuple[str, tuple[int, ...]], schedule: Schedule, materials: Mapping[str, object]={}, resources: Sequence[object]=(), **options: Any)Bases: ScheduleFunction
Schedule function of a translated exec function; with arena, its schedule is planned natively when the Runner is built.
with_materials
method
def with_materials(materials: Mapping[str, object]) -> ScheduleFunction: ...graphed
method
def graphed(key: object=None, *, adaptive: bool=False) -> ScheduleFunction: ...ObjectTable
class View source
ObjectTable()Append-only table of the Python objects that exec operations reference by index.
One table serves every function of a module; index returns the position of an object, adding it on first use, by identity.
index
method
def index(value: object) -> int: ...OverlapReport
class View source
OverlapReport(moved: tuple[tuple[int, int], ...] = (), transfers: tuple[tuple[str, int], ...] = (), tasks: int = 0)What overlap planning changed in one schedule.
moved lists early-issued transfers as (original, issued-after) top-level positions, where -1 is the start of the schedule; transfers counts asynchronous transfers by direction (h2d, d2h, and comm for collectives); tasks counts the CPU work items run on the worker lane.
Attributes
| Name | Type | Default/value |
|---|---|---|
moved | tuple[tuple[int, int], ...] | () |
transfers | tuple[tuple[str, int], ...] | () |
tasks | int | 0 |
PlanReport
class View source
PlanReport(arena_bytes: tuple[tuple[str, int], ...], arena_buffers: int, segments: int, output_bytes: int = 0, overlap: OverlapReport = OverlapReport())Arena bytes per device, arena buffer count, Graph segment count and output region bytes of a planned schedule, with its OverlapReport.
Attributes
| Name | Type | Default/value |
|---|---|---|
arena_bytes | tuple[tuple[str, int], ...] | |
arena_buffers | int | |
segments | int | |
output_bytes | int | 0 |
overlap | OverlapReport | OverlapReport() |
fragment_function
function View source
def fragment_function(fragment: Fragment) -> Callable[..., tuple[object, ...]]: ...Return the function of a lowered Eager fragment.
The fragment is translated in one MLIR context that every fragment of the process shares. A fragment consisting of one operator call that returns its results calls the operator directly (fhelium.backend.runner.direct_call); every other fragment runs on a Runner whose temporaries return to the caching allocator after each call.
instantiate
function View source
def instantiate(module: ir.Module, name: str, argument_types: Sequence[str], fragments: Sequence[str], calls: object, outputs: Sequence[int], *, callees: Sequence[str]=(), read_in_place: Sequence[bool]=(), materials: Sequence[str]=()) -> None: ...Add the exec function name to module from fragment bodies and function calls.
argument_types are the MLIR types of the function arguments, which take value ids 0 to len(argument_types) - 1. calls is an int64 sequence (a list, bytes or any int64 buffer) holding per operation fragment, operand count, operand ids, result count, result ids: fragment k >= 0 clones the body of fragments[k] with the operands as its arguments, and -(k + 1) calls callees[k]. outputs are the returned value ids and read_in_place marks arguments whose storage Graph segments read at its address, such as keys, plaintexts and tables. An id whose materials entry is a nonempty symbol reads that material (exec.material) instead of being a function argument; the remaining ids become the arguments in id order.
register_exec_dialects
function View source
def register_exec_dialects(context: ir.Context) -> None: ...Load the exec, scf, arith and func dialects into context.
schedule_functions
function View source
def schedule_functions(module: ir.Module, table: ObjectTable, *, names: Sequence[str], materials: Mapping[str, object]={}, resources: Sequence[object]=(), describe: Callable[[object], object]=lambda value: value) -> dict[str, ScheduleFunction]: ...Translate the exec functions names of module and return their schedule functions.
Functions that names call through exec.call are translated as well. materials binds exec.material symbols and resources the fhelium.backend.runner.Resources selections of state bindings; describe returns the recorded form of a live resource bound to state buffers. Each function keeps non-escaping allocations in the shared arena of its device; fhelium.backend.runner.ScheduleFunction.graphed returns its CUDA Graph form.