哪吒 (Nezha) 开发套件
Overview
哪吒 (Nezha) 开发套件 是研扬科技针对边缘 AI 行业开发者推出的开发板,
硬件配置 | 说明 |
---|---|
处理器 | Intel® Processor N97 (formerly Alder Lake-N) |
图形 | Intel® UHD Graphics Gen12 (Xe) |
内存 | 8GB 双通道 LPDDR5 |
存储 | 64GB eMMC |
I/O | HDMI 1.40/USB 3.2 Gen 2 STACK Connector |
USB | USB 3.2 Gen 2 (Type-A) x 3 10-pin USB 2.0 x 2/UART x 1 |
安全 | 板载 TPM 2.0 |
OS | Linux: Ubuntu 22.04 LTS/Kernel 5.15 |
尺寸 | 85 x 56mm |
处理器信息:英特尔® 处理器 N97 | Intel® Processor N97
安装系统
安装 22.04.4 LTS (Jammy Jellyfish)
检查是否安装正确
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
驱动安装
为 Ubuntu 安装 Intel GPU 驱动(自动安装)
参考 Intel® Processor (Products formerly known as Alder Lake-N)
点击 `详细脚本` 查看脚本内容并复制到本地执行
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
set -e
# BKC
OS_ID="ubuntu"
OS_VERSION="22.04"
# KERNEL_PACKAGE_NAME="linux-image-generic-hwe-22.04"
# KERNEL_PACKAGE_NAME="linux-image-oem-22.04d"
KERNEL_PACKAGE_NAME="linux-image-intel-iotg"
# KERNEL_PACKAGE_NAME="linux-image-6.5.0-1009-oem"
# symbol
S_VALID="✓"
#S_INVALID="✗"
# verify current user
if [ "$EUID" -eq 0 ]; then
echo "Must not run with sudo or root user"
exit 1
fi
# resolve scripts directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
install_packages(){
local PACKAGES=("$@")
local INSTALL_REQUIRED=0
for PACKAGE in "${PACKAGES[@]}"; do
INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' "$PACKAGE" 2>/dev/null || true)
LATEST_VERSION=$(apt-cache policy "$PACKAGE" | grep Candidate | awk '{print $2}')
if [ -z "$INSTALLED_VERSION" ] || [ "$INSTALLED_VERSION" != "$LATEST_VERSION" ]; then
echo "$PACKAGE is not installed or not the latest version."
INSTALL_REQUIRED=1
fi
done
if [ $INSTALL_REQUIRED -eq 1 ]; then
sudo -E apt update
sudo -E apt install -y "${PACKAGES[@]}"
fi
}
verify_dependencies(){
echo -e "# Verifying dependencies"
DEPENDENCIES_PACKAGES=(
git
curl
wget
clinfo
)
install_packages "${DEPENDENCIES_PACKAGES[@]}"
echo "$S_VALID Dependencies installed"
}
verify_intel_gpu_package_repo(){
if [ ! -e /etc/apt/sources.list.d/intel-gpu-jammy.list ]; then
echo "Adding Intel GPU repository"
wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
sudo gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu jammy/production/2328 unified" | \
sudo tee /etc/apt/sources.list.d/intel-gpu-jammy.list
sudo -E apt update
fi
}
verify_igpu_driver(){
# TODO: verify if same iGPU driver setup can use for dGPU
echo -e "Verifying iGPU driver"
# verify compute and media runtimes
if [ -z "$(clinfo | grep 'Driver Version' | awk '{print $NF}')" ]; then
verify_intel_gpu_package_repo
IGPU_PACKAGES=(
intel-opencl-icd
intel-level-zero-gpu
level-zero
intel-media-va-driver-non-free
libmfx1
libmfxgen1
libvpl2
libegl-mesa0
libegl1-mesa
libegl1-mesa-dev
libgbm1
libgl1-mesa-dev
libgl1-mesa-dri
libglapi-mesa
libgles2-mesa-dev
libglx-mesa0
libigdgmm12
libxatracker2
mesa-va-drivers
mesa-vdpau-drivers
mesa-vulkan-drivers
vainfo
hwinfo
)
install_packages "${IGPU_PACKAGES[@]}"
if ! id -nG "$USER" | grep -q -w '\<video\>'; then
echo "Adding current user to 'video' group"
sudo usermod -aG video "$USER"
fi
if ! id -nG "$USER" | grep -q '\<render\>'; then
echo "Adding current user to 'render' group"
sudo usermod -aG render "$USER"
fi
fi
}
verify_kernel_package() {
echo -e "Verifying kernel package"
LATEST_KERNEL_VERSION=$(apt-cache madison $KERNEL_PACKAGE_NAME | awk '{print $3}' | sort -V | tail -n 1 | tr '-' '.')
CURRENT_KERNEL_VERSION_INSTALLED=$(dpkg -l | grep "^ii.*$KERNEL_PACKAGE_NAME" | awk '{print $3}' | sort -V | tail -n 1 | tr '-' '.')
LATEST_KERNEL_INSTALLED=$(dpkg -l | grep "^ii.*$KERNEL_PACKAGE_NAME" | grep -E "${LATEST_KERNEL_VERSION}[^ ]*" | awk '{print $3}' | tr '-' '.')
# extract flavour name
KERNEL_FLAVOUR=""
if [[ $KERNEL_PACKAGE_NAME == *"generic"* ]]; then
KERNEL_FLAVOUR="generic"
elif [[ $KERNEL_PACKAGE_NAME == *"oem"* ]]; then
KERNEL_FLAVOUR="oem"
elif [[ $KERNEL_PACKAGE_NAME == *"intel-iotg"* ]]; then
KERNEL_FLAVOUR="intel-iotg"
fi
if [ -z "$LATEST_KERNEL_INSTALLED" ]; then
echo "Installing latest '${KERNEL_PACKAGE_NAME}' kernel"
KERNEL_PACKAGES=("${KERNEL_PACKAGE_NAME}")
install_packages "${KERNEL_PACKAGES[@]}"
fi
if [[ ! "$LATEST_KERNEL_VERSION" == *"$CURRENT_KERNEL_VERSION_REVISION"* ]]; then
if dpkg -l | grep -q 'linux-image.*generic$' && [ "$KERNEL_FLAVOUR" != "generic" ]; then
echo "Removing generic kernel"
sudo apt remove -y --auto-remove linux-image-generic-hwe-$OS_VERSION
sudo DEBIAN_FRONTEND=noninteractive apt purge -y 'linux-image-*-generic'
elif dpkg -l | grep -q 'linux-image.*iotg$' && [ "$KERNEL_FLAVOUR" != "intel-iotg" ]; then
echo "Removing Intel IoT kernel"
sudo apt remove -y --auto-remove linux-image-intel-iotg
sudo DEBIAN_FRONTEND=noninteractive apt purge -y 'linux-image-*-iotg'
elif dpkg -l | grep -q 'linux-image.*oem$' && [ "$KERNEL_FLAVOUR" != "oem" ]; then
echo "Removing OEM kernel"
sudo DEBIAN_FRONTEND=noninteractive apt purge -y 'linux-image-*-oem'
fi
echo "Running kernel version: $CURRENT_KERNEL_VERSION_REVISION"
echo "Installed kernel version: $CURRENT_KERNEL_VERSION_INSTALLED"
echo "System reboot is required. Re-run the script after reboot"
exit 0
fi
}
verify_platform() {
echo -e "\n# Verifying platform"
CPU_MODEL=$(< /proc/cpuinfo grep -m1 "model name" | cut -d: -f2 | sed 's/^[ \t]*//')
echo "- CPU model: $CPU_MODEL"
}
verify_gpu() {
echo -e "\n# Verifying GPU"
DGPU="$(lspci | grep VGA | grep Intel -c)"
if [ "$DGPU" -ge 1 ]; then
if [ ! -e "/dev/dri" ]; then
IGPU=1
else
IGPU="$(find /dev/dri -maxdepth 1 -type c -name 'renderD128*' | wc -l)"
fi
fi
if [ -e "/dev/dri" ]; then
IGPU="$(find /dev/dri -maxdepth 1 -type c -name 'renderD128*' | wc -l)"
fi
if [ "$DGPU" -ge 2 ]; then
GPU_STAT_LABEL="- iGPU\n-dGPU (default)"
echo kern_upgrade_dgpu
else
if [ "$IGPU" -lt 1 ]; then
GPU_STAT_LABEL="- n/a"
else
GPU_STAT_LABEL="- iGPU (default)"
fi
fi
echo -e "$GPU_STAT_LABEL"
}
verify_os() {
echo -e "\n# Verifying operating system"
if [ ! -e /etc/os-release ]; then
echo "Error: /etc/os-release file not found"
exit 1
fi
CURRENT_OS_ID=$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2- | tr -d '"')
CURRENT_OS_VERSION=$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2- | tr -d '"')
if [ "$OS_ID" != "$CURRENT_OS_ID" ] || [ "$OS_VERSION" != "$CURRENT_OS_VERSION" ]; then
echo "Error: OS is not supported. Please make sure $OS_ID $OS_VERSION is installed"
exit 1
fi
echo "$S_VALID OS version: $CURRENT_OS_ID $CURRENT_OS_VERSION"
}
verify_kernel() {
echo -e "\n# Verifying kernel version"
CURRENT_KERNEL_VERSION=$(uname -r | cut -d'-' -f1)
CURRENT_KERNEL_REVISION=$(uname -r | cut -d'-' -f2)
CURRENT_KERNEL_VERSION_REVISION="$CURRENT_KERNEL_VERSION.$CURRENT_KERNEL_REVISION"
if [[ -n "$KERNEL_PACKAGE_NAME" ]]; then
verify_kernel_package
else
# TODO: option to install kernel via verify_custom_build_kernel
echo "Error: Custom build kernel not yet supported."
exit 1
fi
echo "$S_VALID Kernel version: $(uname -r)"
}
verify_drivers() {
echo -e "\n# Verifying drivers"
if [ "$DGPU" -ge 2 ]; then
# TODO: verify_dgpu_driver for supported platform
echo "Error: dGPU driver is not supported"
exit 1
else
verify_igpu_driver
fi
if [ -z "$(clinfo | grep 'Driver Version' | awk '{print $NF}')" ]; then
echo "Error: Failed to configure GPU driver"
exit 1
fi
GPU_DRIVER_VERSION="$(clinfo | grep 'Driver Version' | awk '{print $NF}')"
echo "$S_VALID Intel GPU Drivers: $GPU_DRIVER_VERSION"
}
setup() {
verify_dependencies
verify_platform
verify_gpu
verify_os
verify_kernel
verify_drivers
echo -e "\n# Status"
echo "$S_VALID Platform configured"
}
setup
安装过程中, 它可能会要求您重新启动系统。 重新启动系统并再次运行 ./setup.sh
。当您看到此消息时,安装完成:
✓ Platform configured
为 Ubuntu 安装 Intel GPU 驱动(手动安装)
IMPORTANT
安装默认的 Ubuntu 之后,不包含 Intel GPU 驱动,为了使用 OpenVINO™ GPU 插件,需要安装 Intel GPU 驱动,参考官方指南Configurations for Intel® Processor Graphics (GPU) with OpenVINO™(2024 版本)进行安装
要使用 GPU 设备进行 OpenVINO 推理,必须安装 OpenCL 运行库。如果使用的是独立 GPU(例如Arc 770),还必须确保使用受支持的 Linux 内核。
- 对于 Arc GPU, 推荐内核版本为 kernel 6.2 或更高
- 对于 Max 和 Flex GPU, 或者内核版本为 kernel 6.2 或更高的 Arc,必须根据文档(Max/Flex 或 Arc)安装
ntel-i915-dkms
和xpu-smi
内核模块
首先安装 OpenCL ,需要安装Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver及其依赖:
- Intel Graphics Memory Management Library
- Intel® Graphics Compiler for OpenCL™
- OpenCL ICD loader package
在 Ubuntu 20/24.04 LTS 安装 OpenCL 运行库如下
参考 Installation procedure on Ubuntu 22.04 (tag/24.13.29138.7) 安装 ocl-icd-libopencl1 (with the OpenCl ICD loader)
创建一个目录,用于存放下载的文件
mkdir -p ~/neo
cd ~/neo
下载全部 *.deb
包
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.16510.2/intel-igc-core_1.0.16510.2_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.16510.2/intel-igc-opencl_1.0.16510.2_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/intel-level-zero-gpu-dbgsym_1.3.29138.7_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/intel-level-zero-gpu_1.3.29138.7_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/intel-opencl-icd-dbgsym_24.13.29138.7_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/intel-opencl-icd_24.13.29138.7_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/libigdgmm12_22.3.18_amd64.deb
验证软件包的完整性
wget https://github.com/intel/compute-runtime/releases/download/24.13.29138.7/ww13.sum
sha256sum -c ww13.sum
安装 OpenCL 运行库
sudo apt install ocl-icd-libopencl1
系统级安装全部 *.deb
包
sudo dpkg -i *.deb
检查安装是否成功(好像就有这些东西,可能多了)
apt list --installed | grep intel-igc-core
apt list --installed | grep ocl-icd-libopencl1
apt list --installed | grep intel-opencl-icd
apt list --installed | grep intel-level-zero-gpu
apt list --installed | grep intel-opencl-icd
apt list --installed | grep level-zero
apt list --installed | grep intel-igc-core
apt list --installed | grep intel-igc-oepncl
检测系统中的显卡硬件
$ lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Intel Corporation Device 46d1
Subsystem: Intel Corporation Device 7270
Kernel driver in use: i915
Kernel modules: i915
Intel GPU 的监控工具是 intel-gpu-tools
sudo apt install -y intel-gpu-tools
sudo intel_gpu_top
sudo intel_gpu_time
软件安装
安装 OpenVINO™ 工具包
以下安装基于 OpenVINO 2024.1
请安装 OpenVINO Archives 版本,并根据 Installation Instructions 安装
将如下脚本添加至 ~/.bashrc
确保每次启动的时候都能加载 OpenVINO 环境变量
source /opt/intel/openvino_2024/setupvars.sh
随后安装 Python 依赖
python3 -m pip install -r $INTEL_OPENVINO_DIR/python/requirements.txt
如果使用 VScode ,在 .vscode/settings.json
中添加对 OpenVINO 的补全支持:
{
"python.analysis.extraPaths": [
"/opt/intel/openvino_2024/python",
]
}
.vscode/settings.json
配置参考 Workspace settings ,关于 Python 包的搜索路径"python.analysis.extraPaths"
参考 Python Language Server settings
Python 环境
WARNING
使用 Python 不要使用 conda ,不要使用 conda ,而应该使用 venv
创建虚拟环境,以确保相关的库链接到系统的库
如果没有安装 venv
,请安装
sudo apt install -y python3-venv
python3 -m venv <env_path>
source <env_path>/bin/activate
平台测试
OpenVINO™ 查询设备
import openvino as ov
available_devices = ov.Core().available_devices
print(" -- available devices: ", available_devices)
for device in available_devices:
print("=" * 32)
print(f' -- Device "{device}" SUPPORTED_PROPERTIES:')
supported_properties = core.get_property(device, "SUPPORTED_PROPERTIES")
indent = len(max(supported_properties, key=len))
for property_key in supported_properties:
if property_key not in ("SUPPORTED_METRICS", "SUPPORTED_CONFIG_KEYS", "SUPPORTED_PROPERTIES"):
try:
property_val = core.get_property(device, property_key)
except TypeError:
property_val = "UNSUPPORTED TYPE"
print(f"{property_key:<{indent}}: {property_val}")
Each device has several properties as seen in the last command. Some of the key properties are:
FULL_DEVICE_NAME
- The product name of the GPU and whether it is an integrated or discrete GPU (iGPU or dGPU).OPTIMIZATION_CAPABILITIES
- The model data types (INT8, FP16, FP32, etc) that are supported by this GPU.GPU_EXECUTION_UNITS_COUNT
- The execution cores available in the GPU's architecture, which is a relative measure of the GPU's processing power.RANGE_FOR_STREAMS
- The number of processing streams available on the GPU that can be used to execute parallel inference requests. When compiling a model in LATENCY or THROUGHPUT mode, OpenVINO will automatically select the best number of streams for low latency or high throughput.PERFORMANCE_HINT
- A high-level way to tune the device for a specific performance metric, such as latency or throughput, without worrying about device-specific settings.CACHE_DIR
- The directory where the model cache data is stored to speed up compilation time.
To learn more about devices and properties, see the Query Device Properties page.
OpenVINO™ GPU 插件测试
GIT_HTTP_URL=https://github.com/HenryZhuHR/deep-object-detect-track.git
git clone --depth 1 -b dev-deploy $GIT_HTTP_URL
cd deep-object-detect-track
确保 /opt/intel/openvino_2024
然后创建 Python 环境
bash scripts/create-python-env.venv.sh
激活 Python 环境
source ./.env/deep-object-detect-track.venv/bin/activate
确保包含了 OpenVINO 的权重,即如下目录结构
.
└── .cache
└── yolov5
└── yolov5s_openvino_model
├── yolov5s.bin
├── yolov5s.xml
└── yolov5s.yaml
推理测试
python3 infer.py
查看输出的设备
['AUTO', 'CPU', 'GPU']