工控网首页
>

应用设计

>

NXP iMX8平台上使用imx-gpu-sdk开发

NXP iMX8平台上使用imx-gpu-sdk开发

By Toradex胡珊逢

Apalis iMX计算机模块采用了 NXP 的 i.MX 8 QuadMax 处理器。该处理器具有两个 Vivante GC7000/XSVX 单元,能够支持 OpenCLOpenVXOpenGL ES 。本文将介绍如何使用 NXP 提供的 imx-gpu-sdk 编译能够在 Apalis iMX运行的 OpenCL 和 OpenCV 应用。

 

Toradex 的计算机模块所安装的 Linux BSP 采用 Yocto Project 编译。为了编译和运行 OpenCL 和 OpenCV 应用,首先需要重新编译 BSP 和 SDK,以添加相关库文件、头文件等。在 Yocto Project 的编译目录中修改build/conf/local.conf 文件,添加如下内容:

------------------------------------

IMAGE_INSTALL_append = " imx-gpu-viv imx-gpu-sdk fmt python3 python3-pip \

opencv"

PACKAGECONFIG_append_mx8qm = " opencl"

TOOLCHAIN_TARGET_TASK_append = " imx-gpu-viv imx-gpu-sdk stb fmt opencv"

------------------------------------

 

然后运行下面两个命令,分别生成安装镜像和 SDK 工具。

------------------------------------

bitbake tdx-reference-multimedia-image

bitbake tdx-reference-multimedia-image -c populate_sdk

------------------------------------

 

使用 Toradex Easy Installer 安装生成的镜像。复制生成的 SDK 安装文件 tdx-xwayland-glibc-x86_64-Reference-Multimedia-Image-aarch64-apalis-imx8-toolchain-5.7.0.sh 到 Linux 电脑,如 Ubuntu 20.04。这里安装到 /opt/SDK/ 路径,当然也可以换成其他合适的目录。由于 SDK 中缺少了 stb 库相关的头文件,因此,需要将 Yocto Project 编译路的 build/tmp/sysroots-components/aarch64/stb/usr/include/ 里面所有 .h 头文件复制到 SDK 的安装路径 sysroots/aarch64-tdx-linux/usr/include/stb/ 下面。同时,在 environment-setup-aarch64-tdx-linux 文件里添加 CPATH 变量。

------------------------------------

export ARCH=arm64

export CROSS_COMPILE=aarch64-tdx-linux-

export CPATH=/opt/SDK/sysroots/aarch64-tdx-linux/usr/include/stb

------------------------------------

 

接下来下载 OpenCL 和 OpenCV 应用代码。

------------------------------------

git clone -b master https://github.com/nxpmicro/gtec-demo-framework.git

------------------------------------

 

安装编译代码所需的其他工具,python 版本需要 3.6 以及以上。

------------------------------------

apt install build-essential ninja-build cmake

------------------------------------

 

编译 OpenCL 应用。其中 ROOTFS 的路径需要结合 SDK 的实际安装位置而修改,这里为 /opt/SDK/sysroots/aarch64-tdx-linux

------------------------------------

source /opt/SDK/environment-setup-aarch64-tdx-linux

cd /opt/SDK/gtec-demo-framework

export FSL_PLATFORM_NAME=Yocto

export ROOTFS=/opt/SDK/sysroots/aarch64-tdx-linux

source prepare.sh

cd DemoApps/OpenCL/FastFourierTransform

FslBuild.py

------------------------------------

 

编译 OpenCV 应用。由于 Apalis iMX8 的图形框架采用 wayland,因此在编译时添加 --Variants [WindowSystem=wayland] 参数。

------------------------------------

source /opt/SDK/environment-setup-aarch64-tdx-linux

cd /opt/SDK/gtec-demo-framework

export FSL_PLATFORM_NAME=Yocto

export ROOTFS=/opt/SDK/sysroots/aarch64-tdx-linux

source prepare.sh

cd DemoApps/OpenCV/OpenCV101

FslBuild.py --Variants [WindowSystem=wayland]

------------------------------------

 

编译完成后在 gtec-demo-framework 文件夹的 build 目录生成了对应的项目文件。

------------------------------------

root@3b368d78738f:/opt/SDK/gtec-demo-framework/build/Yocto/Ninja/release/DemoApps# tree -L 3

.

|-- OpenCL

|   `-- FastFourierTransform

|       |-- CMakeFiles

|       |-- Content

|       |-- OpenCL.FastFourierTransform

|       |-- OpenCL.FastFourierTransformConfigVersion.cmake

|       |-- cmake_install.cmake

|       `-- content_deps.txt

`-- OpenCV

    `-- OpenCV101

        |-- CMakeFiles

        |-- Content

        |-- OpenCV.OpenCV101

        |-- OpenCV.OpenCV101ConfigVersion.cmake

        |-- cmake_install.cmake

        `-- content_deps.txt

------------------------------------

 

将 gtec-demo-framework/build/Yocto/Ninja/release/DemoApps 下的两个文件夹复制到 Apalis iMX8 上即可运行。

------------------------------------

root@apalis-imx8:~/DemoApps/OpenCV/OpenCV101# ./OpenCV.OpenCV101

 Simple Linear Blender

-----------------------

libpng warning: iCCP: known incorrect sRGB profile

------------------------------------

 

OpenCV 应用在显示器上可以看到如下内容。

NXP iMX8平台上使用imx-gpu-sdk开发3877.png 

 

OpenCL FastFourierTransform 显示在 GPU 上运行状况。

------------------------------------

root@apalis-imx8-06852111:~/DemoApps/OpenCL/FastFourierTransform# ./OpenCL.FastFourierTransform

Block size: 16

Length: 16

Print result: yes

Initializing device(s)...

Get the Device info and select Device...

# of Devices Available = 1

# of Compute Units = 2

# compute units = 2

Getting device id...

……

Kernel execution time on GPU (kernel 0):   0.000146 seconds

Kernel execution time on GPU (kernel 1): 7.70000e-05 seconds

Kernel execution time on GPU (kernel 2): 7.80000e-05 seconds

Kernel execution time on GPU (kernel 3): 8.40000e-05 seconds

Total Kernel execution time on GPU:   0.000385 seconds

Successful.

------------------------------------

 

更多关于 OpenCLOpenCV 等应用开发的内容可以参考 gtec-demo-framework 的网页说明,从而开发用户自己的应用。

审核编辑(
王静
)
投诉建议

提交

查看更多评论
其他资讯

查看更多

在 Linux 系统上 Docker 容器的性能影响

上游优先 - Toradex 采用主线内核支持

NXP iMX8M Plus M7核心FreeRTOS开发

嵌入式Linux上使用Ramoops

使用容器编译Yocto镜像