Khadas VIM3

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
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.

1. About Khadas VIM3

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

1.1 Raspberry Pi 4 Model B vs. Khadas VIM3 vs. Jetson Nano Developer Kit

Please refer to:

1.2 Amlogic A311D & S922X-B vs. Rockchip RK3399 (Pro) vs. Amlogic S912

Please refer to:

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.2 Flash Krescue Onto SD Card

1
2
3
4
5
➜  Krescue sudo dd bs=4M if=VIM3.krescue-d41d8cd98f00b204e9800998ecf8427e-1587199778-67108864-279c13890fa7253d5d2b76000769803e.sd.img of=/dev/mmcblk0 conv=fsync 
[sudo] password for longervision:
16+0 records in
16+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 4.03786 s, 16.6 MB/s

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
root@Krescue:~# wifi.config WIFI_NAME WIFI_PASSWORD
root@Krescue:~# wifi.client
root@Krescue:~# wifi.status
DRIVER=brcmfmac
OF_NAME=wifi
OF_FULLNAME=/soc/sd@ffe03000/wifi@1
OF_COMPATIBLE_0=brcm,bcm4329-fmac
OF_COMPATIBLE_N=1
SDIO_CLASS=00
SDIO_ID=02D0:4359
MODALIAS=sdio:c00v02D0d4359
[i] iw dev
phy#0
Interface wlan0
ifindex 4
wdev 0x1
addr xx:xx:xx:xx:xx:xx
ssid XXXXXXXXXX
type managed
channel 161 (5805 MHz), width: 80 MHz, center1: 5775 MHz
txpower 31.00 dBm
[i] CLIENT mode active 6754
Selected interface 'wlan0'
bssid=xx:xx:xx:xx:xx:xx
freq=5805
ssid=XXXXXXXXXX
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.1.110
address=xx:xx:xx:xx:xx:xx
uuid=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
ieee80211ac=1

2.4 SSH Into Krescue Via Wireless Connection

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
➜  ~ ping 192.168.1.110
PING 192.168.1.110 (192.168.1.110) 56(84) bytes of data.
64 bytes from 192.168.1.110: icmp_seq=1 ttl=64 time=140 ms
64 bytes from 192.168.1.110: icmp_seq=2 ttl=64 time=54.0 ms
64 bytes from 192.168.1.110: icmp_seq=3 ttl=64 time=13.1 ms
^C
--- 192.168.1.110 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 13.191/69.145/140.193/52.936 ms
➜ ~ ssh root@192.168.1.110
The authenticity of host '192.168.1.110 (192.168.1.110)' can't be established.
RSA key fingerprint is SHA256:0t0PZw/24nWc8hWaCJkltYtwCduMMSlRuux2Nn865Os.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.110' (RSA) to the list of known hosts.


BusyBox v1.28.4 () built-in shell (ash)

OpenWrt 18.06.3, r7798-97ae9e0ccb

__ _____ Khadas ## hyphop ##
/ //_/ _ \___ ___ ______ _____
/ ,< / , _/ -_|_-</ __/ // / -_)
/_/|_/_/|_|\__/___/\__/\_,_/\__/

extreme tiny and fast rescue system

BUILD: Sat Apr 18 08:49:28 UTC 2020

[i] POST_CONFIG: ap_ssid=Krescue ap_passw=12345678 wifi_mode=2g script=sd:launcher.sh eth_hw=C0:4A:00:C0:3F:DB booted= hwver=VIM3.V12

=== WARNING! =====================================
There is no root password defined on this device!
Use the passwd command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@Krescue:~# uname -a
Linux Krescue 5.4.5 #4 SMP PREEMPT Thu Apr 9 22:07:48 +09 2020 aarch64 GNU/Linux

2.5 Flash OS onto EMMC (WIRED Connection Preferred)

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

1
2
root@Krescue:~# ls /dev/mmcblk*
/dev/mmcblk1 /dev/mmcblk1p1 /dev/mmcblk1p2 /dev/mmcblk2 /dev/mmcblk2boot0 /dev/mmcblk2boot1 /dev/mmcblk2rpmb

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
Krescue Default Image Write To EMMC
Select Prebuilt OS Start Downloading OS
Select Prebuilt OS Start Downloading OS
Start Installation Installation Complete
Start Installation Installation Complete
Krescue Reboot Ubuntu XFCE Desktop
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.1 SSH Into Khadas VIM3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜  ~ ssh khadas@192.168.1.95
The authenticity of host '192.168.1.95 (192.168.1.95)' can't be established.
ECDSA key fingerprint is SHA256:Q59XrIX7bSWsphZCpgHBSnVH5ETgCY9iLfDEuvRKtOw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.95' (ECDSA) to the list of known hosts.
khadas@192.168.1.95's password:

