Files
calculet-npu-research-archive/reports/Calculet-NPU-源码Git历史与驱动证据分析-20260802.md
T

312 lines
17 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Calculet NPU 源码、Git 历史与驱动证据分析
日期:2026-08-02
分析基线:CalRT `420c080a`、定制 llama.cpp `fd9bd632`、CalRT 0.7.6、运行中 `calculet_pci.ko` 1.0.0、可读驱动源码包 0.9.0
## 1. 执行结论
当前样机和 OCI 镜像内能够取得的源码、Git 对象、reflog、stash、不可达对象、构建日志、历史性能文件、驱动包和模型资料,已经全部保存在本地。现有完整归档不是只有 HEAD,而是可用于追溯研发路径的证据集。
已经闭环的部分:
- CalRT、定制 llama.cpp、SystemC、fmt 四个 Git 仓库均保存 bundle 和带原始 `.git` 的精确快照。
- 四个仓库均不是 shallow/partial clone`git fsck --full` 通过;四个原始 bundle 均通过 `git bundle verify`
- llama.cpp 当前 refs、远端分支、当前 stash、reflog 中三个过期 stash、7 个不可达 commit、1 个不可达 tag 以及关联 tree/blob 均已保存。
- 17 份历史 `calculet*_run.txt`、两个 CSV、`log.1`、三个临时 patch 源文件和 `server_old.cpp` 共 24 个历史文件已恢复;每个文件与原 Git blob 哈希一致。
- 23 个 OCI layer 已逐层扫描;只发现 CalRT、llama.cpp、SystemC、fmt 四个 Git 仓库,没有隐藏的驱动 Git、`cal-llm` SDK、`libcal_llm.so` 或其他裸仓库。
- 驱动 0.9.0 源码、DEB/control/data、DKMS 状态、make.log、压缩模块和当前运行模块均已保存。
唯一无法从样机匿名取得的关键缺口是驱动上游 Gitea 的完整历史:`http://192.168.20.33:1000/niuzhenyu/cal-pcie.git` 在线但返回 HTTP 401。该缺口必须通过对方提供只读账号/PAT 或 mirror 导出解决,不能用 SSH 系统密码猜测或代替代码托管凭据。
## 2. 本地证据资产
根目录:
```text
outputs/Calculet-NPU-analysis-bundle-20260801/
remote-export/
archives/ 原始远端分层归档
manifests/ 下载和分片校验
extracted/
baseline/ 初始环境、模块、服务、性能记录
llama.cpp-full/ 完整工作区及原始 .git
calrt-git-history-from-oci-layer/
container-home/ 容器 home、构建树、工具链
container-oci/ 完整 OCI layout 与 23 个 layer
live-user2-home/ user2 home 和 rootless OCI storage
models-complete/ 完整模型权重和 calbin
driver-source/ 驱动源码、DEB、DKMS、运行模块
git-history-assets/ 统一 Git/驱动/构建证据
```
Git 证据摘要:
| 仓库 | 当前 HEAD | 当前 refs 可达 commit | 对象库 commit | 关键补充 |
| --- | --- | ---: | ---: | --- |
| CalRT | `420c080a` | 1,444 | 1,444 | reflog、tag、完整变更和主题索引 |
| llama.cpp | `fd9bd632` | 7,092 | 精确库 7,111 | 12 个额外历史对象库 commit + 7 个不可达 commit,含 stash/reflog |
| SystemC | 上游快照 | 2,334 | 2,334 | 未提交工作区 patch |
| fmt | 上游快照 | 7,781 | 7,804 | 不可达对象和未提交工作区 patch |
“当前 refs 可达 commit”和“对象库 commit”不能混用。普通 clone 只保证前者;reflog、stash 和不可达实验需要精确 `.git` 快照或本次新增的恢复 refs。
优先使用的恢复资产:
```text
git-history-assets/llama.cpp/
llama.cpp-exact-recovered-repository-with-git-20260802.tar.gz
llama.cpp-all-refs-20260802.bundle
unreachable-recovery-20260802/
llama.cpp-all-refs-plus-recovered-unreachable-20260802.bundle
commits.tsv
patches/
recovered-historical-artifacts-20260802/
llama.cpp-recovered-historical-performance-and-debug-artifacts-20260802.tar.gz
```
增强 bundle 有 26 个 refs,其中 8 个为新命名的恢复 refs;已经从零执行 `git clone --mirror``git fsck --full` 验证。需要完整保留 ref 名称时必须使用 mirror clone
```bash
git clone --mirror llama.cpp-all-refs-plus-recovered-unreachable-20260802.bundle llama.cpp.git
git -C llama.cpp.git fsck --full
```
## 3. llama.cpp 历史分层
### 3.1 已进入主线
`dev` 当前为 `fd9bd632``dev-ot``dev-ben` 的大部分开发已进入 `dev`,但分支 tip 是否合入必须按具体 commit 判断,不能按分支名判断。
主线中与后续优化直接相关的历史包括:
| Commit | 证据 | 工程含义 |
| --- | --- | --- |
| `62425b3` | 硬件算子不支持 common-prefix 局部 KV 删除,因此 `seq_rm` 释放整条序列 | prefix cache/context shift 不能按标准 llama.cpp 语义默认启用 |
| `c20c0a5` | 随后重新打开 common-prefix | 这是重新启用而非硬件限制消失,必须做共享前缀、分叉、删除和复用专项正确性测试 |
| `da724f3` | CalRT `MapBuf` 接入 | host backing memory 生命周期和异步复用是后续并发安全的核心 |
| `a2d5bf3` 附近 | 服务计时口径多次修改 | 历史性能数字必须保留原始请求和 Runtime 分项,不能只信单一 TTFT 字段 |
| `fd9bd632` | 当前构建 HEAD | 所有新开发和基线测试必须显式记录该 commit、CalRT SO、驱动和 calbin 组合 |
### 3.2 未合入分支
`origin/runtime_replace` 有 9 个未合入 `dev` 的提交。它不是 Runtime 源码,而是 llama-server 对外部 `cal-llm` EngineCore C API 的集成层。它包含:
- `CalrtEngineConfig` 和单个 `calbin_path`
- EngineCore 创建/销毁。
- request add/abort、step、输出 token 和结束原因。
- capacity blocked、profiling 开关和 JSONL dump。
- vocab-only llama model 初始化。
但本地和全部 OCI layer 都没有对应 SDK/实现库,因此只能作为 API 设计证据,不能编译成当前产品能力。分支末端又删除了 runtime capacity loading,说明 capacity 契约本身仍在变动。
`origin/test-cicd` 有 1 个未合入提交,只是 CI 配置,不是设备能力。
`1bec0db` 的“support 2 calbins”只修改 `llama-bench`,按命令参数顺序创建和测试两个 model instance;没有双模型 router、独立 session、同时 submit、per-chip affinity 或并发时间线。它证明 benchmark 能顺序加载两套路径,不证明同板双模型并发。
所有未合入分支已经保存 commit TSV 和全量 patch,不应直接 merge。应按最小能力拆解后重新实现,并逐项补齐 ABI、错误恢复和并发测试。
### 3.3 当前 stash
当前 `refs/stash` 指向 `19210246`,基于 `d028722a`,改动只有 `tools/server/server.cpp` 一行:把 `cparam.n_ubatch` 替换为 `n_ubatch()`。它由一个 WIP commit 和一个 index parent 表示,完整 patch 已保存。
它是未提交实验,不等于主线设计决策。若要采用,应先在当前 HEAD 上重新构造,并验证 upstream API 变化。
### 3.4 过期 stash 和不可达对象
reflog 暴露三个已经不在当前 `refs/stash` tip 上的 stash
| 时间 | WIP | index parent | 内容 |
| --- | --- | --- | --- |
| 2026-04-09 | `c4443857` | `f06f10a5` | server 路径 22 行实验修改 |
| 2026-04-27 | `2a67be2e` | `294f5e41` | `common/common.cpp``src/llama-calrt.cpp` 共 104 行修改 |
| 2026-04-30 | `81d4fd2c` | `499f6ff4` | CalRT version print 一行修改 |
另有普通不可达 commit `1d248d95`:在 `src/llama-calrt.cpp` 增加 output tensor slice,用于只复制 prompt token 范围。它与不可达 annotated tag `v0.1.0` 一起保留,是研究 D2H 切片和历史版本标记的重要证据。
7 个不可达 commit 均已输出:
- 完整作者、父提交、时间和 subject。
- 相对第一父提交的 binary/full-index patch。
- WIP 相对 index parent 的 patch。
- 8 个命名恢复 refs。
- 自包含增强 bundle。
在命名恢复 refs 后,`git fsck --full --unreachable --no-reflogs` 无任何输出,证明原先报告的 commit/tag/tree/blob 已全部被覆盖。
## 4. 历史性能和调试资料
已恢复的 24 个文件包括:
- 17 个 `calculet*_run.txt`
- `llama_perf_logs.csv``llama_content_logs.csv``log.1`
- `patch1.cpp``patch2.cpp``patch3.cpp`
- `server_old.cpp`
其中 6 个日志最初被普通简化历史遗漏,因为它们在新增后几十秒内被删除:
```text
calculet0_103149_run.txt
calculet0_103264_run.txt
calculet0_103409_run.txt
calculet0_103634_run.txt
calculet0_12456_run.txt
calculet0_7518_run.txt
```
本次改用 `--full-history` 和 tree/blob 枚举补齐。`index.tsv` 保存 commit、作者时间、作者、subject、原路径、blob 和恢复文件名;24 个恢复文件已逐一执行 `git hash-object` 验证。
这些历史文件的正确用途是还原实验问题和调优方向,不应直接作为当前性能基线:旧 CSV 的 TTFT/计时扣除、warmup 和客户端时钟口径曾多次变化。正式基线仍应按《性能压测故障注入与验收规范》重测,并保留原始 JSONL、服务 trace、Runtime H2D/infer/D2H 和设备状态。
## 5. CalRT 历史揭示的能力与风险
CalRT 1,444 个 commit 的历史比当前头文件更能说明风险边界。与并发和多芯粒最相关的演进包括:
| Commit | 历史主题 | 解读 |
| --- | --- | --- |
| `6511a9d` | 修复多线程 job engine 同步问题 | 多线程安全经历过实质缺陷,必须压力回归 |
| `0eb1155` | 紧急修复 async mode 空指针行为 | 不能只因 API 存在就默认 async 可靠 |
| `f52b519` | job engine thread-safe 更新 | 是并发 PoC 基础,不是端到端隔离证明 |
| `ef72e26` | 用户可选 async/serial 工作模式 | 需要验证当前 0.7.6 构建、队列深度和 completion 语义 |
| `57ffe19` | reset configuration,允许配置其他 calbin | 支持重配不等于多 calbin 同时常驻 |
| `5ac97e1` | 多芯片 calbin 必须带 CPU program | 说明多芯片配置依赖统一命令/同步程序 |
| `1e1d375` | 多芯片 CCU configure 性能优化 | 证明多芯片路径存在,但未证明 per-chip session |
| `c004584` | release 时 reset CCU | unload/reset 的作用域可能影响整板或另一模型 |
| `a1a0173` | 连续运行同模型时减少寄存器读写 | 同模型 fast path 可能与模型切换状态机不同 |
| `5015afd` | 记录谁在何时使用哪个设备 | 可用于扩展 lease、审计和冲突诊断 |
这些证据支持两个判断:
1. 我方可以基于完整 CalRT 源码开发更严谨的 async executor、队列指标、buffer 所有权和错误恢复。
2. 不能仅改 llama.cpp 和 PCIe 驱动就实现每芯粒独立模型 session。calbin 地址计划、CPU/CCU command、Runtime current-calbin、KV namespace 和 reset scope 仍需一起设计。
最值得从历史中回收为产品能力的特性:
- ping/pong 双 buffer 的受控 in-flight=2。
- async/serial 自动降级和 timeout quarantine。
- job queue depth、jobs left、owner/lease 的只读指标。
- 模型 generation 和 ResetConfiguration 状态机。
- profile JSONL 与 CalRT H2D/infer/D2H 的统一 schema。
- golden replay、buffer slice 和错误后重建。
- common-prefix KV 的能力探测和 fail-closed 开关。
## 6. 驱动证据与版本断层
已保存的驱动证据包含:
```text
extracted/driver-source/
source/cal-pcie-0.9.0/
package-provenance/
dkms-state/0.9.0/
live-module/
git-history-assets/driver/
driver-source-deb-dkms-live-module-evidence-20260802.tar.gz
cal-pcie-0.9.0-changelog.Debian.txt
cal-pcie-0.9.0-dkms-make.log
```
源码可见 board manager、PCIe BAR、DMA、ioctl、soft reset、chip serial 查询、module parameters 和设备状态管理。它足以分析 host-driver ABI 和实现一个受控实验分支,但不等于当前运行模块源码:
| 项目 | 证据值 |
| --- | --- |
| DEB/DKMS/source | 0.9.0 |
| Debian changelog | 仅 2026-05-25 初始版本 |
| 当前 `modinfo version` | 1.0.0 |
| 当前 `srcversion` | `01F04ECBF3AE95C7652F14B` |
| kernel vermagic | `7.0.0-28-generic` |
因此,在取得 1.0.0 对应 commit 前,禁止把 0.9.0 修改后直接替换现场模块。必须先建立:
```text
driver commit -> package version -> module srcversion -> Runtime ABI -> firmware -> kernel
```
驱动层适合实现的内容:设备/board lease、DMA buffer registration、超时、poll/interrupt、队列/中断 telemetry、reset ioctl 的安全边界和多 board 枚举。驱动层不能单独决定 Transformer 图如何分芯粒、参数如何布局或 KV 如何迁移。
## 7. OCI 构建来源
23 个 OCI layer 全部逐层扫描,除四个已恢复仓库外没有其他 Git。构建历史证明:
- CalRT 源码在镜像构建中被编译、安装,随后从后续 layer 删除;从旧 layer 恢复是必要操作。
- llama.cpp、CalRT、SystemC、fmt、OpenSSL 的 configure/build/install 日志已保存。
- `llama_cmake_build.log` 保留 `llama-calrt.cpp` 的多个 unused parameter/variable、缺少声明以及 server 未使用计时变量警告,可用作适配层清理列表。
- 没有 `cal-llm` 头文件、库或 SDK`runtime_replace` 不能在当前镜像闭环。
- 没有 Git LFS 指针和子模块缺口。
## 8. 对双芯粒/多模型设计的修正
历史证据增强了“可做”的信心,但没有改变产品边界:
- 可做:一个 DeviceSupervisor、一个统一 calbin generation、两个受控 worker、独立 buffer/KV namespace,并由 compiler 将 A/B 子模型分别绑定 chip0/chip1。
- 可研究:Runtime 增加 `chip_session/model_handle/job_handle`driver 增加 lease/telemetry/reset scopellama.cpp 增加 router 和 admission。
- 不可证明:当前 0.7.6 已支持两个独立 calbin 同时 configure,或两个进程分别占用一个芯粒。
- 不可替代:compiler 生成单芯粒完整模型、地址计划和 command stream。
`1bec0db` 只能作为多 calbin benchmark 代码样例;`runtime_replace` 只能作为 request lifecycle/C API 设计样例;CalRT async 历史只能作为隔离 runner 的候选能力。三者都不能直接升级为生产支持声明。
## 9. 仍需向对方取得的资料
P0:驱动仓库完整镜像和协作历史。
```text
cal-pcie.git mirror clone
all branches/tags/notes/reflogs if retained
PR and code-review comments
issues and milestones
wiki and releases
CI logs/artifacts
0.9.0 -> 1.0.0 package/build provenance
firmware/Runtime compatibility matrix
```
P0`cal-llm` 正式 SDK。
```text
c_api.h and C++ headers
libcal_llm.so / Windows library
ABI/version contract
EngineCore lifecycle and thread-safety document
capacity blocked semantics
profile JSONL schema
sample calbin and golden
```
P0compiler/kernel 工具链。
```text
compiler container and exact command
ONNX split/export scripts
quantization config and calibration set
single-chip model example
batch 4/8/16 decode profiles
kernel sources or extension SDK
calbin schema and packer
golden/replay tooling
```
取得 Gitea 权限后,使用只读 PAT,并先执行 mirror clone。不要用普通工作区 clone 代替 mirrorPR/Issue/Wiki/Release 需要通过 Gitea API 另行导出。凭据不得写进 remote URL、shell history、报告或 bundle。
## 10. 下一阶段实施顺序
1. 冻结当前四元组:llama `fd9bd632`、CalRT 0.7.6/commit、驱动 `srcversion`、当前 calbin hash。
2. 从历史问题建立 async/queue/KV/reset 回归集,先跑 in-flight=1 的新所有权模型。
3. 用 CalRT 历史中的 async/ping-pong 能力做隔离 runner,不直接接生产服务。
4. 取得 driver 1.0.0 mirror,比较 0.9.0 到运行模块的 ABI、reset、DMA、board/chip 差异。
5. 取得单芯粒小模型 calbin,验证一颗芯粒内 prefill+decode 完整闭环。
6. 取得组合 A/B calbin或 chip-session Runtime,验证 S1 服务并存和 S2 硬件并发。
7. 所有性能优化同时检查 golden、KV 一致性、错误恢复、24h soak 和 per-chip trace。
## 11. 完整性和现场状态
- 原始远端归档及分片已有下载 SHA-256 manifest。
- 本次 Git/驱动/OCI 衍生证据另有统一 `SHA256SUMS-20260802.txt`
- 历史文件归档 gzip 测试通过,24 个文件的 blob 哈希全部通过。
- 增强 llama bundle 已通过 `git bundle verify`、mirror clone 和 `git fsck --full`
- 本轮本地分析未启动容器、llama-server、CalRT runner 或 NPU 任务。
- 当前 VPN 保持连接,不主动断开。
- VPN 到样机 ICMP 为 3/3、零丢包、约 42 ms。2026-08-02 10:30 已重新授权 SSH 并完成最终只读复查:临时文件、传输/测试进程、8031 监听、运行容器和 NPU 设备占用均为 0,驱动参数与历史指纹保持不变。
- 远端仅额外列出两个 `/data/claw` 工作区 `.git` 目录;二者均只有 23,941 字节、tracked file 为 0,没有可解析 HEAD/refs/commit,也没有 driver/CalRT/llama 命中,不是遗漏的源码仓库。
- 驱动 DEB 仍是 `47297336...e792` 的 0.9.0 包,未发现额外 patch、diff、driver Git 或新源码对象。
系统审计和安全日志不是应删除的测试文件。后续现场清理只处理明确由我方创建的普通文件、进程和设备占用,不删除 SSH 登录审计、journald、auth.log 或其他用户记录。