Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,11 @@ normalization and projection examples. Autotuning uses private seeded fixtures.
`ignition.preparation.scratch.ScratchArena` supplies byte storage for kernel
preparation and candidate measurement. `arena.views(*shapes_and_dtypes)` returns
contiguous typed views with 256-byte-aligned, nonoverlapping regions.
`register_parallel(*plans)` declares preparation workspaces that must coexist.
`register_parallel(*plans, reserve_sms=0)` declares preparation workspaces that
must coexist and optionally enforces a cooperative SM reservation floor alongside
`register_cooperative_plan(plan, reserve_sms=...)`, `require_reserve_sms`, and
`resolve_reserve_sms` so overlapping cooperative plans leave headroom for
concurrent auxiliary-stream collectives.
The arena reserves the maximum requirement across sequential operations and
concurrent groups in the complete candidate envelope. After selection and CUDA
synchronization, `trim(nbytes)` sizes that storage from the selected plans, and
Expand Down
2 changes: 1 addition & 1 deletion docs/core-format-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ not substitutes for identifiers.
| `Initializer` | Allocation name, destination offset, source `PayloadUse`. |
| `ExecutableResource` | Preassigned resource ID, kind, stored compressed `PayloadSlice`, signed decoded length, 4 MiB chunk metadata, and compressed chunk commitments. |
| `Module` / `Function` | Cubin resource reference; module reference, symbol, parameter layout and launch attributes. |
| `Graph` | Graph name, instantiation flags, compressed graph resource reference, node and edge counts, and function dependencies. Graph bytes encode nodes, edges, parameters, and dependencies. The rank's `flare.runtime.Execution` record carries each graph's operation kind, capacities, and input bindings. |
| `Graph` | Graph name, instantiation flags, compressed graph resource reference, node and edge counts, function dependencies, and optional per-graph SM bounds (`min_compute_sms`, `max_cluster_size`, with `0` meaning unspecified). Graph bytes encode nodes, edges, parameters, and dependencies. The rank's `flare.runtime.Execution` record carries each graph's operation kind, capacities, and input bindings. |
| `PreparedWeightView` | Semantic tensor name, stable group, dtype, shape, strides, allocation/view binding, source tensor identities and logical ranges, concatenation order, padding/fills, typed packing parameters and locality tile, and quantization statistic domain. |
| `ExternalExtentTable` | Channel name matching an `Execution.async_transfers` entry, one `Weights`-role `PayloadUse` directory, and ordered `Weights`-role `PayloadUse` segment slices entering the rank's authenticated payload set. Each directory entry is 24 little-endian bytes (`segment_index: u32`, `reserved: u32` which must be zero, `offset: u64`, `length: u64`), validated at export and load for channel direct-I/O alignment and segment bounds. |

