Skip to main content

Mojo Manual

Welcome to the Mojo Manual, your complete guide to the Mojo🔥 programming language!

Combined with the Mojo API reference, this documentation provides everything you need to write high-performance Mojo code for CPUs and GPUs. If you see anything that can be improved, please file an issue or send a pull request for the docs on GitHub.

Get started with a tutorial

What is Mojo​

Mojo is a systems programming language specifically designed for high-performance AI infrastructure and heterogeneous hardware. Its Pythonic syntax makes it easy for Python programmers to learn and it fully integrates the existing Python ecosystem, including its wealth of AI and machine-learning libraries.

It's the first programming language built from the ground-up using MLIR—a modern compiler infrastructure for heterogeneous hardware, from CPUs to GPUs and other AI ASICs. That means you can use one language to write all your code, from high-level AI applications all the way down to low-level GPU kernels, without using any hardware-specific libraries (such as CUDA and ROCm).

Key features​

  • Python syntax & interop: Mojo adopts (and extends) Python's syntax and integrates with existing Python code. Mojo's interoperability works in both directions, so you can import Python libraries into Mojo and create Mojo bindings to call from Python. Read about Python interop.

  • Struct-based types: All data types—including basic types such as String and Int—are defined as structs. No types are built into the language itself. That means you can define your own types that have all the the same capabilities as the standard library types. Read about structs.

  • Zero-cost traits: Mojo's trait system solves the problem of static typing by letting you define a shared set of behaviors that types (structs) can implement. It allows you to write functions that depend on traits rather than specific types, similar to interfaces in Java or protocols in Swift, except with compile-time type checking and no run-time performance cost. Read about traits.

  • Value ownership: Mojo's ownership system ensures that only one variable "owns" a specific value at a given time—such that Mojo can safely deallocate the value when the owner's lifetime ends—while still allowing you to share references to the value. This provides safety from errors such as use-after-free, double-free, and memory leaks without the overhead cost of a garbage collector. Read about ownership.

  • Compile-time metaprogramming: Mojo's parameterization system enables powerful metaprogramming in which the compiler generates a unique version of a type or function based on parameter values, similar to C++ templates, but more intuitive. Read about parameterization.

  • Hardware portability: Mojo is designed from the ground up to support heterogeneous hardware—the Mojo compiler makes no assumptions about whether your code is written for CPUs, GPUs, or something else. Instead, hardware behaviors are handled by Mojo libraries, as demonstrated by types such as SIMD that allows you to write vectorized code for CPUs, and the gpu package that enables hardware-agnostic GPU programming. Read about GPU programming.

Get started​

More resources​

Was this page helpful?