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
4 changes: 2 additions & 2 deletions ignition/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ def parse_args(argv=None, *, recipes=(), prog="ignition"):

def main(argv=None, *, recipes=(), prog="ignition", source_roots=()) -> int:
from ignition.preparation.source_identity import source_roots as bind_source_roots
from ignition.registry import active_recipes
from ignition.registry import active_prog, active_recipes

recipes = tuple(recipes)
try:
with active_recipes(recipes), bind_source_roots(source_roots):
with active_recipes(recipes), active_prog(prog), bind_source_roots(source_roots):
args = parse_args(argv, recipes=recipes, prog=prog)
return args.handler(args) or 0
except FlareError as error:
Expand Down
65 changes: 41 additions & 24 deletions ignition/components/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def gather_rows(source, rows, destination):
@triton.jit
def _gather_rows(Source, Rows, Output, SS: tl.constexpr, OS: tl.constexpr,
RS: tl.constexpr, WIDTH: tl.constexpr, BLOCK: tl.constexpr):
row = tl.program_id(0)
columns = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)
selected = tl.load(Rows + row * RS)
row = tl.program_id(0).to(tl.int64)
columns = (tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)).to(tl.int64)
selected = tl.load(Rows + row * RS).to(tl.int64)
value = tl.load(Source + selected * SS + columns, columns < WIDTH, other=0)
tl.store(Output + row * OS + columns, value, columns < WIDTH)

Expand All @@ -137,9 +137,9 @@ def _gather_rows_three(First, Second, Third, Rows, OutFirst, OutSecond, OutThird
FS: tl.constexpr, SS: tl.constexpr, TS: tl.constexpr,
FO: tl.constexpr, SO: tl.constexpr, TO: tl.constexpr, RS: tl.constexpr,
FW: tl.constexpr, SW: tl.constexpr, TW: tl.constexpr, BLOCK: tl.constexpr):
row = tl.program_id(0)
columns = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)
selected = tl.load(Rows + row * RS)
row = tl.program_id(0).to(tl.int64)
columns = (tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)).to(tl.int64)
selected = tl.load(Rows + row * RS).to(tl.int64)
first = tl.load(First + selected * FS + columns, columns < FW, other=0)
second = tl.load(Second + selected * SS + columns, columns < SW, other=0)
third = tl.load(Third + selected * TS + columns, columns < TW, other=0)
Expand All @@ -162,37 +162,54 @@ def save_hidden(source, destination, slots, active):
destination[slots[selected]] = source[selected]


def scatter_rows(source, rows, destination, active):
"""Store active rows at unique request slots, preserving all other rows."""
def scatter_rows(source, rows, destination, active, *, memory_capacity=None, allow_zero=False):
"""Store active rows at unique destination slots, preserving all other rows.
``allow_zero`` defaults to False so continuation-state writes never mutate
the reserved null slot 0. Pass ``memory_capacity`` (for example
``pool.memory_capacity``) when scattering into dynamically grown
``STATE_ROWS`` storage so runtime writes honor Helios's live slot limit.
"""
source = source.view(source.shape[0], -1)
output = destination.view(destination.shape[0], -1)
if memory_capacity is not None:
if (not isinstance(memory_capacity, torch.Tensor) or memory_capacity.ndim < 1
or memory_capacity.numel() < 1 or memory_capacity.dtype != torch.int64
or memory_capacity.device != output.device):
raise ValueError("memory_capacity must be a nonempty int64 tensor on the destination device")
if source.is_cuda:
capacity_tensor = rows if memory_capacity is None else memory_capacity
torch.library.wrap_triton(_scatter_rows)[(source.shape[0], triton.cdiv(source.shape[1], 1024))](
source, rows, output, active, source.stride(0), source.stride(1), output.stride(0),
source.shape[1], output.shape[0], 1024)
source, rows, output, active, capacity_tensor, source.stride(0), source.stride(1), output.stride(0),
source.shape[1], output.shape[0], 1024, memory_capacity is not None, bool(allow_zero))
else:
selected = active.bool() & (rows >= 0) & (rows < output.shape[0])
limit = output.shape[0] if memory_capacity is None else int(memory_capacity[0].item())
in_bounds = (rows >= 0) if allow_zero else (rows > 0)
selected = active.bool() & in_bounds & (rows < limit)
output[rows[selected], :source.shape[1]] = source[selected]