Expand Down
19 changes: 13 additions & 6 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ tier: `--prefix-cache-memory`, `--prefix-cache-disk`, or `--prefix-cache-pool`):
predictor, 4-lane bit packing, 32-way warp-interleaved 12-bit static rANS,
on-GPU packet assembly, and parallel GPU CRC32 directly on each rank's
lowest-priority CUDA transfer stream using a compact 3-buffer aliased
per-rank GPU workspace budgeted before KV cache sizing. On cores that declare
a persistent worker, Helios reserves a third disjoint CUDA Green Context SM
partition for GPU codec execution so codec kernels never share SMs with
cooperative compute graphs, and opens the host prefix store (calling
`cuModuleLoadData`) before starting the persistent worker graph. Only
per-rank GPU workspace budgeted before KV cache sizing. Helios reserves a
disjoint CUDA Green Context SM partition for GPU codec execution—a 2-way
`(codec, compute)` split on standard cores or a 3-way
`(worker, codec, compute)` split on cores declaring a persistent worker—so
codec kernels never share SMs with cooperative compute graphs, validates each
graph's `min_compute_sms` and `max_cluster_size` bounds against the compute
partition, and opens the host prefix store (calling `cuModuleLoadData`)
before starting any persistent worker graph. Only
compressed bytes cross PCIe during capture and GPU-decoded restores, while
small non-matrix restores (< 256 KiB) or mutex-contended restores decode on
the bounded CPU worker pool over async HtoD DMA, with zero external runtime
Expand All @@ -70,7 +73,11 @@ Both modes compress at the VRAM-to-DRAM boundary and keep compressed bytes
across local DRAM (`MemoryStore`), local disk (`DiskStore`, standalone or
composite `--prefix-cache-memory` + `--prefix-cache-disk`), manager DRAM
(`selene-manager` arena), NVMe record files, shared-memory windows, TCP
streams, and RDMA claims. After capturing a packed record into local DRAM
streams, and RDMA claims. On multi-rank deployments, byte-identical per-rank
packed units (such as replicated MLA pages) are deduplicated across ranks into
one stored payload with `PackedUnit.replicas` populated before compacting DRAM
slabs, spilling to disk, or exporting to `selene-manager`. After capturing a
packed record into local DRAM
slabs, `MemoryStore` compacts the compressed payloads and releases unused
trailing slabs; `CompositeStore` spills those compressed units verbatim into v4
`.ckpt` files on `--prefix-cache-disk` and promotes v4 `.ckpt` files back into
Expand Down
4 changes: 3 additions & 1 deletion docs/preparation-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ workspace through an explicit pending record. The fork waits for input
production. The join receives the pending operands and the main-stream result
that must precede it, then waits for the auxiliary stream. Custom operators
declare these dependencies so Inductor keeps storage live through the join.
`ScratchArena.register_parallel` sizes simultaneous preparation workspaces.
`ScratchArena.register_parallel` sizes simultaneous preparation workspaces and
enforces cooperative SM reservation floors (`reserve_sms`) against plans
registered with `register_cooperative_plan`.
Serving overlap uses invocation-local tensors.

Capture serialized graph variants with the same CUDA graph pool through
Expand Down
79 changes: 47 additions & 32 deletions docs/runtime-core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,32 +657,47 @@ then rebased onto the live addresses and validated, and the server starts
from this reconstructed contract. `flare run CORE` in
`flare-cli/src/main.rs` starts the shared server directly from the typed contract.

