Repository navigation
Conversation
hip_engine.zig is the HIP twin of loop_engine.zig's Model without the forward. Each stream owns a slot of five buffers: the visit cache that loop.CacheLayout sizes, four 32-byte rewind sites a visit (conv.hip's and ops.cu's RewindSite layout), the conv states' backup, a 16-row window history and the last prompt row's FP32 logits. HIP's draws keep no per-stream sampling rule, so stream_bytes has no rule buffer. addSlots writes each slot's site table and zeroes its conv states; reset zeroes the current slot's. The forward's shared scratch follows CUDA's buffer list, with hip_attention.zig's partial slots and the routed experts' activation and down rows, allocated once at init. Before any allocation the state refuses, by name and with a log line, a config without a loop, gates other than rank 64, global and sliding KV widths that differ (CacheLayout sizes every conv by the sliding width), a context of zero or past text_config.model_max_length (Mini names max_position_embeddings only under mtp_config, so the HIP host reads no window), and more than 16 streams. test-inkling2-hip-state-host, also part of test-inkling2-hip-host, runs it over a recording runtime: each stream's allocations at Mini's and tiny-inkling2-mini's shapes at 8K, 32K, 128K and 1M (25,087,464 B past the cache on Mini), the scratch, the site tables, the addSlots, reset and deinit counts, each refusal and its message, and cleanup after a failed allocation.
hip_snapshot.zig adapts loop.CacheLayout into kept_state.Visit slices and delegates kept-row counting and packed-order traversal to the shared kept_state.zig walk (the same walk CUDA's loop_engine.zig uses), then appends the slot's conv region. Model.save, restore and drop queue one device copy a piece on the stream, with CUDA's refusals by name (NotAtMark, StateOfAnotherModel, BadLoopSnapshot) and log lines. A snapshot is stored by position, so it restores into any slot whose context holds it. A save whose copy fails waits for the stream before it frees its buffer. Host tests: the walk's rings equal hip_attention.zig's, its bytes at Mini's and tiny-inkling2-mini's shapes, its pieces split at the ring wrap and tile the snapshot; save and restore issue exactly those copies; on host memory a restored slot equals a reference built from positions byte for byte, in place and at another capacity. inkling2-hip-state-test (built in test, run only on its own step) does the same on gfx1151 with tiny-inkling2-mini's and Mini's shapes: seeded slots saved, the snapshot compared with the walk's gather, the slot clobbered, restored and compared whole, and restored into a slot of another capacity.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #5728 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.