My name is Kawano – I’m a data scientist intern here at Hacarus who joined last year November. I’m a master’s student who typically spends time doing research by analyzing insect behavior (for the record, I’m an information science major!). As an intern at Hacarus, I work on FPGA (Field Programmable Gate Arrays) projects. Anywho, let’s get straight to it- have you ever heard of the RISC-V? I’ll be putting in hardware called the Debian into a RISC-V processor with its built-in HiFive Unleashed and executing Sparse Modeling onto it. Let’s get started!
1. Introducing the RISC-V
You might have heard about the RISC-V (pronounced “risk-five”) quite a bit recently if you are following the latest developments in the FPGA space. So what is the RISC-V, anyway? Well, as of late, RISC-V has been rising in popularity in Japan and beyond.
In short, RISC-V is an ISA (Instruction Set Architecture) that was developed by UC Berkley. Most famous ISA is based on Intel’s x86 or ARM architecture. However, to actually use it requires paying a hefty sum of money for licenses and developing the CPU costs a whole lot as well. On the contrary, RISC-V ISA is an open source, license-free option – it is possible for anyone to develop hardware using the RISC-V ISA. What makes me happy about this is that anyone can design an ISA. Furthermore, this means that implementing the RISC-V architecture on FPGA is possible, along with creating a specialized RISC-V based AI required processor chip for IoT or infrastructure.
2. About the HiFive Unleashed Development Kit
Thanks to its open source, license-free approach, RISC-V has become popular around the globe. Which leads us to Hacarus – of course, we need to try it too! Thus, I was given the HiFive Unleashed Development Kit by our CEO and took this opportunity to test out its features.
The HiFive Unleashed Development Kit is a board with built-in RISC-V SoC (System on Chip) and sponsored by the company SiFive. The SiFive company is a team established of mainly UC Berkley researchers developing the RISC-V and for several years have been pioneering the RISC-V development.
The development kit is loaded with the fastest SoC (Freedom U540) and the RISC-V is running Linux with RISC-V mounted to the board (as of May 16, 2019). With 8GB memory, it’s really fast too. Further, the SoC comes with a 1.5 GHz multiprocessor – all in all, this board provides ample compute power so you have more than enough in this environment to try out sparse modeling.
3. Constructing a Debian Environment in RISC-V
3.1 Installation Environment
- Host PC: Mac Book Pro 13 Inch (2017 Model)
- CPU: Core i7
- Memory: 16GB
- Virtual Environment: Ubuntu 18.04 LTS
- Board In-Use: HiFive Unleashed Development Kit
- Memory DDR4 8GB
- micro-SD Card 16GB
I used a virtual machine when putting the OS on the board of the HiFive. Apart from these environments, a wired network environment is also essential.
3.2 HiFive’s HelloWorld
I ran Linux from an SD card on the Raspberry Pi. When purchasing the board, it comes with the SD card in which Linux is also attached. If you read up on the Startup Guide (here), you’ll likely be able to perform this yourself. If you’ve successfully booted up Linux, you can press input basic commands, however, there are too few commands to press- so virtually, you can’t do much of anything. This means you’ll have to plug in other LinuxOS.
3.3 Next, Try Officially Installing Distributed Linux on RISC-V
Before installing Debian, I recommend that you follow the official Linux procedures in the instructions of the earlier mentioned startup guide. If you follow the startup guide protocol, then everything should go swell. The procedures are basically the same, apart from one change since May 2019. That is, at the time of writing, it is necessary to set MSEL2 (the second switch from the right in the figure below) of the DIP switch of the HiFive Unleashed Development Kit, to 0. Based on how freedom-u-sdk was updated, this operation is necessary to run. Information related to freedom-u-sdk is regularly updated on github so please check that out when conducting installation procedures! With this startup guide I conducted the following:
- freedom-u-sdk download as well as install
- Linux (buildroot) install
3.4 Installation Series: Installing Debian
There are a few distributions that can be installed on RISC-V for this project I’ll go with Debian. The reason why I chose Debian is that the project for porting Debian packages to RISC-V is getting a lot of support, and it is an easy-to-use environment for existing software assets.
3.5 Installing Debian on RISC-V
First of all, let’s begin by formatting the micro-SD card. In this article, the micro-SD card is formatted on Ubuntu. Next, format each partition using the file “disk” from the application. When formatting, make sure to format with “ext4”. When the formatting is completed, write Debian to the micro-SD card with the next command. At this time, make sure to put in the micro-SD card on the host PC side. The latest freedom-u-sdk contains an image called format-demo-image, and you can install Debian just by designating it and writing it. Within xxx is sda or sdb will be included. Please set your preference settings according to your own personal environment. Also, if an error occurs by entering the above command,
- Press the same command once more
- Take a look again at the DIP switch settings
Please try either of the options above. ✴︎1
sudo make DISK=/dev/xxx format-demo-image
Please proceed to the following after you’ve finished make.
- Delete the newly created tmp-mnt file directly under freedom-u-sdk.
- Stick micro-SD card to HiFive Unleashed Development Kit
Next step, proceed by inserting chroot as shown below
mount /dev/mmcblk0p2 /mnt mount -t proc /proc /mnt/proc cp /etc/resolv.conf /mnt/etc/resolv.conf chroot /mnt/ /bin/bash
Now you can get into Debian. If you can get into Debian, try the following command:
ntpdate ntp.nict.jp export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true export LC_ALL=C LANGUAGE=C LANG=C dpkg --configure -a echo nameserver 188.8.131.52 >> /etc/resolv.conf apt update apt upgrade
(I think that the command up to dkpg may be put in bashrc.)
4. Adjust the Python Environment
Now that we’ve got the Debian environment in place, next we’ll have to prepare the Python environment.
The version of Python used during this execution is 3.7.3.
4.1 Build pyenv Environment
Begin by installing pyenv.
To install pyenv, first install the following package.
apt -y install make build-essential libssl-dev zlib1g-dev libbz2-dev libfreetype6-dev \ libreadline-dev libsqlite3-dev wget curl libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev
Next, let’s download pyenv.
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
Next, we’ll add ~ / .bashrc.
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)"
By completing the above procedures, we should be able to work pyenv.
4.2 Installing Python 3.7.3
When you’ve confirmed that you’ve installed pyenv, next we’ll install Python.
pyenv install 3.7.3
With the above, we install Python. Depending on the network environment at this time, it will take about approximately 1 hour to install.
Now we play the waiting game.
After the installation completes, switch python to 3.7.3, and confirm if you’ve correctly installed it.
pyenv global 3.7.3 python -V
4.3 Constructing the scikit-learn Environment
4.4 Installing LAPACK and gfortran
apt install gfortran apt -yV install liblapack-dev apt -yV install liblapack-doc apt -yV install liblapack-pic apt -yV install liblapack-test apt -yV install liblapack3gf
4.5 Installing NumPy, SciPy, scikit-learn
pip install numpy==1.16.3 pip install scipy==1.2.1 pip install scikit-learn==0.20.3 pip install matplotlib== 2.2.4
python import sklearn print(sklearn.__version__)
5. Obtaining Samples and Accessing Jupyter Notebook
Finally, we’ve we are able to actually try sparse modeling! We will be using the spm-image sparse modeling sample published on the Hacarus github.
You can proceed according to the README, but if you do not want to spend time setting up the virtual env environment, you can set the environment directly to the pyenv environment. Also, when building an environment in virtual env, make sure that scikit-learn, NumPy, and SciPy’s ver are on the same version as pyenv was built. Start Jupyter Notebook, but this time, follow the steps below to make Jupyter Notebook accessible from host machine via ssh. First, launch the Jupyter Notebook on the RISC-V side. This time, specify the port and access by passing the root authority.
jupyter notebook --no-browser --ip="0.0.0.0" --allow-root
6. Moving the Sample of spm-image
In conclusion, I installed Debian in a module called HiFive Unleashed using the RISC-V chip and tried running Jupyter Notebook in that environment. It seems that it will take some time to develop software for RISC-V, but it is definitely an area that will continue to be developed in the future, so I’ll be keeping up with the advancements and keep you posted.
✴︎ 1 When you first conduct make, make often fails. It often works well if you’ve conducted make several times