Skip to content

Tiled Matmul for perfect tiling (abstract parallel model) - #152

Open
mstn wants to merge 61 commits into
masterfrom
marco/parallel-impl
Open

Tiled Matmul for perfect tiling (abstract parallel model)#152
mstn wants to merge 61 commits into
masterfrom
marco/parallel-impl

Conversation

@mstn

@mstn mstn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Tiled Matmul for perfect tiling using an abstract model for context-based parallelism.

Details

See doc for details.

Limitations

  • we cannot express invariant, we need a fold instead of reduce
  • it works with perfect tiling. Predicated will come in a next PR

@mstn mstn self-assigned this Aug 5, 2026
@mstn
mstn force-pushed the marco/parallel-impl branch from 387ea06 to 04155f9 Compare August 10, 2026 14:38
@mstn mstn changed the title Tiled Matmul using generic parallel model Tiled Matmul for perfect tiling (abstract parallel model) Aug 11, 2026
@mstn
mstn requested a review from statusfailed August 11, 2026 13:32
@mstn
mstn marked this pull request as ready for review August 11, 2026 13:32

@statusfailed statusfailed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Some questions/comments below. Main one: do we have a benchmark for tiled matmul for issue #124 ?

Comment thread catena-lang/doc/PARALLEL_CODEGEN.md
`malloc`, and every block receives its own shared-memory arena managed by the
GPU runtime. The requested total must still fit the device's per-block shared
memory limit; this hardware limit is currently checked by CUDA/HIP rather than
encoded in the Hex types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we exceed the limit? Do we get a crash?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should follow the existing trapping policy, but checking...

Comment thread catena-lang/doc/PARALLELISM.md
b-only-layout = gpu.shared(tile-count, empty)
shared-layout = gpu.shared(tile-count, b-only-layout)

grid = gpu.grid.2d(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are only 2d grids possible? Can we express batched matmuls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add more layouts for grids when needed. I don't think this is relevant for batched matmuls or is it?

(arr gpu.launch_params : 0 -> 1)
# Nominal GPU levels. Their dimensions let lowering distinguish kernel
# launch from block-local cooperative execution.
(arr gpu.grid.2d : 4 -> 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these were previously definitions, I'm not clear on what is baked in to the implementation in terms of shape dimensionality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they were not, at least in my implementation. The reason is that they are like a sort of enum/constant, it cannot be defined in terms of other parallel primitives, we need to know that it is a gpu grid, does it make sense?

```text
host<gpu.grid.2d, ...> -> catena_gpu_grid_host_t
worker<gpu.grid.2d, ...> -> catena_gpu_grid_worker_t
worker<gpu.block.2d, ...> -> catena_gpu_block_worker_t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always 2D?

Comment thread catena-lang/stdlib/cmc.hex Outdated
(def program identity :
([a.] [.a])
->
([a.] [.a])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this so that it uses the more concise

identity : [a] -> [a]

the more examples of this pattern in the codebase, the more codex propagates it

({gpu.state [.b]} * [coargs.])
# Build the type-level description of a two-dimensional GPU block and
# preserve its runtime dimensions for coordinate calculations.
(arr gpu.block.2d : {[

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above comment, does this mean we need a compiler primitive for every dimensionality of tiling?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid so, but in theory we have 1d, 2d, and 3d. In practice 1d and 2d. A thing I was considering is to pass a shape, but I don't know if it brings benefits beyond more complexity.

@@ -0,0 +1,445 @@
# Perfectly tiled f32 matrix multiplication.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a benchmark for this vs. a reference gemm?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR, see offline discussion.

@mstn
mstn force-pushed the marco/parallel-impl branch from 380f912 to 91d7258 Compare August 13, 2026 13:35
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.

2 participants