Skip to content

Support array construction syntax in kernels - #289

Merged
maleadt merged 23 commits into
mainfrom
ao/tile-construction
Aug 6, 2026
Merged

Support array construction syntax in kernels#289
maleadt merged 23 commits into
mainfrom
ao/tile-construction

Conversation

@AntonOresten

@AntonOresten AntonOresten commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Closes #271, deprecates ct.cat in favor of Base.cat and friends.

Currently documented under Construction, with ct.cat removed from Shape.

AntonOresten and others added 23 commits August 6, 2026 08:07
Bracket syntax in kernels now follows Julia's concatenation semantics
(closes #271) instead of supporting only compile-time-constant scalar
literals:

- runtime scalar elements: broadcast to unit tiles and merged with a
  balanced cat tree (balanced so every intermediate keeps power-of-two
  dimensions); constant elements still emit one dense ConstantOp
- tile elements concatenate ([q1; q2], [t1 t2; t3 t4], [t1;;; t2]) via
  balanced Intrinsics.cat trees built by @generated helpers
- scalars and tiles mix as blocks ([x [y z]; t M]): scalars lift to
  unit tiles, vectors to columns, and element types promote across
  blocks -- though under Tile IR's power-of-two rule, mixed-size blocks
  only fit along dimensions where the sizes agree
- single-dim syntax ([1;; 2], Base.hvncat with an Int dim) now works
- the hvncat tuple-of-tuples shape form (ragged/mixed N-D syntax) is
  decoded by probing Base's own hvncat on the host, so invalid literals
  surface Julia's exact DimensionMismatch as a compile-time error
- comma collection of tiles ([t1, t2]) and power-of-two violations get
  clean compile-time errors

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Tiles, scalars, and mixed blocks are one case: bracket syntax
concatenates tiles and scalars (e.g. [1; [1]] works).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Base.cat with the dims keyword (Int or Val) is the generic function
  form of bracket concatenation: variadic, scalars lift to unit tiles,
  element types promote. ct.cat stays public but is deprecated.
- typed T[...] concatenation (typed_vcat/hcat/hvcat/hvncat) now accepts
  tiles and mixed scalar/tile blocks, converting every element to T.
- The hvncat tuple-of-tuples shape form is decoded by probing Base's
  own hvncat with linear indices, so invalid ragged literals surface
  Julia's exact DimensionMismatch instead of a made-up message.
- Drop Base.@constprop :aggressive from the construction overlays:
  literal arguments and kwargs const-prop through @inline frames on
  their own (verified by the construction tests).
- Docs: concatenation (bracket syntax and cat) now lives under
  Construction; Shape keeps single-tile rearrangement ops.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A bare @Assert in compiler/intrinsics/core.jl (included before
language/operations.jl) resolved Base's implicit binding in the module,
making the later `macro assert` (ct.@Assert) definition an invalid
extension on 1.11. Julia 1.12's binding partitions tolerate this, which
is why local tests passed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Base.vect()'s Array allocation lowers to the memorynew intrinsic only on
1.12+; 1.11 fails through the GenericMemory path with a different
message. Assert the common "Unsupported" prefix instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
T[] builds a ghost Tile{T, Tuple{0}} with no Tile IR representation:
concatenation drops zero-length operands (n + 0 = n, so power-of-two
constraints are unaffected) while their element type still participates
in promotion, matching Base (vcat(Float64[], t32) is Float64).

Untyped [] cannot infer an element type; its Base.vect() overlay throws,
so an unconditional [] surfaces as a compile-time diagnostic and a
conditional one as a device-side trap. The throwing body infers as
Union{}, which keeps kernel-reachable Base error paths that call vect()
dead instead of derailing inference the way an Any-returning overlay
once did. This also replaces the Julia-version-dependent memorynew test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maleadt
maleadt force-pushed the ao/tile-construction branch from 45c21a0 to 04ab56d Compare August 6, 2026 11:49
@maleadt

maleadt commented Aug 6, 2026

Copy link
Copy Markdown
Member

I reworked the implementation and aligned it more closely with Julia/Base semantics:

  • Unified scalar and tile construction in the language overlays. Scalars are lifted to tiles and all bracket forms use the same concatenation machinery. This removed the dedicated vect/hvcat/hvncat/empty_tile compiler intrinsics and most of their custom codegen.
  • Simply removed the deprecated ct.cat API and converted internal callers to Base.cat(...; dims); we'll be tagging a breaking 1.0 soon anyway
  • Replaced the previous rejection of tuple dimensions with Base-compatible block-diagonal concatenation. Dimension order and repetitions no longer affect the result, and iterable dimensions such as 1:2 are accepted.
  • Matched hvncat(0, x) semantics, including its single-element requirement, and added Julia 1.11-compatible hvcat handling.
  • Restored typed empty tiles as zero-volume language values. Empty operands still participate in element promotion and shape validation, but emit no Tile IR and are dropped when concatenating into a nonempty result.
  • Moved constant literal optimization onto the normal broadcast/cat codegen path. Constant composition now emits shaped splat or dense ConstantOps instead of broadcast/cat sequences, including packed Boolean constants.
  • Reduced and consolidated the tests around observable Julia behavior, adding regressions for multidimensional/iterable dimensions, empty construction, zero-dimensional hvncat, constant emission, and older Tile IR disassembly.

@maleadt
maleadt marked this pull request as ready for review August 6, 2026 11:50
@maleadt

maleadt commented Aug 6, 2026

Copy link
Copy Markdown
Member

I'm not fully happy yet with the design surrounding "zero-volume tiles" (i.e. empty tiles), which are special cased right now because TileIR doesn't support them yet we can't make them ghost at the Tile level (because we're using mutable structs to avoid flattening everything into a singleton instance). But that redesign can wait.

@maleadt
maleadt merged commit 3c0629a into main Aug 6, 2026
1 check passed
@maleadt
maleadt deleted the ao/tile-construction branch August 6, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hvcat, hvncat, vect for tile construction

2 participants