Skip to content

Subtype AbstractArray for TileArray#176

Closed
shreyas-omkar wants to merge 1 commit intoJuliaGPU:mainfrom
shreyas-omkar:i66
Closed

Subtype AbstractArray for TileArray#176
shreyas-omkar wants to merge 1 commit intoJuliaGPU:mainfrom
shreyas-omkar:i66

Conversation

@shreyas-omkar
Copy link
Copy Markdown
Contributor

Closes #66

Fix

Subtype TileArray{T, N, S} from AbstractArray{T, N}.

Changes

  • struct TileArray{T, N, S} <: AbstractArray{T, N} : one line change to the struct declaration
  • Base.getindex : throws a clear error on host-side indexing instead of crashing cryptically when the default AbstractArray machinery tries to call it
  • Base.show / Base.show(::MIME"text/plain") : custom display so the REPL doesn't try to iterate elements and hit the getindex error
  • Base.pointer : exposes the underlying ptr field so the existing TileArray(arr::AbstractArray) constructor doesn't accidentally recurse when passed a TileArray

Reason

Base.size, Base.eltype, and Base.ndims were already defined manually. Subtyping AbstractArray means these come for free via inheritance for any future additions, and TileArray now participates correctly in Julia's type hierarchy, generic code that dispatches on AbstractArray will work as expected.

The core constraint is that TileArray lives on the GPU and has no host-side element access. The getindex implementation makes this explicit with a useful error message rather than a confusing stack trace.

@maleadt
Copy link
Copy Markdown
Member

maleadt commented Apr 5, 2026

TileArray now participates correctly in Julia's type hierarchy, generic code that dispatches on AbstractArray will work as expected.

What does it realistically enable? As mentioned in #66 (comment), I'm not sure this buys us much, even with the scalar ops from #76. Every operation on a TileArray is realistically going to have to be special-cased to lower to tile-based ops, and not simply expand to a loop doing scalar ones as all of the fallbacks in Base do.

@shreyas-omkar
Copy link
Copy Markdown
Contributor Author

Hi Tim, the immediate benefit I was thinking to get from this patch is that TileArray would pass isa AbstractArray dispatch, which matters for the Tiled broadcast machinery and for user code doing arr isa AbstractArray guards.

I’m still not fully sure the complete AbstractArray interface is meaningful here, but the type relationship being correct feels like a good baseline hence keeping it in draft.

I’ll get back to you with more concrete details once I’ve figured out what else this realistically enables beyond the above.

@maleadt
Copy link
Copy Markdown
Member

maleadt commented Apr 6, 2026

which matters for the Tiled broadcast machinery

How so? We already have broadcast implemented here.

@shreyas-omkar
Copy link
Copy Markdown
Contributor Author

My bad, the broadcast claim was wrong, and isa AbstractArray alone isn’t a strong enough motivation for a type hierarchy change when none of the Base fallbacks actually work. Closing this for now.

@maleadt
Copy link
Copy Markdown
Member

maleadt commented Apr 6, 2026

Note that I'm really not opposed to doing this, I just don't know what it would buy is. If you run into a case where it would help, feel free to re-open.

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.

TileArray and the AbstractArray interface

2 participants