Welcome to Fenix 0.8.1 Ubuntu 18.04.3 LTS Linux 4.9.206
_ ___ _ __ _____ __ __ _____
| |/ / |__ __ _ __| | __ _ ___ \ \ / /_ _| \/ |___ /
| ' /| '_ \ / _` |/ _` |/ _` / __| \ \ / / | || |\/| | |_ \
| . \| | | | (_| | (_| | (_| \__ \ \ V / | || | | |___) |
|_|\_\_| |_|\__,_|\__,_|\__,_|___/ \_/ |___|_| |_|____/


* Website: https://www.khadas.com
* Documentation: https://docs.khadas.com
* Forum: https://forum.khadas.com

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

2.6.2 Specs For Khadas VIM3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
khadas@Khadas:~$ uname -a
Linux Khadas 4.9.206 #13 SMP PREEMPT Tue Dec 31 00:37:47 CST 2019 aarch64 aarch64 aarch64 GNU/Linux
khadas@Khadas:~$ cat /proc/cpuinfo
processor : 0
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 1
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 2
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 2

processor : 3
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 2

processor : 4
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 2

processor : 5
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 2

Serial : 290b1000010c1900000437304e424e50
Hardware : Khadas VIM3
khadas@Khadas:~$ clinfo
Number of platforms 1
Platform Name ARM Platform
Platform Vendor ARM
Platform Version OpenCL 2.0 git.c8adbf9.ad00b04c1b60847de257177231dc1a53
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_icd cl_khr_egl_image cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_create_command_queue cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory cl_arm_shared_virtual_memory
Platform Extensions function suffix ARM

Platform Name ARM Platform
Number of devices 1
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Device Name <printDeviceInfo:0: get CL_DEVICE_NAME size : error -6>
Device Vendor ARM
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Device Vendor ID <printDeviceInfo:2: get CL_DEVICE_VENDOR_ID : error -6>
Device Version OpenCL 2.0 git.c8adbf9.ad00b04c1b60847de257177231dc1a53
Driver Version 2.0
Device OpenCL C Version OpenCL C 2.0 git.c8adbf9.ad00b04c1b60847de257177231dc1a53
Device Type GPU
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Max compute units <printDeviceInfo:17: get CL_DEVICE_MAX_COMPUTE_UNITS : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Max clock frequency <printDeviceInfo:21: get CL_DEVICE_MAX_CLOCK_FREQUENCY : error -6>
Device Partition (core)
Max number of sub-devices 0
Supported partition types None
Max work item dimensions 3
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Max work item sizes <printDeviceInfo:36: get number of CL_DEVICE_MAX_WORK_ITEM_SIZES : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Max work group size <printDeviceInfo:37: get CL_DEVICE_MAX_WORK_GROUP_SIZE : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Preferred work group size multiple <getWGsizes:671: create context : error -6>
Preferred / native vector sizes
char 16 / 4
short 8 / 2
int 4 / 1
long 2 / 1
half 8 / 2 (cl_khr_fp16)
float 4 / 1
double 0 / 0 (n/a)
Half-precision Floating-point support (cl_khr_fp16)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Correctly-rounded divide and sqrt operations No
Double-precision Floating-point support (n/a)
Address bits 64, Little-Endian
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Global memory size <printDeviceInfo:74: get CL_DEVICE_GLOBAL_MEM_SIZE : error -6>
Error Correction support No
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Max memory allocation <printDeviceInfo:80: get CL_DEVICE_MAX_MEM_ALLOC_SIZE : error -6>
Unified memory for Host and Device Yes
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Shared Virtual Memory (SVM) capabilities <printDeviceInfo:83: get CL_DEVICE_SVM_CAPABILITIES : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Shared Virtual Memory (SVM) capabilities (ARM) <printDeviceInfo:84: get CL_DEVICE_SVM_CAPABILITIES_ARM : error -6>
Minimum alignment for any data type 128 bytes
Alignment of base address 1024 bits (128 bytes)
Preferred alignment for atomics
SVM 0 bytes
Global 0 bytes
Local 0 bytes
Max size for global variable 65536 (64KiB)
Preferred total size of global vars 0
Global Memory cache type Read/Write
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Global Memory cache size <printDeviceInfo:97: get CL_DEVICE_GLOBAL_MEM_CACHE_SIZE : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Global Memory cache line size <printDeviceInfo:98: get CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE : error -6>
Image support Yes
Max number of samplers per kernel 16
Max size for 1D images from buffer 65536 pixels
Max 1D or 2D image array size 2048 images
Base address alignment for 2D image buffers 32 bytes
Pitch alignment for 2D image buffers 64 pixels
Max 2D image size 65536x65536 pixels
Max 3D image size 65536x65536x65536 pixels
Max number of read image args 128
Max number of write image args 64
Max number of read/write image args 64
Max number of pipe args 16
Max active pipe reservations 1
Max pipe packet size 1024
Local memory type Global
Local memory size 32768 (32KiB)
Max number of constant args 8
Max constant buffer size 65536 (64KiB)
Max size of kernel argument 1024
Queue properties (on host)
Out-of-order execution Yes
Profiling Yes
Queue properties (on device)
Out-of-order execution Yes
Profiling Yes
Preferred size 2097152 (2MiB)
Max size 16777216 (16MiB)
Max queues on device 1
Max events on device 1024
Prefer user sync for interop No
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
Profiling timer resolution <printDeviceInfo:145: get CL_DEVICE_PROFILING_TIMER_RESOLUTION : error -6>
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
printf() buffer size 1048576 (1024KiB)
Built-in kernels
Device Extensions cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_icd cl_khr_egl_image cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_create_command_queue cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory cl_arm_shared_virtual_memory

NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) ARM Platform
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [ARM]
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
clCreateContext(NULL, ...) [default] <checkNullCtx:2694: create context with device from default platform : error -6>
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) <checkNullCtxFromType:2737: create context from type CL_DEVICE_TYPE_DEFAULT : error -6>
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) <checkNullCtxFromType:2737: create context from type CL_DEVICE_TYPE_GPU : error -6>
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
ERROR: The DDK (built for 0x70030000 r0p0 status range [0..15]) is not compatible with this Mali GPU device, /dev/mali0 detected as 0x7212 r0p0 status 0.
Failed creating base context during DDK compatibility check.
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) <checkNullCtxFromType:2737: create context from type CL_DEVICE_TYPE_ALL : error -6>

ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.2.11
ICD loader Profile OpenCL 2.1
khadas@Khadas:~$ cat /proc/partitions
major minor #blocks name

1 0 4096 ram0
1 1 4096 ram1
1 2 4096 ram2
1 3 4096 ram3
1 4 4096 ram4
1 5 4096 ram5
1 6 4096 ram6
1 7 4096 ram7
1 8 4096 ram8
1 9 4096 ram9
1 10 4096 ram10
1 11 4096 ram11
1 12 4096 ram12
1 13 4096 ram13
1 14 4096 ram14
1 15 4096 ram15
179 0 30535680 mmcblk0
179 1 4096 mmcblk0p1
179 2 65536 mmcblk0p2
179 3 8192 mmcblk0p3
179 4 8192 mmcblk0p4
179 5 32768 mmcblk0p5
179 6 30351360 mmcblk0p6
179 96 4096 mmcblk0rpmb
179 64 4096 mmcblk0boot1
179 32 4096 mmcblk0boot0
251 1 262144 zram1
251 2 262144 zram2
251 3 262144 zram3
251 4 262144 zram4
khadas@Khadas:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 371M 15M 357M 4% /run
/dev/rootfs 29G 3.2G 25G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 1.9G 24K 1.9G 1% /tmp
tmpfs 371M 8.0K 371M 1% /run/user/1000

2.6.3 Package Versions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
khadas@Khadas:~$ gcc --version
gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

khadas@Khadas:~$ python --version
Python 3.6.9
khadas@Khadas:~$ ls /usr/lib/libopencv*
libopencv_calib3d.so libopencv_dnn.so.3.4.3 libopencv_highgui.so.3.4 libopencv_ml.so libopencv_photo.so.3.4.3 libopencv_superres.so.3.4 libopencv_videostab.so
libopencv_calib3d.so.3.4 libopencv_features2d.so libopencv_highgui.so.3.4.3 libopencv_ml.so.3.4 libopencv_shape.so libopencv_superres.so.3.4.3 libopencv_videostab.so.3.4
libopencv_calib3d.so.3.4.3 libopencv_features2d.so.3.4 libopencv_imgcodecs.so libopencv_ml.so.3.4.3 libopencv_shape.so.3.4 libopencv_video.so libopencv_videostab.so.3.4.3
libopencv_core.so libopencv_features2d.so.3.4.3 libopencv_imgcodecs.so.3.4 libopencv_objdetect.so libopencv_shape.so.3.4.3 libopencv_video.so.3.4
libopencv_core.so.3.4 libopencv_flann.so libopencv_imgcodecs.so.3.4.3 libopencv_objdetect.so.3.4 libopencv_stitching.so libopencv_video.so.3.4.3
libopencv_core.so.3.4.3 libopencv_flann.so.3.4 libopencv_imgproc.so libopencv_objdetect.so.3.4.3 libopencv_stitching.so.3.4 libopencv_videoio.so
libopencv_dnn.so libopencv_flann.so.3.4.3 libopencv_imgproc.so.3.4 libopencv_photo.so libopencv_stitching.so.3.4.3 libopencv_videoio.so.3.4
libopencv_dnn.so.3.4 libopencv_highgui.so libopencv_imgproc.so.3.4.3 libopencv_photo.so.3.4 libopencv_superres.so libopencv_videoio.so.3.4.3
khadas@Khadas:~$ cat /usr/lib/pkgconfig/opencv.pc
# Package Information for pkg-config

prefix=/usr/local/nick
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.4.3
Libs: -L${exec_prefix}/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}
khadas@Khadas:~$ sudo apt remove opencv3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libllvm8
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
opencv3
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1024 B disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 118978 files and directories currently installed.)
Removing opencv3 (3.4.3-2) ...
khadas@Khadas:~$ ls /usr/lib/libopencv*
ls: cannot access '/usr/lib/libopencv*': No such file or directory
khadas@Khadas:~$ cat /usr/lib/pkgconfig/opencv.pc
cat: /usr/lib/pkgconfig/opencv.pc: No such file or directory

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:

1
2
3
➜  Manjaro burn-tool -b VIM3 -i ./Manjaro-ARM-xfce-vim3-20.04.img 
Try to burn Amlogic image...
ERROR: Try to burn to eMMC storage, but the image installation type is 'SD-USB', please use 'EMMC' image!

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

1
WARNING: Don’t use your PC as the USB-Host to supply the electrical power, otherwise it will fail to activate Multi-Boot!

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
➜  nbg_unify_inception_v3 ll
total 28M
-rwxrwxrwx 1 longervision longervision 577 Apr 27 14:10 BUILD
-rwxrwxrwx 1 longervision longervision 28M Apr 27 14:10 inception_v3.nb
-rwxrwxrwx 1 longervision longervision 13K Apr 27 14:10 inceptionv3.vcxproj
-rwxrwxrwx 1 longervision longervision 5.8K Apr 27 14:10 main.c
-rwxrwxrwx 1 longervision longervision 2.0K Apr 27 14:10 makefile.linux
-rwxrwxrwx 1 longervision longervision 358 Apr 27 14:10 vnn_global.h
-rwxrwxrwx 1 longervision longervision 7.1K Apr 27 14:10 vnn_inceptionv3.c
-rwxrwxrwx 1 longervision longervision 985 Apr 27 14:10 vnn_inceptionv3.h
-rwxrwxrwx 1 longervision longervision 3.5K Apr 27 14:10 vnn_post_process.c
-rwxrwxrwx 1 longervision longervision 464 Apr 27 14:10 vnn_post_process.h
-rwxrwxrwx 1 longervision longervision 20K Apr 27 14:10 vnn_pre_process.c
-rwxrwxrwx 1 longervision longervision 1.3K Apr 27 14:10 vnn_pre_process.h

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

1
2
3
4
5
6
7
8
➜  ~ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-04-29 03:11:24.272348: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.2
>>> tf.__version__
'2.1.0'

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
➜  nbg_unify_inception_v3 ./build_vx.sh ....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4 ....../fenix 
aarch64-linux-gnu-gcc -c -DLINUX -Wall -D_REENTRANT -fno-strict-aliasing -mtune=cortex-a53 -march=armv8-a -O2 -DgcdENABLE_3D=1 -DgcdENABLE_2D=0 -DgcdENABLE_VG=0 -DgcdUSE_VX=1 -DUSE_VDK=1 -DgcdMOVG=0 -DEGL_API_FB -DgcdSTATIC_LINK=0 -DgcdFPGA_BUILD=0 -DGC_ENABLE_LOADTIME_OPT=1 -DgcdUSE_VXC_BINARY=0 -DgcdGC355_MEM_PRINT=0 -DgcdGC355_PROFILER=0 -DVIVANTE_PROFILER=1 -DVIVANTE_PROFILER_CONTEXT=1 -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include/HAL -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/sdk/inc -I./ -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/utils -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/client -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/ops -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/third-party/jpeg-9b -o bin_r/vnn_pre_process.o vnn_pre_process.c
aarch64-linux-gnu-gcc -c -DLINUX -Wall -D_REENTRANT -fno-strict-aliasing -mtune=cortex-a53 -march=armv8-a -O2 -DgcdENABLE_3D=1 -DgcdENABLE_2D=0 -DgcdENABLE_VG=0 -DgcdUSE_VX=1 -DUSE_VDK=1 -DgcdMOVG=0 -DEGL_API_FB -DgcdSTATIC_LINK=0 -DgcdFPGA_BUILD=0 -DGC_ENABLE_LOADTIME_OPT=1 -DgcdUSE_VXC_BINARY=0 -DgcdGC355_MEM_PRINT=0 -DgcdGC355_PROFILER=0 -DVIVANTE_PROFILER=1 -DVIVANTE_PROFILER_CONTEXT=1 -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include/HAL -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/sdk/inc -I./ -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/utils -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/client -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/ops -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/third-party/jpeg-9b -o bin_r/vnn_inceptionv3.o vnn_inceptionv3.c
vnn_inceptionv3.c: In function ‘vnn_CreateInceptionV3’:
vnn_inceptionv3.c:139:29: warning: unused variable ‘data’ [-Wunused-variable]
uint8_t * data;
^~~~
At top level:
vnn_inceptionv3.c:91:17: warning: ‘load_data’ defined but not used [-Wunused-function]
static uint8_t* load_data
^~~~~~~~~
aarch64-linux-gnu-gcc -c -DLINUX -Wall -D_REENTRANT -fno-strict-aliasing -mtune=cortex-a53 -march=armv8-a -O2 -DgcdENABLE_3D=1 -DgcdENABLE_2D=0 -DgcdENABLE_VG=0 -DgcdUSE_VX=1 -DUSE_VDK=1 -DgcdMOVG=0 -DEGL_API_FB -DgcdSTATIC_LINK=0 -DgcdFPGA_BUILD=0 -DGC_ENABLE_LOADTIME_OPT=1 -DgcdUSE_VXC_BINARY=0 -DgcdGC355_MEM_PRINT=0 -DgcdGC355_PROFILER=0 -DVIVANTE_PROFILER=1 -DVIVANTE_PROFILER_CONTEXT=1 -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include/HAL -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/sdk/inc -I./ -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/utils -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/client -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/ops -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/third-party/jpeg-9b -o bin_r/main.o main.c
aarch64-linux-gnu-gcc -c -DLINUX -Wall -D_REENTRANT -fno-strict-aliasing -mtune=cortex-a53 -march=armv8-a -O2 -DgcdENABLE_3D=1 -DgcdENABLE_2D=0 -DgcdENABLE_VG=0 -DgcdUSE_VX=1 -DUSE_VDK=1 -DgcdMOVG=0 -DEGL_API_FB -DgcdSTATIC_LINK=0 -DgcdFPGA_BUILD=0 -DGC_ENABLE_LOADTIME_OPT=1 -DgcdUSE_VXC_BINARY=0 -DgcdGC355_MEM_PRINT=0 -DgcdGC355_PROFILER=0 -DVIVANTE_PROFILER=1 -DVIVANTE_PROFILER_CONTEXT=1 -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/include/HAL -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/sdk/inc -I./ -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/utils -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/client -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include/ops -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/include -I....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/third-party/jpeg-9b -o bin_r/vnn_post_process.o vnn_post_process.c
aarch64-linux-gnu-gcc -mtune=cortex-a53 -march=armv8-a -Wl,-rpath-link ....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/drivers bin_r/vnn_pre_process.o bin_r/vnn_inceptionv3.o bin_r/main.o bin_r/vnn_post_process.o -o bin_r/inceptionv3 -L....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/build/sdk/drivers -l OpenVX -l OpenVXU -l CLC -l VSC -lGAL ....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/lib/libjpeg.a -L....../aml_npu_sdk/linux_sdk/linux_sdk_6.3.3.4/acuity-ovxlib-dev/lib -l ovxlib -L....../fenix/build/toolchains/gcc-linaro-aarch64-linux-gnu/aarch64-linux-gnu/libc/lib -lm -lrt
aarch64-linux-gnu-strip bin_r/inceptionv3
make: Nothing to be done for 'all'.
➜ nbg_unify_inception_v3 ll bin_r
total 164K
-rwxrwxrwx 1 longervision longervision 126K Apr 27 14:22 inceptionv3
-rwxrwxrwx 1 longervision longervision 6.3K Apr 27 14:22 main.o
-rwxrwxrwx 1 longervision longervision 3.9K Apr 27 14:22 vnn_inceptionv3.o
-rwxrwxrwx 1 longervision longervision 3.5K Apr 27 14:22 vnn_post_process.o
-rwxrwxrwx 1 longervision longervision 17K Apr 27 14:22 vnn_pre_process.o

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
khadas@Khadas:~$ sudo apt install aml-npu
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libllvm8 libssh-dev
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
aml-npu
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/3318 kB of archives.
After this operation, 1024 B of additional disk space will be used.
Selecting previously unselected package aml-npu.
(Reading database ... 136037 files and directories currently installed.)
Preparing to unpack .../aml-npu_6.4.0.3_arm64.deb ...
Unpacking aml-npu (6.4.0.3) ...
Setting up aml-npu (6.4.0.3) ...

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
khadas@Khadas:~$ sudo apt install aml-npu-demo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libllvm8 libssh-dev
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
aml-npu-demo
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/19.7 MB of archives.
After this operation, 1024 B of additional disk space will be used.
Selecting previously unselected package aml-npu-demo.
(Reading database ... 136098 files and directories currently installed.)
Preparing to unpack .../aml-npu-demo_6.3.3.4_arm64.deb ...
Unpacking aml-npu-demo (6.3.3.4) ...
Setting up aml-npu-demo (6.3.3.4) ...

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

Alright, let's try it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
khadas@Khadas:~$ cd /usr/share/npu/inceptionv3
khadas@Khadas:/usr/share/npu/inceptionv3$ ./inceptionv3 ./inception_v3.nb ./dog_299x299.jpg
D [setup_node:368]Setup node id[0] uid[4294967295] op[NBG]
D [print_tensor:136]in(0) : id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
D [print_tensor:136]out(0): id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [optimize_node:312]Backward optimize neural network
D [optimize_node:319]Forward optimize neural network
I [compute_node:261]Create vx node
Create Neural Network: 37ms or 37726us
I [vsi_nn_PrintGraph:1421]Graph:
I [vsi_nn_PrintGraph:1422]***************** Tensors ******************
D [print_tensor:146]id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [print_tensor:146]id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
I [vsi_nn_PrintGraph:1431]***************** Nodes ******************
I [vsi_nn_PrintNode:159]( NBG)node[0] [in: 1 ], [out: 0 ] [10587cb0]
I [vsi_nn_PrintGraph:1440]******************************************
I [vsi_nn_ConvertTensorToData:750]Create 268203 data.
Verify...
Verify Graph: 1ms or 1811us
Start run graph [1] times...
Run the 1 time: 28ms or 28075us
vxProcessGraph execution time:
Total 28ms or 28091us
Average 28.09ms or 28091.00us
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.
--- Top5 ---
208: 0.819824
209: 0.040344
223: 0.009354
185: 0.002956
268: 0.002829
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
khadas@Khadas:~/Programs/inceptionv3$ ll
total 28236
drwxr-xr-x 3 khadas khadas 4096 Apr 29 09:23 ./
drwxrwxr-x 5 khadas khadas 4096 Apr 29 09:22 ../
-rwxr-xr-x 1 khadas khadas 577 Apr 29 09:22 BUILD*
drwxr-xr-x 2 khadas khadas 4096 Apr 29 09:22 bin_demo/
-rwxr-xr-x 1 khadas khadas 9878 Apr 29 09:22 build_vx.sh*
-rwxr-xr-x 1 khadas khadas 28807168 Apr 29 09:23 inception_v3.nb*
-rwxr-xr-x 1 khadas khadas 12691 Apr 29 09:22 inceptionv3.vcxproj*
-rwxr-xr-x 1 khadas khadas 5869 Apr 29 09:23 main.c*
-rwxr-xr-x 1 khadas khadas 2000 Apr 29 09:23 makefile.linux*
-rwxr-xr-x 1 khadas khadas 358 Apr 29 09:23 vnn_global.h*
-rwxr-xr-x 1 khadas khadas 7191 Apr 29 09:23 vnn_inceptionv3.c*
-rwxr-xr-x 1 khadas khadas 985 Apr 29 09:23 vnn_inceptionv3.h*
-rwxr-xr-x 1 khadas khadas 3566 Apr 29 09:23 vnn_post_process.c*
-rwxr-xr-x 1 khadas khadas 464 Apr 29 09:23 vnn_post_process.h*
-rwxr-xr-x 1 khadas khadas 20385 Apr 29 09:23 vnn_pre_process.c*
-rwxr-xr-x 1 khadas khadas 1294 Apr 29 09:23 vnn_pre_process.h*

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.

1
khadas@Khadas:~/Programs/inceptionv3$ cp makefile.linux makefile

My makefile is modified as follows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
khadas@Khadas:~/Programs/inceptionv3$ cat makefile
CFLAGS += -I${ACUITY_OVXLIB_DEV}/include

################################################################################
# Supply necessary libraries.
LIBS += -L/lib -lOpenVX -lOpenVXU -lCLC -lVSC -lGAL -lovxlib -lm -ljpeg

#############################################################################
# Macros.
PROGRAM = 1
TARGET_NAME = inceptionv3
CUR_SOURCE = ${wildcard *.c}
#############################################################################
# Objects.
OBJECTS = ${patsubst %.c, $(OBJ_DIR)/%.o, $(CUR_SOURCE)}

# installation directory
INSTALL_DIR := ./

################################################################################
# Include the common makefile.

include ${VIVANTE_SDK}/common.target

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.

1
2
3
4
5
6
7
8
9
10
khadas@Khadas:~/Programs/inceptionv3$ make
cc -c -I/opt/acuity-ovxlib-dev/include -o bin_r/vnn_pre_process.o vnn_pre_process.c
cc -c -I/opt/acuity-ovxlib-dev/include -o bin_r/vnn_inceptionv3.o vnn_inceptionv3.c
cc -c -I/opt/acuity-ovxlib-dev/include -o bin_r/main.o main.c
cc -c -I/opt/acuity-ovxlib-dev/include -o bin_r/vnn_post_process.o vnn_post_process.c
cc -Wl,-rpath-link /opt/vivante_sdk/drivers bin_r/vnn_pre_process.o bin_r/vnn_inceptionv3.o bin_r/main.o bin_r/vnn_post_process.o -o bin_r/inceptionv3 -L/lib -lOpenVX -lOpenVXU -lCLC -lVSC -lGAL -lovxlib -lm -ljpeg -lrt
bin_r/inceptionv3
Usage: bin_r/inceptionv3 data_file inputs...
/opt/vivante_sdk/common.target:64: recipe for target 'bin_r/inceptionv3' failed
make: *** [bin_r/inceptionv3] Error 255

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.

1
2
3
4
5
6
7
8
9
khadas@Khadas:~/Programs/inceptionv3$ ll bin_r
total 92
drwxrwxr-x 2 khadas khadas 4096 Apr 29 09:46 ./
drwxr-xr-x 4 khadas khadas 4096 Apr 29 09:46 ../
-rwxrwxr-x 1 khadas khadas 34864 Apr 29 09:46 inceptionv3*
-rw-rw-r-- 1 khadas khadas 6864 Apr 29 09:46 main.o
-rw-rw-r-- 1 khadas khadas 5128 Apr 29 09:46 vnn_inceptionv3.o
-rw-rw-r-- 1 khadas khadas 4456 Apr 29 09:46 vnn_post_process.o
-rw-rw-r-- 1 khadas khadas 21976 Apr 29 09:46 vnn_pre_process.o

4.4.3.3 Run inceptionv3

Let's run inceptionv3 under folder bin_demo.

1
2
3
4
5
6
7
8
9
10
khadas@Khadas:~/Programs/inceptionv3$ cd bin_demo/
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ ll
total 28384
drwxr-xr-x 2 khadas khadas 4096 Apr 29 09:52 ./
drwxr-xr-x 4 khadas khadas 4096 Apr 29 09:57 ../
-rwxr-xr-x 1 khadas khadas 15981 Apr 29 09:52 dog_299x299.jpg*
-rwxr-xr-x 1 khadas khadas 88322 Apr 29 09:52 goldfish_299x299.jpg*
-rwxr-xr-x 1 khadas khadas 10479 Apr 29 09:52 imagenet_slim_labels.txt*
-rwxr-xr-x 1 khadas khadas 28807168 Apr 29 09:52 inception_v3.nb*
-rwxr-xr-x 1 khadas khadas 129568 Apr 29 09:52 inceptionv3*

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.

1
2
3
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ cp ../bin_r/inceptionv3 ./
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ ll inceptionv3
-rwxr-xr-x 1 khadas khadas 34864 Apr 29 09:58 inceptionv3*

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.

1
2
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ ll inception_v3.nb 
-rwxr-xr-x 1 khadas khadas 28807168 Apr 29 10:06 inception_v3.nb*

Finally, let's run the demo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ ./inceptionv3 ./inception_v3.nb ./dog_299x299.jpg 
D [setup_node:368]Setup node id[0] uid[4294967295] op[NBG]
D [print_tensor:136]in(0) : id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
D [print_tensor:136]out(0): id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [optimize_node:312]Backward optimize neural network
D [optimize_node:319]Forward optimize neural network
I [compute_node:261]Create vx node
Create Neural Network: 58ms or 58961us
I [vsi_nn_PrintGraph:1421]Graph:
I [vsi_nn_PrintGraph:1422]***************** Tensors ******************
D [print_tensor:146]id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [print_tensor:146]id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
I [vsi_nn_PrintGraph:1431]***************** Nodes ******************
I [vsi_nn_PrintNode:159]( NBG)node[0] [in: 1 ], [out: 0 ] [a56c0cb0]
I [vsi_nn_PrintGraph:1440]******************************************
I [vsi_nn_ConvertTensorToData:750]Create 268203 data.
Verify...
Verify Graph: 1ms or 1959us
Start run graph [1] times...
Run the 1 time: 29ms or 29038us
vxProcessGraph execution time:
Total 29ms or 29063us
Average 29.06ms or 29063.00us
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.
--- Top5 ---
208: 0.828613
209: 0.040771
223: 0.008278
268: 0.002737
185: 0.002396
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
khadas@Khadas:~/Programs/inceptionv3/bin_demo$ ./inceptionv3 ./inception_v3.nb ./goldfish_299x299.jpg 
D [setup_node:368]Setup node id[0] uid[4294967295] op[NBG]
D [print_tensor:136]in(0) : id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
D [print_tensor:136]out(0): id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [optimize_node:312]Backward optimize neural network
D [optimize_node:319]Forward optimize neural network
I [compute_node:261]Create vx node
Create Neural Network: 64ms or 64785us
I [vsi_nn_PrintGraph:1421]Graph:
I [vsi_nn_PrintGraph:1422]***************** Tensors ******************
D [print_tensor:146]id[ 0] vtl[0] const[0] shape[ 1001, 1 ] fmt[f16] qnt[NONE]
D [print_tensor:146]id[ 1] vtl[0] const[0] shape[ 3, 299, 299, 1 ] fmt[u8 ] qnt[ASM zp=137, scale=0.007292]
I [vsi_nn_PrintGraph:1431]***************** Nodes ******************
I [vsi_nn_PrintNode:159]( NBG)node[0] [in: 1 ], [out: 0 ] [6df47cb0]
I [vsi_nn_PrintGraph:1440]******************************************
I [vsi_nn_ConvertTensorToData:750]Create 268203 data.
Verify...
Verify Graph: 2ms or 2951us
Start run graph [1] times...
Run the 1 time: 28ms or 28835us
vxProcessGraph execution time:
Total 28ms or 28873us
Average 28.87ms or 28873.00us
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.
--- Top5 ---
2: 0.832520
795: 0.008316
974: 0.003586
408: 0.002302
393: 0.002016
I [vsi_nn_ConvertTensorToData:750]Create 2002 data.

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 dog_299x299.jpg goldfish_299x299.jpg
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:

Manjaro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
➜  ~ ssh khadas@192.168.1.95
khadas@192.168.1.95's password:
Welcome to Manjaro-ARM
~~Website: https://manjaro.org
~~Forum: https://forum.manjaro.org/c/manjaro-arm
~~IRC: #manjaro-arm on irc.freenode.net
~~Matrix: #manjaro-arm-public:matrix.org
Last login: Sun Apr 19 03:24:46 2020 from 192.168.1.200
[khadas@manjaro ~]$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
[khadas@manjaro ~]$ pwd
/home/khadas
[khadas@manjaro ~]$ uname -a
Linux manjaro 5.6.0-0.6 #1 SMP PREEMPT Wed Apr 1 19:25:06 +03 2020 aarch64 GNU/Linux
[khadas@manjaro ~]$ lsb_release -a
LSB Version: n/a
Distributor ID: Manjaro-ARM
Description: Manjaro ARM Linux
Release: 20.04
Codename: n/a
[khadas@manjaro ~]$ gcc --version
-bash: gcc: command not found
[khadas@manjaro ~]$ g++ --version
-bash: g++: command not found
[khadas@manjaro ~]$ sudo apt install gcc g++ automake autoconfig libtool

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for khadas:
sudo: apt: command not found
[khadas@manjaro ~]$ pamac help
Available actions:
pamac --version
pamac --help,-h [action]
pamac clean [options]
pamac checkupdates [options]
pamac update,upgrade [options]
pamac search [options] <package(s)>
pamac info [options] <package(s)>
pamac list [options] <package(s)>
pamac install [options] <package(s)>
pamac reinstall [options] <package(s)>
pamac clone [options] <package(s)>
pamac build [options] [package(s)]
pamac remove [options] [package(s)]
[khadas@manjaro ~]$

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