Repository navigation
A flat generic def's spin takes words at its instance's layouts (#1195) - #1588
Merged
Merged
Conversation
Merged
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.
Closes #1195.
Root cause
A generic def (
-A: Type) already gets one spin per layout of its erased types, but every spin kept the generic calling convention: a value of typeAcrosses the call as one boxed word. SoBool.pick(Tint, ...)with a flatTint{r, g, b}made the caller heap-allocate a node, the callee drop the unpicked one through the genericterm_drop, and the result come back boxed to be unpacked again (ctr_take+ free). On the device each small spin is inlined at every call site into the one kernel, so that heap round trip is copied per site, which is what blows up the Metal program.Fix
A flat def's spin takes and returns words at its own instance's layouts. An open type takes the layout of the value that reaches it (
lay_at). If a self-call changes an erased type (polymorphic recursion, e.g.grow(Dup<A>, ...)), the def keeps the generic convention, so there is no extra copy. Spins are the ones that already existed: the corpus has 1825 spins before and after.Numbers
Bool.pick(Tint, ...)): Metal program 96,176 -> 74,816 B (thematchversion is 74,784); heap_alloc 14 -> 13.Bool.pick(Tint, ...): main 17 s / 4.20 MB Metal, this PR 9 s / 2.15 MB (no-pick baseline: 9 s / 2.25 MB). v2.0.34 did not finish (killed at 240 s, 3.4 GB).make test-nativepasses, bench checksums identical.New test
tests/compile/generic_flat_instance.bendcovers pick at Tint/V2/U32/List, a type-changing self-call (grow) and a type-keeping loop (last).Gates
repo 54/54, test 1636/1636, ping 58/58, perf 124/124. comp.ts 63,997 / 64k tokens. Not run: safe (local
bendttnot built; change is comp.ts only), CUDA, Linux, Windows.