Home Programming PyXL: Run Python Code Directly In Hardware!

PyXL: Run Python Code Directly In Hardware!

Meet PyXL: The Processor That Runs Python Code Directly. No OS, No VM, No JIT Required!

By sk
910 views 5 mins read

We all know Python. It's one of the most popular programming languages because it's easy to read and quick to get things done. But when you need your code to run incredibly fast, or on tiny, low-cost chips called microcontrollers, Python usually isn't the first choice. This is because Python typically needs extra software layers, like interpreters or virtual machines (VMs), to run, which can slow things down.

But what if you could run Python code without all that extra software? Directly, on a specially designed piece of hardware? That's the exciting idea behind a new project called PyXL.

What Exactly is PyXL?

Think of PyXL as a custom-built computer chip (a hardware processor) specifically designed to understand and execute Python code. Instead of a standard computer chip running a Python interpreter program, the PyXL hardware is the interpreter, built right into the "silicon" (the material chips are made from).

PyXL Processor
PyXL, a custom-built Processor designed to execute Python code

It's not just running a regular Python program on a standard chip really, really fast. PyXL uses a special set of tools (a toolchain) to prepare your Python code.

It takes your standard Python file (.py) and first turns it into a format called CPython ByteCode, then translates that into a custom set of instructions (called PySM), and finally creates a hardware file (a binary) that the PyXL chip can run directly.

Why Build Hardware for Python?

The main goal of PyXL is to achieve super-fast speeds and predictable timing for Python code, especially in situations where timing is critical.

Let's look at a simple test: turning a digital pin on a chip off and on very quickly and measuring the time it takes for the signal to go out one pin and be read back on another (called a GPIO roundtrip). This is a basic test of how quickly a chip can react to the outside world.

On a popular MicroPython board (called the PyBoard), this GPIO test takes about 15,000 nanoseconds (that's 15 millionths of a second). This is because the Python code has to go through MicroPython's software interpreter and layers of software before it talks to the pin.

PyXL skips these software layers. The custom PyXL hardware is designed to execute the instructions from your compiled Python code directly, and the connection to the GPIO pins is wired physically into the processor. In the same test, PyXL achieved a GPIO roundtrip time of just 480 nanoseconds.

That means PyXL is about 30 times faster than MicroPython on the PyBoard in this test. If you adjust for the fact that the PyXL chip currently runs at a lower speed (100MHz compared to the PyBoard's 168MHz), the speed difference is even more dramatic, roughly 50 times faster.

Beyond just speed, PyXL offers deterministic timing. In the GPIO test, the time taken was exactly the same every single time (480ns). MicroPython, like other software-based systems, shows some variation in timing (jitter). This predictability is vital for applications that need to react to things at precisely the right moment.

What Can PyXL Be Used For?

Because it makes Python fast and predictable, PyXL could be useful in areas where Python traditionally wasn't suitable due to performance limitations. This includes things like:

  • Real-time control systems: Where machines or processes need to be controlled with very precise timing.
  • Robotics: For tasks like processing sensor data and controlling motors with high accuracy.
  • Systems needing quick reactions to sensors: Such as in machine learning where a decision based on sensor input needs to happen instantly.
  • Embedded industrial systems: Where reliability and exact timing are critical.

The idea is that you could write the important performance-sensitive parts of your project in Python and run them directly on the PyXL hardware for speed and predictability.

Is PyXL Ready for Everyone?

PyXL is currently an early-stage project, developed by a single person. It runs on a specific development board that uses a chip called a Zynq-7000 FPGA (specifically, the Arty-Z7-20 development board).

Importantly, it only supports a subset of Python right now. Many features from the standard Python (CPython) aren't implemented yet. Some features, like complex runtime changes to code or dynamic loading, might never be fully supported because the focus is on simple, predictable execution for embedded systems.

Also, existing Python libraries written in C cannot be used directly on PyXL as it is today. Memory management (like garbage collection) is also still a work in progress.

While the developer describes PyXL as executing Python "directly" in hardware, some technical discussions note that it involves compiling the Python code into a custom set of instructions for the hardware, which is a form of compilation like preparing code for any other chip.

However, the key difference is that the hardware is designed specifically for these Python-like instructions, avoiding the need for a separate software interpreter.

Looking Ahead

PyXL offers a unique and potentially powerful way to use Python in embedded and real-time applications by building hardware specifically for it.

While it's still under development and has limitations, the early performance results show a significant leap in speed and timing predictability compared to running Python on traditional microcontroller setups.

The developer plans to share more technical details at PyCon 2025.

In summary, PyXL is a project creating a special computer chip to run Python code really fast and predictably, opening up possibilities for using Python in systems where timing is critical.

Resource:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More