{"id":4427,"date":"2026-12-04T14:12:30","date_gmt":"2026-12-04T08:42:30","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=4427"},"modified":"2026-12-04T14:12:30","modified_gmt":"2026-12-04T08:42:30","slug":"finding-hardware-configuration-using-mojo-programming-language","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2026\/12\/04\/finding-hardware-configuration-using-mojo-programming-language\/","title":{"rendered":"Finding Hardware Configuration using Mojo Programming Language"},"content":{"rendered":"<p><a href=\"https:\/\/mojolang.org\" target=\"_blank\" rel=\"noopener\"><em><strong>Mojo<\/strong><\/em><\/a> is a versatile Systems programming language that was open-sourced by <em><strong>Modular<\/strong><\/em> in August 2026. Its performance closely matches <em><strong>C++<\/strong><\/em> and <em><strong>Rust<\/strong><\/em>.<\/p>\n<p>There are several functions in <em><strong>Mojo<\/strong><\/em> 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.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Here is a program that shows some of the possibilities.<\/p>\n<figure id=\"attachment_4428\" aria-describedby=\"caption-attachment-4428\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"4428\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/12\/04\/finding-hardware-configuration-using-mojo-programming-language\/code-23\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png\" data-orig-size=\"2096,1088\" data-comments-opened=\"1\" data-image-title=\"Detecting Hardware\" data-image-description=\"&lt;p&gt;Detecting Hardware&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Detecting Hardware&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code-1024x532.png\" class=\"wp-image-4428\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png?resize=650%2C337&#038;ssl=1\" alt=\"Detecting Hardware\" width=\"650\" height=\"337\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png?resize=300%2C156&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png?resize=1024%2C532&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/code.png?w=1560&amp;ssl=1 1560w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-4428\" class=\"wp-caption-text\"><strong>Detecting Hardware<\/strong><\/figcaption><\/figure>\n<p>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 <em><strong>iMac<\/strong><\/em> (2023 model, Apple M3).<\/p>\n<figure id=\"attachment_4429\" aria-describedby=\"caption-attachment-4429\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4429\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/12\/04\/finding-hardware-configuration-using-mojo-programming-language\/output-17\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png\" data-orig-size=\"856,338\" data-comments-opened=\"1\" data-image-title=\"Program output\" data-image-description=\"&lt;p&gt;Program output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png\" class=\"wp-image-4429\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png?resize=400%2C158&#038;ssl=1\" alt=\"Program output\" width=\"400\" height=\"158\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png?resize=300%2C118&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/12\/output.png?w=856&amp;ssl=1 856w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-4429\" class=\"wp-caption-text\"><strong>Program output<\/strong><\/figcaption><\/figure>\n<p>The functions <em><strong>num_physical_cores()<\/strong><\/em>, <em><strong>num_logical_cores()<\/strong><\/em> and <em><strong>num_performance_cores()<\/strong> <\/em>help decide how many worker threads to start. <em><strong>num_logical_cores()<\/strong><\/em> matters on chips where putting a heavy job on an efficiency core can make the whole parallel job wait for it.<\/p>\n<p>Functions <em><strong>is_linux(<\/strong><\/em>) and <em><strong>is_macos()<\/strong><\/em> allow us to write OS-specific fine-tuned code.<\/p>\n<p>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.<\/p>\n<p>You can download the code <a href=\"https:\/\/www.rangakrish.com\/downloads\/First.mojo\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\">here.<\/span><\/a><\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[471,17],"tags":[],"class_list":["post-4427","post","type-post","status-publish","format-standard","hentry","category-mojo","category-programming"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-19p","jetpack-related-posts":[{"id":2935,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/11\/07\/why-learn-c\/","url_meta":{"origin":4427,"position":0},"title":"Why Learn C++","author":"admin","date":"November 7, 2022","format":false,"excerpt":"This is the third and the last article in the series \u201cWhy Learn Language-XYZ?\u201d. I talked about Prolog and Lisp earlier. The present article is on C++. Once you have gained reasonable proficiency with Prolog and Lisp, you are ready to learn C++! In my view, C++ is a complex\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2383,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/04\/26\/lparallel-a-parallel-programming-library\/","url_meta":{"origin":4427,"position":1},"title":"lparallel: A Parallel Programming Library","author":"admin","date":"April 26, 2021","format":false,"excerpt":"You may recall that in the last article I had reviewed the book \"Algorithms in Lisp\"\u00a0by Vsevolod Domkin. There was a reference to the lparallel\u00a0library in Chapter 15 of the book. That immediately reminded me of the nice discussion of lparallel by Edi Weitz in Chapter 11 of his excellent\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"pmap: Parallel Map","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/04\/pmap-300x208.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/04\/pmap-300x208.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/04\/pmap-300x208.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1339,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/23\/book-review-real-time-c\/","url_meta":{"origin":4427,"position":2},"title":"Book Review: Real-Time C++","author":"admin","date":"December 23, 2018","format":false,"excerpt":"Title: Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming Author: Christopher Kormanyos Publisher: Springer-Verlag Year: 2018 (Third Edition) It was the title of this book which caught my attention a few weeks ago and I decided to invest in it. I am not in to real-time software development these days,\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2496,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/08\/07\/first-encounter-with-the-ring-programming-language\/","url_meta":{"origin":4427,"position":3},"title":"First Encounter with the Ring Programming Language","author":"admin","date":"August 7, 2021","format":false,"excerpt":"The Ring Programming Language, designed by Mahmoud Fayed,\u00a0 has been around since 2016. I came to know of it quite accidentally two weeks ago when I received a promotional email from Apress about their book \"Beginning Ring Programming\" by Mansour Ayouni, published in 2020. I immediately did a google search\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Ring Installation Directory","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/08\/directory-300x155.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":304,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/08\/20\/cuda-and-mathematica\/","url_meta":{"origin":4427,"position":4},"title":"CUDA and Mathematica","author":"admin","date":"August 20, 2016","format":false,"excerpt":"Recently I purchased a high-end desktop computer for my image processing project. Since many computations tend to take several hours to execute, I wanted to accelerate the calculations to the extent possible by adding a GPU. I chose NIVIDA's GeForce GTX 1080\u00a0processor-based card. Although I will be using C++ for\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Basic CUDA Check","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/08\/Mathematica-1-1024x771.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/08\/Mathematica-1-1024x771.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/08\/Mathematica-1-1024x771.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/08\/Mathematica-1-1024x771.png?resize=700%2C400 2x"},"classes":[]},{"id":1278,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/02\/book-review-functional-programming-in-c\/","url_meta":{"origin":4427,"position":5},"title":"Book Review: Functional Programming in C++","author":"admin","date":"December 2, 2018","format":false,"excerpt":"Title: Functional Programming in C++: How to improve your C++ programs using functional techniques Author: Ivan Cukic Publisher: Manning Publications Co. Year: 2019 This book came out recently, about a week ago. I bought it immediately, and when I started to read it, I couldn\u2019t put it down! Very informative\u2026","rel":"","context":"In &quot;Book Review&quot;","block_context":{"text":"Book Review","link":"https:\/\/www.rangakrish.com\/index.php\/category\/book-review\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=4427"}],"version-history":[{"count":6,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4427\/revisions"}],"predecessor-version":[{"id":4435,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4427\/revisions\/4435"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=4427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=4427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=4427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}