Add: prepare and freeze kernel context device resources - #2173
Draft
TaoZQY wants to merge 4 commits into
Draft
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Kernel mode is simpler's second execution identity: instead of owning
the device, a context borrows the caller's already-current device and
stream to enqueue one bounded asynchronous operator per launch, so a
PyPTO program is capturable by ACLGraph as an ordinary node. This
change freezes the public surface that identity hangs off; it creates
no resources and changes no program-path behavior.
- runtime_c_api.h declares the lifecycle entries
simpler_kernel_mode_{supported,init,prepare_callable,launch} plus
simpler_kernel_mode_ctx_control with its versioned
SimplerKernelCtxControl POD (mode SIMPLER_MODE_PROGRAM/KERNEL,
CONFIGURE/FREEZE actions, exact struct_size match, layout pinned by
static_asserts) and adds the host-band codes
PTO_RUNTIME_ERR_INVALID_STATE / _CAPACITY_EXCEEDED. The existing
finalize_device stays the fifth lifecycle entry. FREEZE requires a
previously accepted kernel-mode CONFIGURE and rejects a second
FREEZE, so a successful FREEZE is synonymous with "the capacity
guard will enforce this" and program-mode contexts stay structurally
outside that guard's reach.
- ensure_acl_ready() and force_reset_device() refuse with UNSUPPORTED
on a context configured for kernel mode: the ACL lifecycle belongs
to the caller, and every call site of the five ACL lifecycle APIs
(aclInit, aclrtSetDevice, aclrtResetDevice, aclrtResetDeviceForce,
aclFinalize) is either inside force_reset_device() or gated on
acl_ready_, which only ensure_acl_ready() sets — so poison recovery
can never reset the device out from under the host process.
- kernel_invocation_header.h pins the 64-byte envelope every kernel
launch ships to the AICPU (version / mode / callable / generation /
int32_t arg counts / payload length). Runtime payload formats are
defined under it by each runtime, and its fail-closed validation
belongs to the AICPU-side consumers rather than this header.
- KernelCtxControlState implements the CONFIGURE/FREEZE ordering table
once for all eight host-runtime components: unsupported stubs run
identical structural and ordering validation and diverge only after
every check passes, so an argument a stub accepts is one the real
implementation accepts.
- KernelExecutionState and ExecutionModeClaimState carry the kernel
context phase machine (New/Collecting/ReadyEnqueued/Poisoned/
Closing/Closed with sticky, retriable Closing and separate
runtime-error and teardown-error slots) and the two restricted
operation vocabularies; synchronize, allocation, capture queries,
and model attachment stay unrepresentable in those tables.
- ChipWorker dlsyms the five new symbols from every runtime, so a
component missing one fails at load. test_host_runtime_abi.py
asserts the export across all eight components, and table-driven
UTs cover the control table, the phase machine, and both wire
layouts.
- ChipCallable additionally records scalar_count in four bytes of
historical header tail padding, the callable-side comparandum for
the invocation header's scalar_count. Every historical offset,
sizeof, and the kernel-cache ABI token are unchanged; a legacy blob
reads 0. make_callable validates [0, CHIP_MAX_SCALAR_ARGS];
ChipCallable.build gains a trailing scalar_count=0 keyword and a
read-only property; static_asserts pin both ChipCallable and
CoreCallable layouts (CoreCallable's leaf header has no padding, so
it carries no such field).
TaoZQY
force-pushed
the
codex/hbg-pr-context-resources
branch
from
September 9, 2026 09:14
fda5c39 to
746b8ae
Compare
This was referenced Sep 9, 2026
Expose a leased Host graph build result without device allocation or H2D. Keep program execution on an explicit upload path that compacts from the virtual-address source, and rebind retained Definition staging after growth so repeated uploads and failed-copy retries keep a valid source. Add dual-architecture build/upload tests and document workspace ownership. Validate both HBG C++ suites and both architecture simulation suites.
Query graph-dependent heap, runtime image, Definition and scheduler sizes without binding or allocating device memory. Aggregate compatible graphs by region and recompute aligned offsets for one execution slot. Align common resource validation with TMR while retaining the current K1 wire ABI and program byte semantics. Validate three distinct stream roles and reject unsupported configuration-only HBG sizing queries. Cover size overflow, Definition framing, concurrent queries, stream aliases and loader admission; document Host tensor-data capability rules.
Make the kernel context own an aligned heap and packed runtime arena, including Definition and scheduler regions. Prepare capacity once and freeze it explicitly; launch binding only validates identity and sizes before borrowing existing addresses. Preserve ownership on failed allocation rollback or close for retry, and retain platform allocator accounting. Distinguish dedicated AICPU and hidden AICore stream creation and their completion events. Test capacity boundaries, lifecycle, allocator failures, close retry and concurrent preparation on both HBG architectures.
TaoZQY
force-pushed
the
codex/hbg-pr-context-resources
branch
from
September 9, 2026 11:41
746b8ae to
5e8cbf8
Compare
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.
Move kernel device capacity ownership into context resource preparation. Allocate one aligned heap and one packed runtime arena, with Definition and scheduler slices, then freeze their addresses and capacities. Launch binding only checks context identity and required sizes before borrowing existing addresses.
Preserve platform allocator accounting and retain ownership after rollback or close failures so cleanup can be retried. Context stream creation distinguishes dedicated non-hidden AICPU from hidden AICore; caller remains a separate borrowed stream.
Validation
mkdocs build --strictpassed separately at all five PR heads. The HBG contract page is included in navigation from H1; the execution-slot page is included from H3.Public K1 owner integration remains pending. Context close requires external quiescence and captured-graph lifetime ordering; these resource helpers do not introduce hidden synchronization.
Dependency and review scope
Draft 3/5: Context prepare/freeze. Depends on #2172.
5e8cbf85.The stack was rebased onto
mainatf2478fadaf56a6fefacb8768f62a431b124a749f. The simulator runner retains both the SDMA communication header and K1 context-control header. Runtime and test changes are preserved; documentation navigation fixes are folded into the milestones that introduce the pages. The subsequent main documentation-theme update also merges cleanly with these branches.All five upstream drafts target
main, so this branch includes K1 and prior milestones (4 cumulative commits). The isolated diff above contains only this milestone. Rebase in dependency order after prerequisites land.The original K1 snapshot
21fb15c0is carried as rebased commit5612d48473592269b2d08a43a771afcedeb07594. Upstream #2064 remains open and has advanced; alignment with its final version remains public execution integration work.No idle onboard devices were available. Simulation golden checks cover existing program-mode regression; mixed ACLGraph capture/replay, DSV4 CSA device accuracy and comparative performance remain unvalidated.