Skip to content

前端算子目录(deepx·op)+ 编译器 pass:读 /lib 后端绑定 + 复合算子融合版本化 #2

Description

@miaobyte

背景

延续 #1(deepx-cpu-compute 重建为 kvlang main-runtime + CPU tensor myrwircaps)。现状:后端算子以 deepx/<author>·<op> 注册为 def rwir(myrwircaps_find 精确串匹配,无优先级/无 fallback/无版本),.kv 里直接写死具体后端,无前端抽象层

kvlang 核心契约见 array2d/kvlang#273(spec 卷 06-编译器语义)。本 issue 实现 deepx 侧的前端算子目录编译器 pass

范围

1. 前端算子(抽象)目录 —— deepx·<op>

  • 定义厂商中立的前端算子 schema:/lib/deepx·<op>,schema-only def rwir + abstract 标记,只承诺签名与语义,无实现、无 author。首批对齐已有/在建后端:argmaxmatmulsoftmax(复合)等。
  • argmax schema(依 deepx-design op-list 既有约定):argmax(tensor<any>:A, var<int32>:axis, var<bool>:keepdims) -> (tensor<int64|int32>:B)。属性(axis/keepdims)作普通位置参数(var/vector),非独立 attribute 字段——与 deepx reduce 族一致。
  • author ≈ PyTorch DispatchKey:miaobyte/cblas/cublas/default_(见 deepx-core tensorfunc/authors.hpp)。前端 deepx·op 无 author,后端 deepx/<author>·op 有。

2. 编译器 pass —— 读 /lib,生成新函数

  • 后端绑定:扫 /lib 全部调用点,对抽象算子 deepx·<op>,枚举已注册 deepx/*·<op> 后端,按策略选一,就地改写调用点 opcode 为 deepx/<author>·<op>
  • 选择策略:① 源码显式 author(deepx/cblas·matmul)保留 → ② 默认 author 表(authormap 式:matmul→cblasargmax→miaobyte,可配置)→ ③ 唯一可用者 → ④ 皆无则诊断「op 无已注册后端」。
  • 复合算子分解/融合deepx·softmax(= exp/sum/broadcast/div 组合的 rwfunc)→ 融合成单条自解释 rwir,登记为版本 softmax.1(写 /lib/deepx·softmax.1 + 基键 maxversion 标记)。runtime 侧高版本优先由 kvlang#273 兑现。
  • 定位:编译器介于 layout 之后、runtime 之前,运行在「已 layout 且各计算 runtime 已注册 myrwircaps」的 kvspace /lib 树上(复用 core 骨架,见 kvlang#166)。产物仍是合法 /lib 树。

3. 对照 PyTorch(参照,不照搬)

  • 后端绑定 ≈ TorchInductor lowering 表(编译期静态绑定),非 c10::Dispatcher 运行期 device 派发。
  • deepx·op/deepx/author·opTORCH_LIBRARY m.def / TORCH_LIBRARY_IMPL(deepx,<author>,m).impl
  • 复合算子 ≈ CompositeImplicitAutograd + torch/_decomp;融合 ≈ Inductor Scheduler → 单 kernel;版本择优 ≈ autotune 缓存最优。

验收

  • 用户锚例:deepx·argmax(v0, axis0, false) -> vmax 编译为 deepx/miaobyte·argmax(...) 并正确执行。
  • softmax 编译前后输出逐字节一致,编译后走 softmax.1

关联

array2d/kvlang#273(核心契约 + spec 卷 06)、#1、kvlang#166 #189 #202。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions