Today’s concert: ONE WORLD : TOGETHER AT HOME. Yup, today, I’ve my previous blog updated. A lot of modifications. Khadas VIM3 is really a good product. With Amlogic’s A311D with 5.0 TOPS NPU, the board itself comes with a super powerful AI inference capability.

What a sunny day after the **FIRST** snow in this winter. Let me show you 3 pictures in the first row, and 3 videos in the second. We need to enjoy both R&D and life…
Green Timers Lake 1 Green Timers Lake 2 Green Timers Park
A Pair of Swans A Group of Ducks A Little Stream In The Snow

After a brief break, I started investigating Khadas VIM3 again.

Khadas VIM3 is a super computer based on Amlogic A311D. Before we start, let’s carry out several simple comparisons.

# 2. Install Prebuilt Operating System To EMMC Via Krescue

## 2.1 WIRED Connection Preferred

As mentioned in VIM3 Beginners Guide, Krescue is a Swiss Army knife. As of January 2020, Krescue can download and install OS images directly from the web via wired Ethernet.

## 2.3 Setup Wifi From Within Krescue Shell

If you really don’t like the WIRED connection, boot into Krescue shell, and use the following commands to set up Wifi:

## 2.4 SSH Into Krescue Via Wireless Connection

Now, let’s try to connect Khadas VIM3 board remotely.

## 2.5 Flash OS onto EMMC (WIRED Connection Preferred)

Let’s take a look at the SD card device:

### 2.5.1 Install OS Using Shell Command

Please refer to the Shell Commands Examples.

curl -sfL dl.khadas.com/.mega | sh -s - -Y -X > /dev/mmcblk? should do.

### 2.5.2 Install OS Using Krescue GUI

Let’s bring back Krescue GUI by command krescue, and select VIMx.Ubuntu-xfce-bionic_Linux-4.9_arm64_V20191231.emmc.kresq and have it flashed onto EMMC.

Krescue Default Image Write To EMMC
Start Installation Installation Complete
Krescue Reboot Ubuntu XFCE Desktop

## 2.6. Boot From EMMC

Actually, the 8th image in the above just showed Ubuntu XFCE desktop. We can also SSH into it after configuring Wifi successfully.

### 2.6.3 Package Versions

It looks current OpenCV on current VIM3_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20191231.img is a kind of outdated. Let’s just remove package opencv3 and have OpenCV-4.3.0 installed manually.

# 3. Install Manjaro To TF/SD Card

As one of my dreamed operating systems, Manjaro has already provided 2 operating systems for Khadas users to try out.

To flash either of the above systems onto a TF/SD card is simple. However, both are ONLY for SD-USB, instead of EMMC. For instancen:

Before moving on, let’s cite the following word from Boot Images from External Media:

# 4. NPU

In this section, we’re testing the computing capability of Khadas VIM3’s NPU.

Before everything starts, make sure you have the galcore module loaded, by using command modinfo galcore.

## 4.1 Obtain aml_npu_sdk From Khadas

Extract the obtained aml_npu_sdk.tgz on your local host. Bear in mind that it is your local host, BUT NOT Khadas VIM3. Relative issues can be found at:

## 4.2 Model Conversion on Host

Afterwards, the models applicable on Khadas VIM3 can be obtained by following Model Conversion. Anyway, on my laptop, I obtained the converted model as follows:

Do I need to emphasize that I’m using Tensorflow 2.1.0 ? Anyway, check the following:

## 4.3 Build Case Code

### 4.3.1 Cross-build on Host

You can of course cross-build the case code on your local host, instead of Khadas VIM3 by referring to Compile the Case Code. (The document seems NOT updated yet.) Instead of using 1 argument, we specify 2 auguments, one for aml_npu_sdk, the other for Fenix.

inceptionv3 now should be ready to use, but in my case, it’s NOT working properly. It’s probably because Fenix is NOT able to provide/represent the correct cross-compile toolchains for my installed VIMx.Ubuntu-xfce-bionic_Linux-4.9_arm64_V20191231.emmc.kresq. Anyway, this is NOT my preference.

### 4.3.2 Directly Build on Khadas VIM3

Let’s leave this for the next section 4.4 Run Executable on Khadas VIM3.

## 4.4 Run Executable on Khadas VIM3

### 4.4.1 Step 1: Install aml-npu

And with command line dpkg -L aml-npu, you’ll see what’s been installed by aml-npu. However, due to its commercial license, I may NOT be allowed to show anything here in my blog.

😶

### 4.4.2 Step 2: Install aml-npu-demo and Run Demo

Where is the sample to run? /usr/share/npu/inceptionv3.

Alright, let’s try it.

The program runs smoothly.

😏

### 4.4.3 Step 3: Build Your Own Executable and Run

Clearly, ALL (really???) required development files have been provided by aml-npu, in such, we should be able to build this demo inceptionv3 out by ourselves.

#### 4.4.3.1 You STILL Need aml_npu_sdk from Khadas

Besides aml-npu from repo, in order to have the demo inceptionv3 fully and successfully built, you still need aml_npu_sdk from Khadas. In my case, you do need acuity-ovxlib-dev, and let’s do export ACUITY_OVXLIB_DEV=path_to_acuity-ovxlib-dev.

#### 4.4.3.2 Build inceptionv3 from Source

We don’t need to copy the entire aml_npu_sdk onto Khadas VIM3, but ONLY demo/inceptionv3. Here in my case, ONLY demo/inceptionv3 is copied under ~/Programs.

This is almost the same as folder nbg_unify_inception_v3 shown in 4.2 Model Conversion on Host.

Now, The MOST important part is to modify makefile.

My makefile is modified as follows.

In fact, you still need to modify common.target a little bit accordingly. However, to disclose it in this blog is still NOT allowed I think. Anyway, after the modification, let’s make it.

Don’t worry about the error. It just failed to run the demo, but the executable inceptionv3 has already been successfully built under folder bin_r.

#### 4.4.3.3 Run inceptionv3

Let’s run inceptionv3 under folder bin_demo.

This is the original status of ALL files under bin_demo. Let’s copy and paste our built bin_r/inceptionv3 into this folder bin_demo. The size of the executable seems to be dramatically decreased.

Now, let’s copy the built inception_v3.nb from host to Khadas VIM3. It seems inception_v3.nb built by Tensorflow 2.1.0 on host is of the same size as provided by Khadas.

Finally, let’s run the demo.

By comparing to imagenet_slim_labels.txt under current folder, let’s take a look at our inference results. Only the FIRST inference is qualified because of the probability.

Index Result for dog_299x299.jpg Result for goldfish_299x299.jpg
N/A
1 208: ‘curly-coated retriever’, 2: ‘tench’,
2 209: ‘golden retriever’, 795: ‘shower cap’,
3 223: ‘Irish water spaniel’, 974: ‘cliff’,
4 268: ‘miniature poodle’, 408: ‘altar’,
5 185: ‘Kerry blue terrier’, 393: ‘coho’,
😘

# 5. Dual Boot From Manjaro

## 5.1 How to Boot Images from External Media?

There are clearly 2 options:

• dual boot by selecting devices: EMMC or TF/SD Card. On Boot Images from External Media, it’s recommended as Via Keys mode (Side-Buttons) - the easiest and fastest way, which is the FIRST option on page How To Boot Into Upgrade Mode. Therefore, by following 4 steps as follows(cited from How To Boot Into Upgrade Mode), we should be able to boot into SD-USB.
1. Power on VIM3.
2. Long press the POWER key without releasing it.
3. Short press the ‘Reset’ key and release it.
4. Count for 2 to 3 seconds, then release the POWER key to enter into Upgrade Mode. You will see the sys-led turn ON when you’ve entered Upgrade Mode.
• multiple boot via grub: Reasonably speaking, 2 operating systems may even have a chance to be installed onto a SINGLE EMMC

## 5.2 How to flash Manjaro XFCE for Khadas Vim 3 from TF/SD card to EMMC?

ONLY 1 operating system is preferred. Why??? Khadas VIM3 board comes with a large EMMC of size 32G.

After a VERY long time struggling, I would really like to emphasize the quality of Type C cable and power adaptor again. Try to buy things NOT from Taobao.

😢 😭

Finally, I had Manjaro XFCE for Khadas Vim 3 on SD card booted and running, as follows:

It seems Arch Linux is totally different from Debian. What can I say? Go to bed.