fhelium.native.artifact
Encode Runner schedules as FHElium artifact entries and read and write artifact containers.
An artifact is a container file whose manifest describes entries, kernels, constants and materials; libfhelium loads it as torch.classes.fhelium.Artifact (C++ fhelium::Artifact), whose header fhelium/artifact.h specifies the format. ArtifactWriter encodes linked schedules into entries: their buffer tables and builder calls become int64 tensors, kernels become cubin images for the current device and the requested targets plus PTX, link-time constants become stored tensors, and material and state buffers name the material symbols the caller assigns. The caller completes the manifest with identity, configuration, signature and material records and writes it with save_artifact.
ARTIFACT_FORMAT
constant View source
ARTIFACT_FORMAT = 'fhelium-artifact'ARTIFACT_SCHEMA_VERSION
constant View source
ARTIFACT_SCHEMA_VERSION = 1ArtifactWriter
class View source
ArtifactWriter(targets: Iterable[str]=())Collect artifact entries with their kernels and constants.
targets names further kernel architectures, such as "sm_90", whose cubins are compiled offline; every kernel also stores the cubin of the device it was compiled for and its PTX.
entry
method
def entry(name: str, schedule: Any, *, binding: Binding) -> str: ...Encode schedule as entry name and return the name.
schedule is a fhelium.backend.runner.Schedule or a fhelium.backend.runner.ScheduleFunction, whose planned schedule (arena placement and, for a graphed function, Graph segments) is stored. binding maps each material and state buffer binding to its material symbol; a fhelium.backend.runner.Material it does not map keeps its own symbol. Called schedules become entries <name>/call<k> with the same binding. A schedule with Python calls raises ExportError that names their functions.
build
method
def build(device: torch.device) -> tuple[dict[str, Any], dict[str, torch.Tensor]]: ...Return the manifest fields entries, kernels, constants and devices and the tensors they name.
devices records device, the device the entries' Ciphertext payloads lie on, as execution and the further CUDA devices in devices as other.
copy
method
def copy(name: str, path: str | os.PathLike[str], source: str, symbols: Callable[[str], str]) -> None: ...Copy entry source of the artifact at path, with its called entries, kernels and constants, as entry name.
The planned schedule is copied as stored. symbols names the material each stored material symbol binds in this artifact.
ExportError
class View source
ExportError()Bases: ValueError
A schedule cannot be stored in an artifact.
load_artifact
function View source
def load_artifact(path: str | os.PathLike[str], device: torch.device | str | Mapping[torch.device | str, torch.device | str]) -> Any: ...Load an artifact as torch.classes.fhelium.Artifact.
A single device places the artifact's execution device there; a mapping places each artifact CUDA device it names on the CUDA device it maps to. Other CUDA devices of the artifact keep their indices.
load_container
function View source
def load_container(path: str | os.PathLike[str], device: torch.device | str='cpu') -> tuple[dict[str, torch.Tensor], dict[str, str]]: ...Return the tensors on device and the metadata of a container file.
native_identity
function View source
def native_identity() -> dict[str, str]: ...Return the identity of the loaded native library and Triton that artifacts record and loaders compare.
triton_version is empty in environments without Triton, such as CPU-only Torch installations.
read_container_header
function View source
def read_container_header(path: str | os.PathLike[str]) -> tuple[dict[str, str], dict[str, Any]]: ...Return the metadata and the tensor header (name to dtype, shape and offsets) of a container file without reading its tensors.
save_artifact
function View source
def save_artifact(path: str | os.PathLike[str], manifest: Mapping[str, Any], tensors: Mapping[str, torch.Tensor], *, overwrite: bool=False) -> None: ...Write an artifact; manifest receives the native identity unless it records one.
save_container
function View source
def save_container(path: str | os.PathLike[str], tensors: Mapping[str, torch.Tensor], metadata: Mapping[str, str], *, overwrite: bool=False) -> None: ...Atomically write a container file readable by owner only.