Make host Tiled broadcast shape-correct#261
Closed
AntonOresten wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
|
Pardon the clutter... |
Host-level Tiled broadcasts previously loaded every array leaf with the
destination's block index and tile shape, silently producing garbage for
any shape-mismatched input, and never validated axes at all. Fix:
- Validate via Broadcast.check_broadcast_axes: Base-illegal shapes now
throw DimensionMismatch instead of computing garbage.
- Base-legal size-1 (and missing trailing) dims now work: such leaves are
wrapped in BroadcastLeaf{P}, load a 1-wide slice at index 1 in flagged
dims, and are expanded by the device-side tile broadcast.
- Scalar-only RHS (Tiled(C) .= 0) now fills the destination instead of
MethodError-ing on convert(Tile{T}, ::Number).
- Empty destinations are a no-op instead of launching a 0-block grid.
- ct.@. in-place assignment returns the original destination array.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Host-level
Tiledbroadcasts loaded every array leaf with the destination's block index and tile shape, and never validated axes — so shape-mismatched inputs (both Base-legal(1,N)vs(M,N)expansion and outright wrong sizes) silently produced garbage.Changes
_tiled_broadcast!now callsBroadcast.check_broadcast_axes, so Base-illegal shapes throwDimensionMismatchinstead of computing garbage.BroadcastLeaf{P}(P = static mask of expanded dims), load a 1-wide slice at index 1 in those dims, and are expanded by the existing device-side tile broadcast (broadcast_shape/broadcast_to). Exact-shape leaves keep the previous fast path unchanged.Tiled(C) .= 0used toMethodErroronconvert(Tile{T}, ::Number); the kernel result is now routed through_bc_result, which splats scalars viabroadcast_to(Tile(T(x)), tile_size)(and also expands sub-shaped result tiles when every leaf is size-1 in a dim).ct.@.return value: in-place assignment (ct.@. C = A + B) now evaluates to the original destination arrayCrather than theTiledwrapper.Tests
9 new testsets in
test/host/broadcast.jl: mismatch throws (1D/2D, nested), row/column size-1 expansion, expansion-only RHS, rank expansion (vector + matrix), allocating form with expansion, scalar fill, empty no-op, and macro return identity. Full host broadcast suite passes on GPU: 32/32.🤖 Generated with Claude Code