When a single-rank core declares an entry in `Execution.persistent_workers`
(repeated field 8; at most one entry is currently accepted, and multi-rank or
multi-host cluster cores declaring a persistent worker are rejected),
`NativeResources` resolves the CUDA driver Green Context entrypoints optionally
at driver load (failing load explicitly only when a core requires them on an
unsupported driver), retains the device's primary context, and partitions device
SMs with `cuDevSmResourceSplit` into disjoint structured SM resource groups:
two groups (a `worker` green context aligned to the device's co-scheduled SM
alignment and a `compute` backfill green context preserving co-scheduled SM
alignment for multi-CTA cluster launches) when prefix-cache offload does not use
GPU compression, or three groups (`worker`, one minimal aligned `codec` green
context, and `compute` backfill) when prefix-cache offload is enabled with
`--lossless-kv-compression gpu` (failing load explicitly if remaining SMs cannot
form a structured compute partition). Helios applies the core's recorded CUDA
context limits and cache configuration to the primary context and every created
green context (`worker`, `compute`, and `codec` when present), and opens
non-blocking streams for the worker and compute contexts. Offload transfers and
GPU KV-codec kernels bind the `codec` green context when present and the rank's
base context otherwise, while host slab registration remains portable
(`CU_MEMHOSTREGISTER_PORTABLE`) on the base context. All modules, kernels, graph
executables, and host prefix-store GPU codec modules are loaded, instantiated
under their partition's green context (clamping cooperative grids to that
partition's SM count), and uploaded on their partition's non-blocking stream
before the persistent worker starts; `ModelRuntime` opens the host prefix store
before constructing `RankExecutor` so `cuModuleLoadData` for embedded GPU codec
kernels finishes before any worker graph launches. The executor launches the
When a core declares an entry in `Execution.persistent_workers` (repeated field
8; at most one entry is accepted on single-rank cores, and multi-rank or
multi-host cluster cores declaring a persistent worker are rejected) or when
prefix-cache offload enables `--lossless-kv-compression gpu` on any single-rank
or multi-rank core, `NativeResources` resolves the CUDA driver Green Context
entrypoints optionally at driver load (failing load explicitly only when a core
or offload configuration requires them on an unsupported driver), retains the
device's primary context, and partitions device SMs into disjoint green
contexts: two groups `(worker, compute)` for persistent-worker cores without
GPU compression, two groups `(codec, compute)` for standard cores with
`--lossless-kv-compression gpu`, or three groups `(worker, codec, compute)` when
both are active. On CUDA 13.1+ drivers Helios partitions SMs with
`cuDevSmResourceSplit` (giving the compute group backfill discovery and
co-scheduled SM alignment); on CUDA 13.0 drivers lacking
`cuDevSmResourceSplit`, Helios falls back to `cuDevSmResourceSplitByCount`,
placing the compute partition in the structured `result[0]` group and, for
three-way splits, refreshing the remainder through a temporary green context to
split `worker` and `codec`. Helios validates the compute partition's
driver-reported SM count and co-scheduled alignment against the maximum
`min_compute_sms` and `max_cluster_size` across non-worker graphs (failing load
explicitly with `--lossless-kv-compression cpu` guidance when remaining SMs or
cluster alignment cannot satisfy the core's graphs), applies the core's recorded
CUDA context limits and cache configuration to the primary context and every
created green context (`compute`, plus `worker` and `codec` when present), and
opens non-blocking streams for the created worker and compute contexts. Offload
transfers and GPU KV-codec kernels bind the `codec` green context when present
and the rank's base context otherwise, while host slab registration remains
portable (`CU_MEMHOSTREGISTER_PORTABLE`) on the base context. `Stream::open`
and `Stream::open_lowest_priority` query `cuStreamGetGreenCtx` once and route
Green Context streams through `cuMemcpyAsync` inside `Stream::copy_batch` to
avoid R580 driver faults on `cuMemcpyBatchAsync_v2` against `cuMemMap` VMM
ranges. All modules, kernels, graph executables, and host prefix-store GPU codec
modules are loaded, instantiated under their partition's green context (clamping
cooperative grids to that partition's SM count and validating each graph's
`min_compute_sms`, `max_cluster_size`, and per-node
`CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION` attributes against the partition's SM
count and driver-reported co-scheduled alignment), and uploaded on their
partition's non-blocking stream before any persistent worker starts;
`ModelRuntime` opens the host prefix store before constructing `RankExecutor` so
`cuModuleLoadData` for embedded GPU codec kernels finishes before any worker
graph launches. When a persistent worker is declared, the executor launches the
worker graph once on its worker stream only after startup completes, while
compute graphs replay on the compute green context. When the entry also declares
an optional mapped-host `metrics` reference with positive `metrics_count`,
Expand All @@ -700,12 +715,12 @@ context before any rank frees shared memory; second, while `Memory::MappedHost`
mailboxes and CUDA contexts remain live, Engram background workers and prefix
offload workers join, after which every rank destroys its streams, executables,
modules, and allocations (draining active telemetry counter readers before
unmapping); third, every rank destroys all created green contexts (worker,
compute, and optional codec, clearing rather than restoring the caller's current
context if it referred to any destroyed green context), virtual-address
reservations, and primary CUDA contexts in reverse rank order. If any rank fails
drain, all ranks retain their CUDA and host resources until process
exit.
unmapping); third, every rank destroys all created green contexts (`compute`,
plus `worker` and `codec` when present, clearing rather than restoring the
caller's current context if it referred to any destroyed green context),
virtual-address reservations, and primary CUDA contexts in reverse rank order.
If any rank fails drain, all ranks retain their CUDA and host resources until
process exit.

Before CUDA initialization or serving worker threads, Flare restricts
`CUDA_VISIBLE_DEVICES` to `--gpus`, resolving indices within an inherited mask.
Expand Down
76 changes: 76 additions & 0 deletions heliopause/src/export/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,34 @@ fn function_layout(cuda: &Cuda, function: usize) -> ExportResult<Vec<(usize, usi

const KERNEL_ATTRIBUTES: [c_int; 10] = [1, 2, 4, 5, 8, 9, 10, 11, 13, 14];

fn kernel_cluster_size(kernel: &wire::Kernel) -> ExportResult<u32> {
let Some(attribute) = kernel
.attributes
.iter()
.find(|attr| attr.id == helios_core::runtime_core::CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION)
else {
return Ok(0);
};
let Some(blob) = attribute.value.as_ref() else {
return Ok(0);
};
helios_core::runtime_core::kernel_cluster_size_from_bytes(&blob.data)
.map_err(|error| invalid(error.to_string()))
}

fn graph_sm_requirements(
nodes: &[wire::Node],
declared_min_compute_sms: u32,
) -> ExportResult<(u32, u32)> {
let mut max_cluster_size = 0u32;
for node in nodes {
if let Some(wire::node::Operation::Kernel(kernel)) = &node.operation {
max_cluster_size = max_cluster_size.max(kernel_cluster_size(kernel)?);
}
}
Ok((declared_min_compute_sms, max_cluster_size))
}

#[derive(Debug)]
struct RecordedKernel {
function: usize,
Expand Down Expand Up @@ -3397,13 +3425,17 @@ pub(crate) fn capture_rank(
_ => None,
})
.collect();
let (min_compute_sms, max_cluster_size) =
graph_sm_requirements(&nodes, graph.min_compute_sms)?;
output.index.ranks[0].graphs.push(wire::GraphIndex {
name: graph.name.clone(),
flags,
resource: file.clone(),
node_count: nodes.len() as u64,
edge_count: edges.len() as u64,
functions: functions.into_iter().collect(),
min_compute_sms,
max_cluster_size,
});
let source = file_source(path)?;
graph_bytes += source.nbytes;
Expand Down Expand Up @@ -5589,4 +5621,48 @@ mod tests {
assert!(err.contains("is empty"), "{err}");
Ok(())
}

#[test]
fn graph_sm_requirements_extracts_cluster_dimension_and_preserves_unspecified_zero() -> ExportResult<()>
{
let mut cluster_bytes = vec![0u8; 64];
cluster_bytes[0..4].copy_from_slice(&4u32.to_ne_bytes());
cluster_bytes[4..8].copy_from_slice(&2u32.to_ne_bytes());
cluster_bytes[8..12].copy_from_slice(&1u32.to_ne_bytes());

let nodes = vec![
wire::Node {
operation: Some(wire::node::Operation::Kernel(wire::Kernel {
function: 0,
grid: vec![8, 1, 1],
block: vec![128, 1, 1],
shared: 0,
arguments: vec![],
attributes: vec![],
})),
},
wire::Node {
operation: Some(wire::node::Operation::Kernel(wire::Kernel {
function: 1,
grid: vec![8, 16, 1],
block: vec![128, 1, 1],
shared: 0,
arguments: vec![],
attributes: vec![wire::Attribute {
id: helios_core::runtime_core::CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION,
value: Some(wire::Blob {
data: cluster_bytes,
relocations: vec![],
}),
}],
})),
},
];

assert_eq!(graph_sm_requirements(&nodes, 0)?, (0, 8));
assert_eq!(graph_sm_requirements(&nodes, 128)?, (128, 8));
assert_eq!(graph_sm_requirements(&nodes[..1], 0)?, (0, 0));
assert_eq!(graph_sm_requirements(&[], 0)?, (0, 0));
Ok(())
}
}
2 changes: 2 additions & 0 deletions heliopause/src/export/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,8 @@ fn rank_plan(
node_count: graph.node_count,
edge_count: graph.edge_count,
functions: graph.functions.clone(),
min_compute_sms: graph.min_compute_sms,
max_cluster_size: graph.max_cluster_size,
});
}

Expand Down
2 changes: 2 additions & 0 deletions heliopause/src/export/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub(crate) struct GraphHandle {
pub instantiate_flags: Option<u64>,
#[serde(default)]
pub recorded: usize,
#[serde(default)]
pub min_compute_sms: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading
Loading