native: share one resource slot registry across partitions - #633
Merged
Conversation
Collect every ERTS resource slot (value/Ptr/Array per kind, plus the internal kinds and callback reply token) into a single comptime registry in mlir_capi.zig. The core partition publishes handles by slot name and the leaf partitions sync from it, replacing the hand written per-kind lookups in core.zig and resource_sync.zig. Kind aliases (OpaquePtr/OpaqueArray/USize/DiagnosticHandlerID/ SparseTensorLevelType) are declared as one table instead of five aliasKind calls. Requires kinda 5d34fb2 exposing ResourceKind.slots.
Kinda 0.11.0 on Hex predates the ResourceSlot registry API that the partition resource sync now depends on, so the paired checkout can no longer be Windows-only. Pin kinda.ref and build.zig.zon to the merged aa43cd0 (beaver-lodge/kinda#87).
Kinda 0.11.0-dev (aa43cd0) requires Elixir ~> 1.20, which is not available on OTP 25; the dependency chain no longer supports that lane. Keep the Elixir 1.18 coverage on OTP 27, which passes. The docker_build job previously resolved kinda from Hex (which lacks the ResourceSlot API), so it also needs the paired checkout and BEAVER_KINDA_PATH when publishing.
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.
背景
beaver 的 NIF 加载入口(
nif_load)把 MLIR C API 分片成多个 DSO(core / conversion / callback_bridge / rewrite_pattern / cuda)。每个 kind 有 3 个 ERTS resource slot(value / Ptr / Array),跨 partition 共享 resource type handle 时不能重复enif_open_resource_type(会创建不同 resource type),所以 core 通过core_resource_type_by_name按名字发布 handle,leaf partition 通过syncResourceTypes拉取。现状是三份手写遍历:
core.zig的core_resource_type_by_name:逐个allKinds+ Internal 类型 + ReplyToken 手写字符串比较;resource_sync.zig的syncResourceTypes:手写同一批 kind 的同步;mlir_capi.zig的open_all:5 处手写aliasKind调用。改动
依赖 kinda 5d34fb2(
ResourceKind暴露统一的slots数组,open/alias 都遍历槽位)。mlir_capi.zig:新增resourceSlotscomptime 注册表(所有 kind 的 3 槽位 + Internal 4 个 kind + callback ReplyToken),alias 收敛为kindAliases表;core.zig:core_resource_type_by_name遍历注册表;resource_sync.zig:syncResourceTypes遍历同一注册表;build.zig.zon/kinda.ref:kinda pin 更新到 5d34fb2。验证
zig build(beaver_native 全部分片编译通过);mix test:431 passed(含 resource 密集的 op/memref/pattern/transform 模块),5 skipped,21 excluded(triton/cuda 相关)。后续
注册表目前是线性 comptime 遍历(~200 槽位),加载时一次性执行;如果未来槽位数进一步膨胀,可以换排序+二分,但当前量级没必要。