Showing posts with label MOJO. Show all posts
Showing posts with label MOJO. Show all posts

what is MOJO? | Learn mojo introduction

 HEY GUERILLIANS WELCOME BACK TO GUERILLA TECK WE ARE STARTING A NEW SERIES ON A TRENDING LANGUAGE WHICH IS MOJO LET’S START.


ABOUT MOJO AND ITS FOUNDER

The developer of Swift and the LLVM Compiler Infrastructure, Chris Latner, who also created Mojo Lang, has merged Python's simplicity of use with C's strength. Because of the hardware's exceptional programmability and the models' extensibility, this has enabled a new level of programming for all AI developers.

In terms of speed, Mojo Lang is 35000x quicker than Python, Scalar C++ is 5000x faster, and PyPy is 22x faster.

The programming language Mojo Lang is intended for use with CUDA-enabled GPUs and other AI gear. It accomplishes this by scaling hardware types without being complicated by utilizing Multi-Level Intermediate Representation (MLIR).

Since Mojo Lang is a superset of Python, you won't need to learn any more programming languages. Isn't it convenient? Because of the base language's complete compatibility with Python, you can connect with the Python ecosystem and use NumPy and other libraries. Mojo Lang combines the simplicity of Python with the strength of the C programming language, thanks to Chris Latner, who also invented the Swift programming language and the LLVM Compiler Infrastructure. All AI developers now have access to previously unheard-of levels of programming thanks to the extensibility of AI models and the programmability of AI hardware.

• Types are used to improve efficiency and error checks.

• Taking control of memory through the zero-cost inline assignment of values to structures.

• Ownership and Borrower checking using memory safety to eliminate sharp edges.

• With auto-tuning, your parameters can be automatically determined to have the best values.

Differences between Mojo Lang and Python

Mojo Lang and Python are so similar, but there must be some differences, right?

Well, we’ve established that speed is the main difference between the two. But there are a few more.

Adding types

Similar to a Python class, Mojo Lang's built-in struct keyword. Structural differences from dynamical differences between class and struct.

var and let are two immutable keywords in the Mojo Lang syntax for instructing. In Mojo Lang, fn, a stricter function, takes the place of def, which defines a function as we are all familiar with from Python.

The built-in type SIMD (Single Instruction Many Data) in Mojo Lang can describe a vector in which a single instruction can be performed over many elements concurrently on the underlying hardware.

You can increase efficiency by 500 times by using the struct type and using it in the Python implementation.

Parallel Computing

Mojo Lang has a built-in parallelization feature that allows you to split your code into multiple threads, which can increase speed by 2000 times. Parallel processing is not available in Python and can be very complex.

Tiling Optimization

Mojo has a built-in tile optimization tool that allows you to cache and reuse your data more effectively. You can use and reuse memory that is close together at a given time.

Autotune

With the use of Autotune Mojo Lang, you can automatically modify your program's code to locate the ideal hardware-specific parameters.


CAN WE USE MOJO NOW???

THE ANSWER IS NO IT IS NOT PUBLICALLY AVAILABLE BUT WE ARE HERE TO TELL YOU ABOUT IT. IT IS ONLY AVAILABLE FOR DEVELOPERS IF YOU WANT SO WE CAN MAKE A BLOG ABOUT IT.

LET’S START WITH SOME CODING PART

Mojo is designed as a superset of Python, so many language features you are familiar with and the concepts you know in Python translate directly to Mojo. For instance, a "Hello World" program in Mojo looks exactly as it does in Python:


OUTPUT


And we can import our favorite libraries of Python in Mojo too and use them similarly to Python.


Basic systems programming extensions in Mojo

Systems programming is something to which Python is not well suited and where Mojo shines. Basic systems programming in Mojo is covered in this part.

1. Let and Var declarations

Similar to Python, you can give name values, and it implicitly creates a function-scope variable inside a function. This offers a very flexible and simple approach to writing code, but it also presents a challenge for two reasons:

1) Systems programmers often want to declare an immutable value.

2) Systems programmers want to get an error if they mistype a variable name in an assignment.

To support this, Mojo supports `let` and `var` declarations, which introduce a new scoped runtime value: `let` is immutable, and `var` is mutable.

For example:-


OUTPUT:- 3

Example 2:-


OUTPUT:- 1.0

STRUCT TYPE IN MOJO

Low-level data layout controls, indirection-free field access, and other techniques can be built upon in modern systems programming to create high-level and secure abstractions. The struct type is offered by Mojo in this regard.

In many aspects, classes and struct types are comparable. Classes, on the other hand, have dynamic dispatch, monkey-patching (also known as dynamic method "swizzling"), and dynamically bound instance properties, whereas structs are static, bound at compilation time, and embedded within their container rather than inherently indirect and reference counted.

Example:-





That’s all for today we’ll get back to it as soon as possible

Thank you