Skip links

Finding Hardware Configuration using Mojo Programming Language

Mojo is a versatile Systems programming language that was open-sourced by Modular in August 2026. Its performance closely matches C++ and Rust.

There are several functions in Mojo for detecting the configuration of the hardware it is currently running on. It is even possible to compile for specific hardware. This ability allows seasoned developers to hand craft code for heterogeneous hardware. 

Here is a program that shows some of the possibilities.

Detecting Hardware
Detecting Hardware

In this example I have focussed only on the run-time check, not compile-time. Here is what I get when I run the program on my iMac (2023 model, Apple M3).

Program output
Program output

The functions num_physical_cores(), num_logical_cores() and num_performance_cores() help decide how many worker threads to start. num_logical_cores() matters on chips where putting a heavy job on an efficiency core can make the whole parallel job wait for it.

Functions is_linux() and is_macos() allow us to write OS-specific fine-tuned code.

The example I have shared is not exhaustive. There is a lot more one can do with Mojo in the context of working with specific hardware.

You can download the code here.

Have a nice weekend!

Leave a comment