3. Custom ops in Mojo

MAX’s operations are written in Mojo, and you can write your own the same way. This chapter writes a kernel in a notebook cell, calls it from your model, tests and times it, and then looks underneath compile at the graph API that MAX builds models with.

SectionYou learn
3.1 Your first custom opWriting a fused SwiGLU kernel in a %%mojo cell, calling it with F.custom, and measuring whether it helps.
3.2 Under the hood: the graph APIWhat compile builds, max.graph, and MAX’s weight loaders.

To go deeper into GPU programming in Mojo, work through the Mojo GPU puzzles. The handbook’s kernel optimization chapter explains why fused kernels matter.