5

I have been trying to run a Python program on a system with RISC-V architecture. The program involves runs a simple artificial neural network model, and involves the use of numpy.

However, the operating system running on the RISC-V archtecture (currently running on an FPGA) is a very basic Linux system that cannot install software such as Python3 or Pip. But it can compile C/C++ programs and run them. So I thought there could still be a way to run my Python program on this system, by converting it to C/C++ on my host system, transferring it to the RISC-V system, and compile it there.

The problem is that I am not able to find a good Python to C/C++ converter software anywhere. I found that there are some software tools available to convert Python code to binary executables, such as py2exe and pyinstaller. However, it is irrelevant if I am trying to run machine code, only compatible only with my host system architecture, using RISC-V architecture.

I also came across Nuitka, which does convert Python code into C/C++ and stores it in a portable distribution folder, but then also generates shared object files (.so) for libraries which I have imported in my program, which again can't be executed on the RISC-V system. Furthermore, based on what I have seen in the Nuitka documentation, there are no guidelines for compiling of the C/C++ code in the distribution.

So I have a couple of questions :

  1. Based on the constraints I have mentioned regarding my RISC-V system, is there any other procedure I could follow to run my Python program on the system?
  2. If not, is there any software tools that I could use to convert Python to C/C++, other than Nuitka?
  3. If not, can you provide a clear procedure as to how to convert Python code to C/C++ using Nuitka, and then compiling the given C/C++ code on the RISC-V system?
  • That task is not as easy as you may think; it is somehow hard to manage. The best is to have some cross-compiler to compile to native RISC-V platform on another one and then deploy the generated executable on your target. But this is beyond SO purpose. First have a look a cross-compiler for your dev platform. – Jean-Baptiste Yunès Jun 10 '20 at 08:15
  • 2
    If it is a simple neural network model, why not directly writing a C++ code for it, starting from this model and not from the Python code? – Damien Jun 10 '20 at 08:15
  • @Damien, the program that I had mentioned was just a test program. My main aim is to run any Python program, which would include those importing Tensorflow, PyTorch, etc., on the RISC-V system. – Bharath Kinnal Jun 10 '20 at 13:40
  • Based on what you've described, I'd go for patching Nuitka and have it use a RISC-V cross compiler to generate binaries, instead of the host compiler – valiano Jun 11 '20 at 14:42
  • @BharathKinnal how about progress in your project? – Adam Mierzwiak Aug 21 '20 at 12:37
  • try https://chocopy.org – Delfino Jun 29 '21 at 01:38
  • @BharathKinnal Have you got the answer to your question? It's my question too – engineer1155 Feb 03 '22 at 17:00

1 Answers1

0

You say your system can compile C/C++ programs and run them. Most python interpreters, such as the reference implementation CPython, are C programs, so perhaps the best course of action is to try to compile python itself on your system and then run the python scripts using that. https://github.com/python/cpython#build-instructions CPython's build instructions claim it will work for Linux, although it may fail if you don't have other programs used in the build process (eg make). Good luck!