@triton.jit
def _scatter_rows(Source, Rows, Output, Active, SS: tl.constexpr, CS: tl.constexpr,
OS: tl.constexpr, WIDTH: tl.constexpr, SLOTS: tl.constexpr, BLOCK: tl.constexpr):
row = tl.program_id(0)
columns = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)
selected = tl.load(Rows + row)
active = (tl.load(Active + row) != 0) & (selected >= 0) & (selected < SLOTS)
def _scatter_rows(Source, Rows, Output, Active, MemoryCapacity, SS: tl.constexpr, CS: tl.constexpr,
OS: tl.constexpr, WIDTH: tl.constexpr, SLOTS: tl.constexpr, BLOCK: tl.constexpr,
HAS_CAPACITY: tl.constexpr, ALLOW_ZERO: tl.constexpr):
row = tl.program_id(0).to(tl.int64)
columns = (tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)).to(tl.int64)
selected = tl.load(Rows + row).to(tl.int64)
limit = tl.load(MemoryCapacity).to(tl.int64) if HAS_CAPACITY else SLOTS
in_bounds = (selected >= 0) if ALLOW_ZERO else (selected > 0)
active = (tl.load(Active + row) != 0) & in_bounds & (selected < limit)
values = tl.load(Source + row * SS + columns * CS, active & (columns < WIDTH), other=0)
tl.store(Output + selected * OS + columns, values, active & (columns < WIDTH))


@triton.jit
def _save_hidden(Source, Destination, Slots, Active, SS: tl.constexpr, DS: tl.constexpr,
WIDTH: tl.constexpr, BLOCK: tl.constexpr):
row = tl.program_id(0)
slot = tl.load(Slots + row)
row = tl.program_id(0).to(tl.int64)
slot = tl.load(Slots + row).to(tl.int64)
active = (tl.load(Active + row) != 0) & (slot > 0)
columns = tl.arange(0, BLOCK)
columns = tl.arange(0, BLOCK).to(tl.int64)
value = tl.load(Source + row * SS + columns, active & (columns < WIDTH), other=0)
tl.store(Destination + slot * DS + columns, value, active & (columns < WIDTH))

Expand Down Expand Up @@ -222,9 +239,9 @@ def _request_history(Counts, History, SavedCounts, SavedHistory, Requests, Sourc
Count, Errors, MemoryCapacity, REQUESTS: tl.constexpr,
CS: tl.constexpr, SS: tl.constexpr, HS: tl.constexpr, SHS: tl.constexpr,
HAS_HISTORY: tl.constexpr, SNAPSHOT: tl.constexpr):
command = tl.program_id(0)
slot = tl.load(Requests + command)
row = tl.load(Sources + command) if SNAPSHOT else tl.load(Destinations + command)
command = tl.program_id(0).to(tl.int64)
slot = tl.load(Requests + command).to(tl.int64)
row = (tl.load(Sources + command) if SNAPSHOT else tl.load(Destinations + command)).to(tl.int64)
valid = (command < tl.load(Count)) & (tl.load(Errors + command) == 0)
valid &= (slot >= 0) & (slot < REQUESTS) & (row > 0) & (row < tl.load(MemoryCapacity))
if SNAPSHOT:
Expand All @@ -234,7 +251,7 @@ def _request_history(Counts, History, SavedCounts, SavedHistory, Requests, Sourc
value = tl.load(SavedCounts + row * SS, valid, other=0)
tl.store(Counts + slot * CS, value, valid)
if HAS_HISTORY:
columns = tl.arange(0, 2)
columns = tl.arange(0, 2).to(tl.int64)
if SNAPSHOT:
value = tl.load(History + slot * HS + columns, valid, other=0)
tl.store(SavedHistory + row * SHS + columns, value, valid)
Expand Down
Loading