Compiled artifact format
A compiled artifact stores the specializations of a compiled callable as Runner schedules that libfhelium loads without Python. fhelium.compile.export writes artifacts, fhelium.compile.load and C++ fhelium::Artifact read them, and the persistent compile cache stores its entries in the same format. The format is specified in csrc/include/fhelium/artifact.h and csrc/include/fhelium/container.h; this page summarizes it and the Python components that produce it.
Container
An artifact is a container file in the safetensors layout: an 8-byte little-endian header length, a JSON header that maps each tensor name to its dtype, shape, and [begin, end) byte range, and the raw tensor bytes. The reserved header key __metadata__ holds a string-to-string map. Writers order tensors by decreasing element alignment and then by name, pad the header to a multiple of 8 bytes, and write metadata keys in sorted order, so the same tensors and metadata produce the same bytes. Files are written through a temporary file that is renamed over the destination and are readable by their owner only. complex64 and complex128 use the dtypes C64 and C128, which only FHElium reads. FHElium value files use the same container with their own format metadata.
An artifact's metadata has three keys: fhelium.format ("fhelium-artifact"), fhelium.schema_version (1), and fhelium.manifest, a JSON object.
Manifest
| Field | Content |
|---|---|
identity | fhelium_version, native_schema_hash (SHA-256 of the sorted registered fhelium_* operator schemas), torch_abi (Torch version and C++11 ABI flag), cuda_runtime, and the producing Triton version. A loader rejects a file whose identity differs from its own. |
config | The CKKS configuration text, or null when the schedules read no tables. |
devices | {execution, other}: the device the Ciphertext payloads of the entries lay on when they were written ("cpu" or "cuda:<k>"), and the further CUDA devices that the entries, constants, and materials use. |
signatures | The exported call signatures, the entry each one runs, its material working set, and, as results, the value type and metadata of each output in output order. A signature with per-call preparation adds prepare, the name of its preparation entry, and prepare_arguments, the argument path and payload position of each caller Tensor that entry reads. |
materials | {keys, rounding, tables, weights}: records {symbol, binding, shape, dtype, device, ...}; key records add role and layout, and rounding records rounding.<device> have kind rounding_state. |
prepare | {name: {entry, inputs, outputs}}: per-call preparation entries. inputs lists the entry inputs in order: {argument: k} is the k-th caller Tensor and a string names a bound material; outputs names the materials the entry produces, in output order. |
entries | {name: entry}: Runner schedules. |
kernels | Kernel records with launch parameters, scratch sizes, the Triton version, and images ({<arch>: tensor, ptx: tensor} as uint8 tensors). |
constants | [{tensor, sizes, strides, offset, device}]: link-time constant Tensors, each a strided view of one stored tensor. |
parameters | The parameter names of the exported function, for keyword calls. |
rank | The process rank the schedules were captured for when the source reads the rank or its reads cannot be identified, otherwise null. fc.load rejects a file with a different rank. |
default_groups | The process-group symbols captured on the default group, which bind to the torch.distributed WORLD group. |
Material bindings
Each material record names how the loader obtains its Tensor:
| Binding | Source | Examples |
|---|---|---|
caller | Bound by the loading process (bind_key, seed_rounding) | Evaluation keys with their role and prime and digit layout; the random stream state that plaintext encoding and real-scalar arithmetic advance, one per device |
built | Output output of entry entry, normally tables | NTT, RNS, and key-switching tables produced by registered builder operators |
embedded | Stored container tensor tensor, optionally as a view {sizes, strides, offset} | Plaintexts computed by a preparation function that reads only function materials, Tensors and plaintexts the function reads, tables without a registered builder |
prepare | Output output of per-call preparation entry entry | Plaintexts encoded from Tensors of the call arguments |
Records that name one stored tensor share its storage. device ("cpu" or "cuda:<k>") is the device the material lies on, placed as the loader places the artifact's devices. An embedded material that the example call supplied as an argument records its argument path, and a loaded function binds it from each call's arguments.
Entries
fhelium.compile.export stores each specialization as two entries: its planned schedule call<i> and, for CUDA, the same schedule planned with CUDA Graph segments call<i>.graphs. Called schedules become entries <name>/call<k>. A specialization whose preparation function reads materials located in the call arguments adds the per-call preparation entry call<i>.prepare (_export.py:_preparation_entry): the preparation function traced through the Eager interpreter and recorded as one exec fragment, whose plaintext encoding reads and advances the device's rounding state. An entry holds a string table, the names of two int64 tensors buffers and code, the integer and float register counts, inputs and outputs, output_buffers, bindings ([buffer, {material: symbol}] or [buffer, {constant: index}]), graphs, callees, arena_bytes, output_bytes, working_set, groups (the process-group symbol and size of each Runner group id; the default group is named world), and streams (the role of each Runner stream id, such as h2d, d2h, or comm, or null without streams). Events and CPU-lane tasks of a planned schedule are builder calls of the entry.
buffers encodes each buffer's storage class, sizes, strides, dtype, and device as string-table indices and integers. code encodes the Runner builder calls: the method name, the argument count, and each argument as a tag and payload, where the tags cover None, int, float (IEEE-754 bits), bool, string, list, dtype, device, kernel index, callee entry, memory format, and layout. Linking and loading build a fhelium::exec::Runner from this encoding with one decoder (csrc/runner/build.cpp), so an entry reproduces the Runner that linking built. Code::encode also reports the CUDA devices that an entry's buffers, device arguments, launches, segments, and streams use, and the writer records them with the devices of constants and material records in the manifest field devices.
fhelium.native.artifact.ArtifactWriter encodes the entries, stores each kernel as the cubin of the exporting device, the cubins of the requested targets, and PTX, and raises ExportError for schedules with python_call instructions. Material and state buffers are stored by symbol; a state buffer is named state.<requirement>.<field> after the resource requirement whose live value owns it.
Loading
fhelium::Artifact places the artifact's devices by a device map from artifact CUDA device indices to process CUDA device indices: the constructor with one device maps the recorded execution device to it, and the constructor with a DeviceMap maps the listed devices. The decoder (placed in csrc/runner/build.cpp) applies the map to buffer devices, device arguments, and launch, segment, and stream devices, and constants and materials are placed from their record device through the same map; unlisted devices keep their index, and the CPU stays the CPU. Kernels select the image of the placed execution device's architecture. Before anything is placed, the constructor raises an error naming the artifact device whose placed device the process does not have. fhelium::Artifact then checks the identity, binds caller materials and process groups (bind_group), seeds the rounding states (seed_rounding(seed), or from the operating system in prepare() for states still unbound), runs the tables entry once in prepare(), and builds Runners for entries on request. Tables with equal builder calls are shared across artifacts loaded in one process. The Python loader fhelium.compile.load wraps the same class: it matches keys, binds process groups, seeds the rounding states from seed, and returns a LoadedFunction that selects the stored signature matching each call. Artifact::refresh(name, arguments) runs a per-call preparation entry on the caller Tensors: its first run binds the output materials, and later runs copy into the bound Tensors, so Runners and their captured Graphs read unchanged addresses. LoadedFunction calls it before an entry when the version counters of the Tensors the preparation entry reads differ from those of its last run.
Compile cache entries
The persistent compile cache stores each specialization in the same container format with one entry, entry or entry.graphs, beside the MLIR bytecode of its pipelined module. A cache entry stores no material data: it records the recipes of the schedule's constant arguments and the location of each material in the call arguments, the source function, or the Engine, and a hit binds the current values at those locations. An exported artifact embeds all materials other than keys and tables and does not depend on the source that produced it. The compile cache describes the keys and hits.