← Back to list

MOJO — The Magical Spell

✌Hello folks , In this blog I am making discussion on new trendy programming language that is MOJO. In our discussion we are diving into…

Bellamkonda N V S Chaitanya in Dev Genius · 2023-06-11 18:15 · 56 claps · 8.5 min read
#mojo #modular #llvm #mlir #chris-lattner
Open on Medium ↗
Wiki topics: 💻 · Programming

MOJO — The Magical Spell

✌Hello folks , In this blog I am making discussion on new trendy programming language that is MOJO. In our discussion we are diving into deep study of evolving mojo .In this we come up touching backend concepts and terms like LLVM , memory latency , memory wall , cpu cache, floating point precision , 64 bit / 32bit / 16 bit ( B flops ,M flops) , static and dynamic type checking , impact of static and dynamic nature, Assembly language , Agile nature ( develop, deploy) , MLIR (Multi Lang Intermediate Representation) , matmul problem , SIMD (Single Instruction Multiple Data) , SIMT (Single Instruction Multiple Threads) , GIL (Global Intrepreter Lock) — (parallel , concurrent )

Img: Mojo Featuring😉🤞

Img: Mojo Featuring😉🤞

MOJO Intro:

Mojo is a new programming language for all AI developers .It combines the usability of Python with the performance of C and with safety , flexible features of Rust. We can say Mojo is a superset of Python or python++ , which means that it does not require you to learn a new programming language and you can use it within the Python ecosystem. It bridges the gap between research and production by combining the best of Python syntax with systems programming and metaprogramming. It is developed in modular by Chris Lattner the one who devloped the Swift and LLVM.

🔎About the Chris Lattner’s work:👩‍💻

**Chris Lattner is the one who come up with creating many of the projects that all we are rely on today . As part of his PhD thesis , he started the development of LLVM, which fundamentally changed how compilers are created, and today forms the foundation of many of the most widely used language ecosystems in the world. He then went on to launch Clang, a C and C++ compiler that sits on top of LLVM**, and is used by most of the world’s significant software developers (including providing the backbone for Google’s performance critical code). LLVM includes an “intermediate representation” (IR), a special language designed for machines to read and write (instead of for people), which has enabled a huge community of software to work together to provide better programming language functionality across a wider range of hardware.

At 🌍Google Chris🦸‍♂️ did develop another project which became hugely successful: MLIR. MLIR is a replacement for LLVM’s IR for the modern age of many-core computing and AI workloads.So, if Swift was “syntax sugar for LLVM”, what’s “syntax sugar for MLIR”? The answer is: Mojo🔥🔥! Mojo is a brand new language that’s designed to take full advantage of MLIR.

Img: Tim Davis and Chris Lattern

Img: Tim Davis and Chris Lattern

I’m extremely excited!🥳 ✨They seem to be addressing nearly all the challenges related to developing and deploying AI systems.

Modular coming with mojo🔥:

Modular Company has announced its goal to provide fair and equitable access to AI. It has contributed to developments in LVM, Swift, TensorFlow, PyTorch, TPUs, and the MLR Compiler to achieve this goal. Modular plans to rebuild AI software with the world’s best people. The software infrastructure that powers AI is expensive and holding the world back. Developers are juggling a fragmented mess of technologies and frameworks that drive AI workloads. The fastest AI execution engine provides better performance by working across multiple frameworks and hardware. Modular AI offers massive cost savings out of the box. Their new programming language “Mojo” is 35,000 times faster than Python😮 while still maintaining Python-like usability. Mojo unifies high-level code and high-performance libraries in one language to simplify workflows.

🤔Why MOJO is developed and what is its need ?

Lets start understand the need of the coming with new programming language. Mostly all the AI workloads are performed on top of python programming only because of the python being simple and easy to use . The evolution of AI field gave refame to the python programming . All the AI field work are based on the mathematical calculations , concepts and that are performed by researchers. To the perform the practicals , to run the models with datasets , python is been as most perferable language to use. Because of its simplicity , dynamic nature and having rich support of libraries. On providing simple and easy usuage python went for dynamic nature with implict operations performing it resulted in slow downing the performance. Python is much slower than comparing with other programming languages such as c , cpp . Python is a high level object oriented programming language it doesn’t performs operation on lower level things its been as one of factor for performance slow down. Its dynamic nature makes to performs more implict operations and take more memory for storing data it leads in increasing consuming more CPU operations creating memory latency. So the point to note is static type intialisation and explict function operations makes the performance more optimised compared to implict operations and dynamic type intialisation.

🔥Mojo is developed with addressing the all of the python problems. Lets case study what are problems of python and how mojo come with resolving :

🐶Even though mojo following the same syntax of python . It differs in performance widely in mechanism of underlying engine . If you look on internal architecture of 🐍🐍python programming approach the source code we build run by a interpreter and generates a excutable file .It is run🏃‍♂️🏃‍♀️ on top of LLVM( a framework of compiler design) and is converted using into Assemble language using IR (Intermediate Representation) making understable to respective CPU architecture and making operations on it . 🦴Mojo makes its source code to directly on top of LLVM using MLIR (Multi Language Intermediate Representation) and makes to perform CPU operations directly . It supports low level interaction. That making to support system programming and metaprogramming. If you try on running same python in both python and mojo environment (Currently mojo playground only available). 🤸‍♂️

A Mojo code compared to Python code

  • 2 times faster on an Intel processor.
  • 3 times faster on an AMD processor.
  • 4 times faster on a Graviton processor.

