Add Dynamic Memory Array Support - #25
Open
hmljy2020 wants to merge 3 commits into
Open
Conversation
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.
变更概述
本 PR 在现有显式 Memory 能力之上,额外实现了动态 Memory Array。
Python 前端现在可以通过:
声明多维 memory bank array,并使用运行时 Queue 数据动态选择目标 bank。
本次实现覆盖完整链路:
ac.array、ac.array.invoke和ac.array.invoke.yieldPython 前端示例
示例说明
1. 声明请求类型
每个请求包含:
address:同时编码 bank 坐标和 bank 内地址id:用于匹配可能乱序完成的响应write:区分读请求和写请求data:写入数据;响应时承载读取值或 old-data2. 声明二维 Memory Array
该声明创建一个
2 × 2的 memory bank array,共四个物理 bank。每个 bank:
因此,不同 bank 可以并行处理请求;同一个 bank 上的后续请求仍会受到 backpressure。
3. 从地址中解析动态 bank 坐标
示例使用:
row和col都来自运行时 Queue token,不是 elaboration-time 常量。4. 使用 tuple
apply保持请求字段关联tuple-valued
apply只消费一个输入 Queue token,并同时产生本次访问所需的所有值。这样可以保证:
始终来自同一个请求,不会因为拆成多条独立 Queue 而失去关联。
5. 动态选择 bank 并发起请求
banks[row, col]会 lower 为动态 array invoke,而不是静态展开后的固定选择。运行时只访问被选中的 bank:
6. 使用 ID 匹配响应
不同 bank 的访问可以同时进行,因此响应按照实际完成顺序返回,不保证全局请求顺序。
响应保留请求的
id,调用方应通过 ID 匹配请求和响应。Memory Array 时序语义
本实现遵循以下规则:
当前 Memory 与 Memory Array invoke 只支持
rate=1。遇到rate>1会明确拒绝,避免被 multi-rate scheduler 静默错误执行。后端实现
ACIR
新增并验证:
ac.arrayac.array.invokeac.array.invoke.yieldverifier 会检查:
ac.arrayowner 不是 Pure operation,canonicalization 不会删除物理 array 实例。QueueGraph 与 gfsim
QueueGraph 保存 array shape、bank 配置、invoke endpoint 和 Queue 连接关系。
gfsim 为每个 bank 分别维护:
只有动态选择的 bank 会处理请求,不同 bank 可以独立推进。
PYC 与 Verilog
PYC lowering 为每个物理 bank 生成一个
pyc.sync_mem。对于
2 × 2array,会生成四个 memory primitive,并包含:当前每个 service array 限制为一个 invoke endpoint。
示例运行结果
examples/memory/memory_array.py的 harness 会向三个不同 bank 分别写入数据,再发起读取。预期输出:
该结果验证:
[0, 0]保存41[0, 1]保存52[1, 0]保存63其他变更
0.4examples/memory只保留 DMA 和动态 Memory Array 两个 canonical 示例验证结果
已完成:
本地尚未安装完整 lit helper、Verilator 和外部 pinned PYC toolchain,因此这些可选工具对应的完整集成测试由 CI 或具备完整工具链的环境执行。