Live data from Hacker News

Highly efficient matrix transpose in Mojo

veitner.bearblog.dev

51–60 of 70 posts

Re: Highly efficient matrix transpose in Mojo

#51

As someone said below - you'd never write just a transpose kernel - it'll be fused into something else.

Look the frontier AI companies need something other than reversing binary trees to give interview candidates

No one is going to ask this on an interview. Used to be matmul. These days it's FA.

Re: Highly efficient matrix transpose in Mojo

#52

I think Mojo’s lack of being a true open product and existing to drive profits at Modular has really held it back. It’s just really impractical to use a licensed programming language in 2025.

My impression is that this is on purpose on their part. They’ve repeatedly stated that by 2026 they will open source the compiler, and I think they’ve wanted a slow adoption ramp in order to spend some more time getting it right first.

Possibly rose-tinted glasses on my part, but I’m optimistic for 2026. Chris Lattner has a pretty strong track record of getting these things right.

Re: Highly efficient matrix transpose in Mojo

#55
Fast matrix transpose? Agree for a transposed matrix, just change the indexing arithmetic that converts row i and column j to an offset in the storage for the matrix and then remember that this is a transposed matrix. Some software object semantics could make this easy for other software to use.

Re: Highly efficient matrix transpose in Mojo

#56

Earlier quoted context omitted.

Now I'm curious, how many times do you have to fully read the matrix in GPU for the total impact of reading columns to be higher than one-off actual transpose and then sequential row reads? I know it depends on lots of things, I'm after a rough estimate.

It's quite rare. Usually problems are tiled anyway and you can amortize the cost of having data in the "wrong" layout by loading coalesced in whatever is the best layout for your data and then transposing inside your tile, which gives you access to much faster memory.

The one pure transpose case that does come up occasionally is an in-place non-square transpose, where there is a rich literature of very fussy algorithms. If someone managed to make any headway with compiler optimization there, I'd be interested.

Re: Highly efficient matrix transpose in Mojo

#57

I wonder if there is a reason for not using the high level abstractions provided by Modular

Most interesting algorithms (e.g. with dynamic shapes, mixed computation) are typically better scheduled by hand.

Sure, but Modular’s mission was to provide abstractions to minimize these types of optimizations.

Re: Highly efficient matrix transpose in Mojo

#58

Earlier quoted context omitted.

I work on Mojo. The whole compiler, runtime etc. will get open sourced, most likely within a year. It is just a matter of time and us getting all the required work done. https://docs.modular.com/mojo/faq/#open-source

,,will get open sourced'' means closed source, parent wrote the same

Chris Lattner (the CEO of Modular) was previously the technical lead behind the creation of LLVM, Clang and Swift, all of which were open sourced.

He has a bit of a track record already.

Re: Highly efficient matrix transpose in Mojo

#59

I think Mojo’s lack of being a true open product and existing to drive profits at Modular has really held it back. It’s just really impractical to use a licensed programming language in 2025.

My impression is that this is on purpose on their part. They’ve repeatedly stated that by 2026 they will open source the compiler, and I think they’ve wanted a slow adoption ramp in order to spend some more time getting it right first. Possibly rose-tinted glasses on my part, but I’m optimistic for 2026. Chris Lattner has a pretty strong track record of getting these things right.

Yeah, and he's clearly trying to avoid what happened to Swift[1]. Although the danger of "corporate owner priorities dictate releasing half-baked/awful changes" risk is still there, Lattner himself has more influence within Modular (obviously, as co-founder and CEO) than he did at Apple, so it may work out better this time.

[1]: https://news.ycombinator.com/item?id=30416070

Re: Highly efficient matrix transpose in Mojo

#60

In the coarse graining code, you use an @parameter-for. Doesn’t that lead to some pretty large code size unrolling that? Or is that less of an issue on GPU? Great write up! I learned a lot!

It doesn’t. The batch size is just 8. This is a very good trick and often needed to archive peak performance in memory bound kernels. You can checkout the equivalent code in cuda aswell :)
Post reply on HN