Difference between revisions of "NPU"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
 
(updated by API)
Line 1: Line 1:
[[CPU/zh|查看中文]]
+
[[NPU/zh|查看中文]]
  
==RK3399==
+
==RK3588==
===查看cpu0-3 支持的频率===
+
===install rknpu===
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
+
git clone https://github.com/rockchip-linux/rknpu2.git
 +
cd rknpu2
 +
sudo cp ./runtime/RK3588/Linux/librknn_api/aarch64/* /usr/lib
 +
sudo cp ./runtime/RK3588/Linux/rknn_server/aarch64/usr/bin/* /usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
===锁定cpu0-3 的最高频率为816 mhz===
+
===install rknn_toolkit===
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
echo 816000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
+
sudo apt-get install -y python3-dev python3-numpy python3-opencv
 +
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
 +
pip3 install ./rknn-toolkit2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.5.0-cp39-cp39-linux_aarch64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===查看cpu4-5 支持的频率===
+
===run test===
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_available_frequencies
+
$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite
</syntaxhighlight>
+
$ python3 test.py
===锁定cpu4-5 的最高频率为1008 mhz===
+
--> Load RKNN model
<syntaxhighlight lang="text">
+
done
echo 1008000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq
+
--> Init runtime environment
</syntaxhighlight>
+
I RKNN: [11:33:44.186] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
 +
I RKNN: [11:33:44.186] RKNN Driver Information: version: 0.8.8
 +
I RKNN: [11:33:44.186] RKNN Model Information: version: 4, toolkit version: 1.5.0+1fa95b5c(compiler version: 1.5.0 (e6fe0c678@2023-05-25T16:15:03)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_shape
 +
done
 +
--> Running model
 +
resnet18
 +
-----TOP 5-----
 +
[812]: 0.9996760487556458
 +
[404]: 0.00024927023332566023
 +
[657]: 1.449744013370946e-05
 +
[466 833]: 9.023910024552606e-06
 +
[466 833]: 9.023910024552606e-06
  
===查看当前频率===
 
<syntaxhighlight lang="text">
 
cat /sys/devices/system/cpu/cpu[04]/cpufreq/cpuinfo_cur_freq
 
</syntaxhighlight>
 
===查看cpu4-5可用频率===
 
<syntaxhighlight lang="text">
 
/sys/devices/system/cpu/cpu4/cpufreq# cat scaling_available_frequencies
 
408000 600000 816000 1008000 1200000 1416000 1608000 1800000
 
</syntaxhighlight>
 
 
==S5P4418/S5P6818==
 
===Setting CPU's Max Clock===
 
====Method 1====
 
The following command is used to temporarily limit the maximum CPU frequency to 1GHz:
 
echo 1000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
 
 
====Method 2====
 
Modify the kernel source code:
 
<syntaxhighlight lang="text">
 
arch/arm/plat-s5p4418/nanopi2/device.c
 
</syntaxhighlight>
 
 
Delete the unwanted frequencies in the following array:
 
<syntaxhighlight lang="text">
 
static unsigned long dfs_freq_table[][2] = {
 
    { 1400000, 1200000, },
 
    { 1200000, 1120000, },
 
    { 1000000, 1040000, },
 
    {  800000, 1000000, },
 
    {  700000,  940000, },
 
    {  600000,  940000, },
 
    {  500000,  940000, },
 
    {  400000,  940000, },
 
};
 
</syntaxhighlight>
 
 
===CPU thermal===
 
Get CPU's working temperature by reading the following files:<br />
 
S5P4418/S5P6818/H3/H5/A64:<br />
 
/sys/class/thermal/thermal_zone0/temp<br />
 
RK3399, get CPU's working temperature and clock:<br />
 
<syntaxhighlight lang="text">
 
while true; do
 
t1=`cat /sys/class/thermal/thermal_zone0/temp`
 
t2=`cat /sys/class/thermal/thermal_zone1/temp`
 
f1=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq`
 
f2=`cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq`
 
echo "$t1 $t2  $f1 $f2"
 
sleep 1
 
#cat /sys/class/thermal/thermal_zone[01]/temp
 
#cat /sys/devices/system/cpu/cpu[04]/cpufreq/cpuinfo_cur_freq
 
 
done
 
done
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==H3==
 
===CPU DVFS===
 
====Linux-4.14====
 
All H3 based boards have the same DVFS setting and the setting is in the "arch/arm/boot/dts/sun8i-h3-nanopi.dtsi" file:
 
<syntaxhighlight lang="text">
 
&cpu0 {
 
operating-points = <
 
1008000 1300000
 
816000 1100000
 
624000 1100000
 
480000 1100000
 
312000 1100000
 
240000 1100000
 
120000 1100000
 
>;
 
#cooling-cells = <2>;
 
cooling-min-level = <0>;
 
cooling-max-level = <6>;
 
cpu0-supply = <&vdd_cpux>;
 
};
 
 
&cpu_thermal {
 
trips {
 
cpu_warm: cpu_warm {
 
temperature = <65000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_hot: cpu_hot {
 
temperature = <75000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_very_hot: cpu_very_hot {
 
temperature = <90000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_crit: cpu_crit {
 
temperature = <105000>;
 
hysteresis = <2000>;
 
type = "critical";
 
};
 
};
 
 
cooling-maps {
 
cpu_warm_limit_cpu {
 
trip = <&cpu_warm>;
 
cooling-device = <&cpu0 THERMAL_NO_LIMIT 1>;
 
};
 
cpu_hot_limit_cpu {
 
trip = <&cpu_hot>;
 
cooling-device = <&cpu0 2 3>;
 
};
 
cpu_very_hot_limit_cpu {
 
trip = <&cpu_very_hot>;
 
cooling-device = <&cpu0 5 THERMAL_NO_LIMIT>;
 
};
 
};
 
};
 
</syntaxhighlight>
 
 
===CPU ID===
 
====Linux-4.14====
 
{{FriendlyCoreAllwinner-CHIPID}}
 
 
===CPU thermal===
 
====Linux-4.14====
 
<syntaxhighlight lang="text">
 
$ cat /sys/class/thermal/thermal_zone0/temp
 
30489
 
</syntaxhighlight>
 
The reading means the working temperature is 30.489 degrees Celsius.
 
 
==H5==
 
===CPU DVFS===
 
====Linux-4.14====
 
For H5 based boards different boards have different DVFS settings.
 
Let's take the NanoPi NEO2 as an example the setting is in the "arch/arm64/boot/dts/allwinner/sun50i-h5-nanopi-neo2.dts" file:
 
<syntaxhighlight lang="text">
 
&cpu0 {
 
operating-points = <
 
1008000 1100000
 
816000 1100000
 
624000 1100000
 
480000 1100000
 
312000 1100000
 
240000 1100000
 
120000 1100000
 
>;
 
#cooling-cells = <2>;
 
cooling-min-level = <0>;
 
cooling-max-level = <6>;
 
cpu0-supply = <&vdd_cpux>;
 
};
 
 
&cpu_thermal {
 
trips {
 
cpu_warm: cpu_warm {
 
temperature = <65000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_hot: cpu_hot {
 
temperature = <75000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_very_hot: cpu_very_hot {
 
temperature = <90000>;
 
hysteresis = <2000>;
 
type = "passive";
 
};
 
cpu_crit: cpu_crit {
 
temperature = <105000>;
 
hysteresis = <2000>;
 
type = "critical";
 
};
 
};
 
 
cooling-maps {
 
cpu_warm_limit_cpu {
 
trip = <&cpu_warm>;
 
cooling-device = <&cpu0 THERMAL_NO_LIMIT 1>;
 
};
 
cpu_hot_limit_cpu {
 
trip = <&cpu_hot>;
 
cooling-device = <&cpu0 2 3>;
 
};
 
cpu_very_hot_limit_cpu {
 
trip = <&cpu_very_hot>;
 
cooling-device = <&cpu0 5 THERMAL_NO_LIMIT>;
 
};
 
};
 
};
 
</syntaxhighlight>
 
 
===CPU ID===
 
====Linux-4.14====
 
{{FriendlyCoreAllwinner-CHIPID}}
 
 
===CPU thermal===
 
====Linux-4.14====
 
<syntaxhighlight lang="text">
 
$ cat /sys/class/thermal/thermal_zone0/temp
 
30489
 
</syntaxhighlight>
 
The reading means the working temperature is 30.489 degrees Celsius.
 

Revision as of 07:19, 8 January 2024

查看中文

1 RK3588

1.1 install rknpu

git clone https://github.com/rockchip-linux/rknpu2.git
cd rknpu2
sudo cp ./runtime/RK3588/Linux/librknn_api/aarch64/* /usr/lib
sudo cp ./runtime/RK3588/Linux/rknn_server/aarch64/usr/bin/* /usr/bin/

1.2 install rknn_toolkit

sudo apt-get install -y python3-dev python3-numpy python3-opencv
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
pip3 install ./rknn-toolkit2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.5.0-cp39-cp39-linux_aarch64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/

1.3 run test

$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite
$ python3 test.py
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [11:33:44.186] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
I RKNN: [11:33:44.186] RKNN Driver Information: version: 0.8.8
I RKNN: [11:33:44.186] RKNN Model Information: version: 4, toolkit version: 1.5.0+1fa95b5c(compiler version: 1.5.0 (e6fe0c678@2023-05-25T16:15:03)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_shape
done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9996760487556458
[404]: 0.00024927023332566023
[657]: 1.449744013370946e-05
[466 833]: 9.023910024552606e-06
[466 833]: 9.023910024552606e-06
 
done