ModularM
Modular2y ago
7 replies
Martin Dudek

How to understand Mojo's compiler optimization capabilities?

This is something that’s been bugging me for a while. I am afraid there’s no clear answer, but I’m curious how you guys handle it.

How can I figure out what optimizations the compiler is doing anyway instead of implementing them myself (vectorize etc) ?

Implementing them myself is often easy with Mojo, but still it’s prone to errors, makes the code harder to read, and things like choosing simd_width in the code might be less optimal than letting the compiler decide based on the machine the code is running on.

To clarify what i mean with the last point, it seems that on Apple Sillicon
alias simd_width = 4 * simdwidthof[dtype]()

is the best choice but on other machines maybe
alias simd_width = 2 * simdwidthof[dtype]()

Who knows? I hope the compiler does depending on the machine it is compiling for. It feels a bit insane to actually hardcode this factor. 😉

Thanks
Was this page helpful?