目标
在 v0.2 Queue/Var 基础上建立 v0.3 的参数化高层积木体系:Python 和 frozen ACIR 只表达官方、可复用的高层硬件积木;所有积木之间只通过现有 !ac.queue<T> SSA operand/result 通信;每个积木绑定经过优化且语义等价的 gfsim C++ 与 Verilog Provider。
Python 使用 ac.const 参数和 JIT elaboration 产生具体 specialization。端口数量、payload 类型、结构参数和策略必须在发布 frozen ACIR 前完全常量化。运行时不得发现 Provider、改变 topology 或解释 Python/MLIR。
用户模型
import agentic_circuit as ac
@ac.config
class CoreConfig:
engines: int
issue_entries: int
issue_width: int
rob_entries: int
@ac.system
def davinci(cfg: ac.const[CoreConfig]) -> None:
inst = ac.source(PTOInst, rate=cfg.issue_width)
with ac.scope("decode"):
inst = ac.compute(
inst,
lambda x: x.with_fields(
engine=decode_engine(x.opcode),
cycles=decode_latency(x.opcode),
),
)
with ac.scope("dispatch"):
lanes = ac.route(
inst,
by=PTOInst.engine,
outputs=cfg.engines,
)
with ac.scope("issue"):
issued = ac.issue(
lanes,
entries=cfg.issue_entries,
width=cfg.issue_width,
policy=ac.oldest,
)
with ac.scope("execute"):
completed = ac.engine(issued, lanes=cfg.engines)
with ac.scope("retire"):
retired = ac.reorder(
completed,
entries=cfg.rob_entries,
width=cfg.issue_width,
by=PTOInst.sequence,
)
ac.sink(retired)
model = ac.jit(
davinci,
cfg=CoreConfig(
engines=4,
issue_entries=16,
issue_width=4,
rob_entries=64,
),
)
系统函数仍不声明运行时输入输出。所有函数参数必须是 ac.const[...];Queue 边界和 scope I/O 继续由 source/sink 与 lexical def-use 推导。
高层积木边界
公开名字保持简短,并按公共硬件语义定义:
boundary: source, sink, observe
compute: compute, pipeline
transport: queue, route, merge, fork, join, crossbar
synchronization: barrier
storage: memory, table, pool
resource: credit
scheduling: issue, reorder
execution: engine
adaptation: adapt, cdc
decode、dispatch、rename、execute、retire 是 scope 或高层积木组合,不是应用专用 opcode。
Rule、State、ready/valid 和 raw register 不进入 Python 公共积木层。
- 用户不能定义私有 opcode、C++ Provider、Verilog Provider 或注入 raw backend code。
最终闭集与每个积木的精确名字由本 Issue 冻结;应优先复用现有名字,删除重叠或只反映实现细节的别名。
SimQueue-only 接口
积木动态输入输出必须继续使用现有 IR:
inputs = Variadic<!ac.queue<T>> operands
outputs = Variadic<!ac.queue<U>> results
端口数量和类型从 operand/result 列表直接推导,不额外存储可能不一致的 input_count 或 output_count。
具有多组可变端口的积木使用 named operand/result segments。例如:
%issued:4 = ac.issue
enqueue(%in0, %in1, %in2, %in3)
wakeup(%done0, %done1, %done2, %done3)
{entries = 16, width = 4, policy = #ac.policy<oldest>}
: (...) -> (...)
使用 operand_segment_sizes / result_segment_sizes 或等价的 ODS variadic segment contract 区分 enqueue、wakeup、issued 等端口组。
必须区分:
- port arity:独立 SimQueue 的数量;
- Queue rate:单条 SimQueue 每 epoch 最多传输的 token 数量;
- payload shape:单个 token 内部的结构、array 或 packet。
三者都是 frozen specialization 的一部分,但语义不能混用。
Static parameter 与 C++ template 映射
每个积木参数必须声明分类和 backend 映射:
| 参数类别 |
ACIR 表达 |
C++ |
Verilog |
| payload/type |
Queue element type 或 TypeAttr |
template type |
parameter type/packed layout |
| port shape |
operand/result arity |
template pack/non-type template |
interface array/generate |
| structural |
integer/bool attribute |
non-type template |
integer parameter |
| policy |
enum/SymbolRefAttr |
policy template type |
enum parameter/generate |
| instance constant |
typed attribute |
constexpr/constructor constant |
parameter/localparam |
| compute function |
pure ACIR region |
generated functor |
generated combinational logic |
沿用 schemas/component.schema.json 已有的:
template_argument
constexpr_argument
constructor_constant
结构布局、端口数量、entry 数、lane 数、issue width 和实现策略优先成为 template/non-type-template 参数。只影响实例数值且不改变布局的参数可以是 constexpr/constructor constant,但仍必须进入 specialization identity。
Compute 是唯一 lambda 积木
ac.compute 可以携带一个或多个纯组合 lambda region:
- lambda 参数和临时值全部是
ac.var<T>;
- 只能捕获 closed
ac.const;
- 只能使用受支持的纯计算、字段读取和 immutable update;
- 禁止 Queue effect、跨周期状态、任意 Python runtime、I/O 和 mutable capture;
- JIT 后 lambda 必须完全降低为 canonical
ac.var.* region;
- specialization hash 使用 canonical region,不使用原始 Python 文本。
其他积木不接受任意 lambda。它们通过类型化 field descriptor 或 policy 参数选择字段:
ac.route(inst, by=PTOInst.engine, outputs=4)
ac.reorder(done, by=PTOInst.sequence, entries=64)
field descriptor 在 ACIR 中成为稳定的字段符号/路径,C++ 映射为 typed accessor,Verilog 映射为冻结 packed layout 中的 bit slice。
Const-only JIT specialization
ac.jit(system, **constants) 必须执行以下流程:
validate closed const values
-> execute static Python elaboration
-> infer Queue types, scope I/O and port arity
-> emit ACIR operands/results + canonical attributes
-> lower compute lambda to Var regions
-> canonicalize and constant-fold
-> compute block specialization identities
-> bind backend Providers
-> compile only cache misses
-> publish frozen artifacts and manifest
允许的 const 值必须是封闭、可规范化的 bool、bounded integer、enum、type、field descriptor、tuple/array/map 及 @ac.config immutable record。不允许 Python object identity、open callable、mutable collection 或 runtime Queue handle 进入 specialization input。
frozen ACIR 之后不得依赖 Python。所有 const conditional、const loop、静态 collection shape 和端口数量必须已经消失或展开。
Specialization identity 与缓存
每个 Provider specialization 的 content-addressed identity 至少包含:
- opcode、version 和 contract epoch;
- BlockSpec/schema fingerprint;
- Provider implementation fingerprint;
- input/output Queue element types 与 canonical layout;
- operand/result segment shape;
- canonical static parameter dictionary;
- canonical compute region hash(仅
compute);
- backend、target triple、compiler 和 toolchain identity。
沿用现有 SpecializationInput、ComponentSpecialization、build fingerprint 和 manifest 体系。相同 specialization 必须命中同一缓存 artifact;不同 checkout root、Python hash seed 和进程不得改变 identity。
C++ 第一阶段采用按需生成 template-instantiation translation unit、优化编译并写入内容寻址缓存的方式。无需第一阶段直接实现 LLVM ORC C++ template frontend。
Verilog Provider 使用常量化 wrapper、parameter 和 generate;PYC/CIRCT/Verilator elaboration 后形成专用模块。参数化 source 与 specialization manifest 必须可复现。
BlockSpec 单一事实源
合并当前并行存在的 Queue opcode catalog、QueueBlockContract 与 schemas/stdlib/*.json component schema。每个官方积木只保留一个版本化 BlockSpec,并由它生成:
- ACIR ODS declaration/metadata;
- Python API metadata;
- opcode catalog;
- verifier 和参数约束;
- C++ Provider binding;
- Verilog/PYC Provider binding;
- refinement observation contract;
- specialization schema、文档表格和 capability inventory。
BlockSpec 必须声明 variadic port groups、payload relation、static parameters、parameter mapping、state/effect、timing、backpressure、Provider identity 和 refinement observations。
Provider ABI
gfsim C++
- Parent scope/topology 物理拥有所有
SimQueue<T> interconnect。
- 积木只借用 typed Queue reference/pointer/span,不拥有兄弟 interconnect。
- hot path 不执行字符串 opcode 查找、schema walk、RTTI dispatch 或 plugin discovery。
- specialization 直接实例化优化 template/provider,例如:
using Issue4 = gfsim::Issue<
PTOInst,
16,
4,
4,
4,
ac::Oldest>;
Verilog/PYC
- 逻辑 SimQueue 降低为 typed
data/valid/ready interface 和显式 Queue storage。
- Queue depth、latency、rate 和 domain 由 interconnect owner 实现,不由相邻积木私自复制。
- Provider 可以按参数选择 register、SRAM、banked 或 pipelined implementation,但必须满足同一 BlockSpec。
- 同一 frozen ACIR 的 gfsim 与 Verilog Provider 比较声明的 Queue transaction、architectural state、completion/retirement 和 failure observations。
交付内容
- const-only
@ac.system 参数和 ac.jit specialization API。
@ac.config closed canonical config model。
- 统一 BlockSpec schema、catalog generator 和 Provider registry。
- ACIR high-level parameter attributes、field descriptor 和 variadic port segments。
- 简化后的官方积木闭集及 Python API。
- optimized gfsim C++ Provider bindings。
- optimized PYC/Verilog Provider bindings。
- specialization compiler/cache、manifest 和 deterministic publication。
- DavinciOO 4-wide reference specialization,包括
route、issue、engine、reorder 的 parameterized multi-port graph。
验收标准
非目标
- 不支持运行时动态 topology、动态 Queue port count 或 Queue handle escape。
- 不把 Rule/State/ready-valid 暴露为 Python 公共积木。
- 不允许用户自定义 opcode 或 backend Provider。
- 不在运行时解释 Python、MLIR、BlockSpec 或 schema。
- 不要求 C++ 与 Verilog 内部数据结构或未声明的内部 cycle 完全相同。
- 不把架构阶段名称直接做成无法复用的专用 opcode。
关联
本 Issue 是上述 v0.2 闭环之后的高层积木/JIT specialization 升级。
目标
在 v0.2 Queue/Var 基础上建立 v0.3 的参数化高层积木体系:Python 和 frozen ACIR 只表达官方、可复用的高层硬件积木;所有积木之间只通过现有
!ac.queue<T>SSA operand/result 通信;每个积木绑定经过优化且语义等价的 gfsim C++ 与 Verilog Provider。Python 使用
ac.const参数和 JIT elaboration 产生具体 specialization。端口数量、payload 类型、结构参数和策略必须在发布 frozen ACIR 前完全常量化。运行时不得发现 Provider、改变 topology 或解释 Python/MLIR。用户模型
系统函数仍不声明运行时输入输出。所有函数参数必须是
ac.const[...];Queue 边界和 scope I/O 继续由 source/sink 与 lexical def-use 推导。高层积木边界
公开名字保持简短,并按公共硬件语义定义:
decode、dispatch、rename、execute、retire是 scope 或高层积木组合,不是应用专用 opcode。Rule、State、ready/valid和 raw register 不进入 Python 公共积木层。最终闭集与每个积木的精确名字由本 Issue 冻结;应优先复用现有名字,删除重叠或只反映实现细节的别名。
SimQueue-only 接口
积木动态输入输出必须继续使用现有 IR:
端口数量和类型从 operand/result 列表直接推导,不额外存储可能不一致的
input_count或output_count。具有多组可变端口的积木使用 named operand/result segments。例如:
使用
operand_segment_sizes/result_segment_sizes或等价的 ODS variadic segment contract 区分enqueue、wakeup、issued等端口组。必须区分:
三者都是 frozen specialization 的一部分,但语义不能混用。
Static parameter 与 C++ template 映射
每个积木参数必须声明分类和 backend 映射:
parameter type/packed layout沿用
schemas/component.schema.json已有的:结构布局、端口数量、entry 数、lane 数、issue width 和实现策略优先成为 template/non-type-template 参数。只影响实例数值且不改变布局的参数可以是 constexpr/constructor constant,但仍必须进入 specialization identity。
Compute 是唯一 lambda 积木
ac.compute可以携带一个或多个纯组合 lambda region:ac.var<T>;ac.const;ac.var.*region;其他积木不接受任意 lambda。它们通过类型化 field descriptor 或 policy 参数选择字段:
field descriptor 在 ACIR 中成为稳定的字段符号/路径,C++ 映射为 typed accessor,Verilog 映射为冻结 packed layout 中的 bit slice。
Const-only JIT specialization
ac.jit(system, **constants)必须执行以下流程:允许的 const 值必须是封闭、可规范化的 bool、bounded integer、enum、type、field descriptor、tuple/array/map 及
@ac.configimmutable record。不允许 Python object identity、open callable、mutable collection 或 runtime Queue handle 进入 specialization input。frozen ACIR 之后不得依赖 Python。所有 const conditional、const loop、静态 collection shape 和端口数量必须已经消失或展开。
Specialization identity 与缓存
每个 Provider specialization 的 content-addressed identity 至少包含:
compute);沿用现有
SpecializationInput、ComponentSpecialization、build fingerprint 和 manifest 体系。相同 specialization 必须命中同一缓存 artifact;不同 checkout root、Python hash seed 和进程不得改变 identity。C++ 第一阶段采用按需生成 template-instantiation translation unit、优化编译并写入内容寻址缓存的方式。无需第一阶段直接实现 LLVM ORC C++ template frontend。
Verilog Provider 使用常量化 wrapper、parameter 和 generate;PYC/CIRCT/Verilator elaboration 后形成专用模块。参数化 source 与 specialization manifest 必须可复现。
BlockSpec 单一事实源
合并当前并行存在的 Queue opcode catalog、
QueueBlockContract与schemas/stdlib/*.jsoncomponent schema。每个官方积木只保留一个版本化 BlockSpec,并由它生成:BlockSpec 必须声明 variadic port groups、payload relation、static parameters、parameter mapping、state/effect、timing、backpressure、Provider identity 和 refinement observations。
Provider ABI
gfsim C++
SimQueue<T>interconnect。Verilog/PYC
data/valid/readyinterface 和显式 Queue storage。交付内容
@ac.system参数和ac.jitspecialization API。@ac.configclosed canonical config model。route、issue、engine、reorder的 parameterized multi-port graph。验收标准
@ac.system只接受ac.const参数;运行时参数和 Queue 参数被确定性拒绝。!ac.queue<T>operands/results 表达。compute接受 lambda;非法 capture、Queue effect 和 stateful lambda 被拒绝。非目标
关联
本 Issue 是上述 v0.2 闭环之后的高层积木/JIT specialization 升级。