[embed]MLIR The MLIR project is a novel approach to building reusable and extensible compiler infrastructure. MLIR aims to address…mlir.llvm.org

On addition it makes enhancing it performance also through dealing issue on floating point precision / Compute Fragmentation. By implictly python takes 64 bit float point precision because of dynamic type initalsation it makes to occupy more storage space in CPU cache and make to perform operations more bits for smaller amount of data . Mojo comes with supporting manual memory management with optimising datatypes on support (64bit , 32bit , 16bit floating point precision ie. F64 Double precision, F32 Single precision , F16 half precision(B flops) ). Example: For storing a number x = 6000 takes 4bytes in python .Similar value in mojo , stored in converting into scientific notation i.e 6x10³ as 6e3 will takes less memory optimising bit values. The floating precision is C++ is 32 bit only . With this mojo can performs on very lower level also even much faster than C++ language.The better way of measuring cpu speed is in FLOPS(Floating point Operations per sec). To get more information regarding floating precision refer below wikipedia 🔎🌍:

[embed]FLOPS - Wikipedia In computing, floating point operations per second ( FLOPS, flops or flop/s) is a measure of computer performance…en.wikipedia.org

  • It is no more possible to enhance the performance cpu it has saturated and made end to Moore’s law : the observation that the number of transistors in an integrated circuit (IC) doubles about every two years.

FIg: Moore’s Law

FIg: Moore’s Law

Its time for devlopment in enhancing performance through using multiple processors GPUs , TPUs , ASICs. Mojo comes with support of parallel processing with auto tuning concept . Based on the system configuration how much cores , how much ram you want to use is known as Auto tuning .

🎈 Mojo comes with 🐱‍👤a lot of such kind of optimising feature to enhance the performance such as:

  • *var y : Int = 23 - Introducing immutable concept with var and let keywords
  • providing Int , Float (primitive types) instead of int , float (class types) for speed up intialisation.***
  • Mojo doesn’t support class type and concept of run time polymorphism . In Runtime client will be in interaction , so mojo helps only what is required focus on code.
  • It suggests to use keywords fn instead of def .

Matrix Multiplication (Matmul) problem:👻🤥 In AI field🤖 while training the models with large volume of data that is through images or numerical datasets performed in the form of matrices using linear algebra. The computation of this Matrix is performed with time complexity of O(n³) which is not better approach of optimization of performance . Its been as issue over decades . The Great news is mojo comes with solving this problem with the time complexity of O(1) with using SIMD (Single Instruction Multiple Data ) vectorising the data values supporting 16bit precision . Supporting the features of parallelisation and concurrency help in solving the matmul problem.

“The Entire Game of Mojo comes play with dealing matmul problem.”

The GIL issue🤦‍♀️ with python : A Gobal interpreter lock (GIL) is a mechanism used in computer-language interpreters to synchronize the execution of threads so that only one native thread (per process) can execute at a time. An interpreter that uses GIL always allows exactly one thread to execute at a time, even if run on a multi-core processor. Mojo came up resolving GIL issue with supporting parallel and concurrency .

[embed]Mojo 🔥: Programming language for all of AI Mojo combines the usability of Python with the performance of C, unlocking unparalleled programmability of AI hardware…www.modular.com

Try Mojo

Mojo is still young and it is not available to local devlopment for hand of practice they providing Mojo playground a jupyterHub environment . It that they providing handbooks as some reference documents guiding the Usuability of mojo . For getting mojo playground we have to make a request , they providing access (limit) no of people so they will send you a mail of access confirmation for certain time period. Mojo doesn’t has internet access😒 , so install packages and libraries are not possible currently , On behalf they providing standard mojo library access to everybody but each user has a private volume in which you can write and save your own Mojo programs.

  • %%python at the top of a notebook cell and write normal Python code. Variables, functions, and imports defined in a Python cell are available for access in future Mojo cells.
  • Redefining of global variables implictly is not supported, to redefine it should prefix with var and let keywords.

Python is a generic programming language used in production evironment which is very slow so it makes fun of by c, c++ , rust languages but tables are about to turn . Mojo is programming language devlop a superset of python .

Conclusion:

Chris Lattner, Tim Davis, and the Modular team have done an incredible job of creating a platform that will revolutionize the way we develop AI

. Modular’s unified inference engine, hardware portability, and new programming language, Mojo, are all game-changers

. I’m excited to see what the future holds for Modular and the future of AI development

.

Chris Lattner, Tim Davis, and the Modular team have done an incredible job of creating a platform that will revolutionize the way we develop AI

. Modular’s unified inference engine, hardware portability, and new programming language, Mojo, are all game-changers

. I’m excited to see what the future holds for Modular and the future of AI development

[embed]

⏰Try to watch on Product Launch of Mojo when you find enough time , it is much informative.

👏👏Clap if you feel my blog is helpful and do follow to be update with my upcoming technical blogs .To connect on **LinkedIn .**


메타데이터
post_id
f22aa79a92cd
slug
mojo-the-magical-spell-f22aa79a92cd
url
https://blog.devgenius.io/mojo-the-magical-spell-f22aa79a92cd
canonical_url
https://blog.devgenius.io/mojo-the-magical-spell-f22aa79a92cd
author_url
https://medium.com/@bellamkonda.nvschaitanya
status
ok
fetched_at
2026-08-28 07:22:36