nvidia tk1使用记录--基本环境搭建
前言
项目最开始是在X86+Nvidia(ubuntu+opencv+cuda)平台上实现,达到了期望性能,最近考虑将其移植到嵌入式平台,特别是最近nvidia出了tegra X1,基于和我们使用的gtx960相同的架构的gpu且是64位 8核心cpu,于是开始了尝试移植过程。当前TX1才出来,购买不是那么方便,于是拿它的前一代TK1进行一个最基本的评估。下面记录了评估过程的一些操作。
tk1系统更新
拿到的tk1时,板子自带的系统版本(非内核版本)是Jetson TK1 R19.3 - June 2014,非常老了,有必要对其进行升级。当前(2016/04/11),最新的系统版本为Linux For Tegra R21.4,它的相关介绍及下载包地址在这里。系统更新有两种方法,不管是哪种方式,都需要用数据线(一端接tk1的micro usb口,一端接PC机的usb口)连接开发板与主机,然后上电的时候让设备进入recovery模式,最后在主机上启动升级。
注意:tk1开箱上电启动时,默认是在非图形界面下的,ls一下会看到目录NVIDIA-INSTALLER,cd进去,执行
sudo ./installer来进行图形化安装,然后sudo reboot重启即可进入图形界面了。默认的用户名是ubuntu,密码ubuntu。
自动更新
JetPack for L4T傻瓜式自动更新,提供图形界操作。它是由官方提供的升级包,可以说它是所有需要安装包的集合,包括最新系统,cuda,opencv,cross-develop-environment,samples等等,非常方便,缺点就是主机系统只能是ubuntu12.04或者ubuntu14.04,安装后的软件包版本可能并非期望的,比如opencv是2.4。关于这种更新方式的详细介绍请参考这里,我没有采用这种升级方式,所以不再过多描述。
手动更新
这种升级方式实际上和上面的升级方式一样,只不过它仅仅是上面升级里面的一个步骤而已,JetPack for L4T不仅仅更新系统,还会同时更新其他软件包,如cuda、opencv等等。具体升级的步骤如下:
- 下载内核及驱动包
http://developer.download.nvidia.com/embedded/L4T/r21_Release_v4.0/Tegra124_Linux_R21.4.0_armhf.tbz2; - 下载文件系统包
http://developer.download.nvidia.com/embedded/L4T/r21_Release_v4.0/Tegra_Linux_Sample-Root-Filesystem_R21.4.0_armhf.tbz2; - 构建升级包(包括了boot、kernel、fs),执行
sudo tar --numeric-owner -jxpf Tegra124_Linux_R21.4.0_armhf.tbz2解压内核及驱动包,然后cd linux_for_tegra/rootfs下,再次解压文件系统包sudo tar --numeric-owner -jxpf ../../Tegra_Linux_Sample-Root-Filesystem_R21.4.0_armhf.tbz2,然后cd ../,即返回到linux_for_tegra,执行sudo ./apply_binaries.sh构建升级包。注意,执行命令前,请先确保系统还有20G空间,如果没有,那么将14GiB改下点吧,虽然这样会导致板子上flash没充分利用,但至少能够更新系统; - 开始升级,USB端插到ubuntu PC上,小头插到TK1上,也就是耳机口旁边的口。TK1上有三个按钮,最左边的是电源,中间的是reset,最右边的是force recoverry,按住最右边的force recoverry 按钮别松手,再按一下中间的reset键,指示灯会闪一下,板子就重启进入了刷机模式。然后在ubuntu PC上,当前目录,即
linux_for_tegra目录下,执行终端命令:sudo ./flash.sh -S 14GiB jetson-tk1mmcblk0p1,这个时候ubuntu上会弹出一个设备,就是tk1了,然后就会进入刷机过程,若干小时后,最后成功了的话,会出现success字样。这时重启TK1开发板,就发现这板子已经成功被初始化了。进入ubuntu桌面环境,默认的用户名是ubuntu,密码ubuntu。
tk1 cuda安装
cuda的安装可以参考elinux的指导,这部分也没有需要特别注意的,确保cuda安装在opencv之前以及所有操作都是在tk1系统里进行的就可以了。下面还是把关键步骤给摘抄下来吧(略加修改)!
Download the .deb file for the CUDA Toolkit for L4T from http://developer.download.nvidia.com/embedded/L4T/r21_Release_v3.0/cuda-repo-l4t-r21.3-6-5-prod_6.5-42_armhf.deb
On the device, install the .deb file and the CUDA Toolkit. eg:
cd ~/Downloads
# Install the CUDA repo metadata that you downloaded manually for L4T
sudo dpkg -i cuda-repo-l4t-r21.3-6-5-prod_6.5-42_armhf.deb
# Download & install the actual CUDA Toolkit including the OpenGL toolkit from NVIDIA. (It only downloads around 15MB)
sudo apt-get update
# Install "cuda-toolkit-6-0" if you downloaded CUDA 6.0, or "cuda-toolkit-6-5" if you downloaded CUDA 6.5, etc.
sudo apt-get install cuda-toolkit-6-5
# Add yourself to the "video" group to allow access to the GPU
sudo usermod -a -G video $USER
Add the 32-bit CUDA paths to your .bashrc login script, and start using it in your current console:
echo "# Add CUDA bin & library paths:" >> ~/.bashrc
echo "export PATH=/usr/local/cuda/bin:$PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc
Verify that the CUDA Toolkit is installed on your device:
nvcc -V
tk1 opencv安装
opencv的安装可以参考elinux的指导,我这里还是对每一个步骤详细的描述下,因为这里会遇到些上面链接里没有指出的问题,另外要注意,下面所有操作都是在tk1系统里进行的。opencv的安装有两种方式:
方法一,直接采用nvidia提供的安装包。优点:简单,且同时增加了cpu neon的优化;缺点:版本不够新2.4,基于opencv-3.0.0实现的代码可能需要修改代码。操作方法如下:
- 从
http://developer.download.nvidia.com/embedded/OpenCV/L4T_21.2/libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.deb下载opencv deb包 - 执行
sudo dpkg -i libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.deb安装 - sudo apt-get update
- sudo apt-get install libopencv4tegra libopencv4tegra-dev
方法二,从源码编译。优点:能够使用最新的opencv版本代码;缺点:复杂。下面的操作步骤中包含了对OpenGL的使能,需要注意的是如果不添加-DWITH_QT=ON,那么-DWITH_OPENGL=ON将没有效果,因此如果你想开启OPENGL使能,还得先参考后面怎么安装qt环境。参考 ...
If you haven't added the "universal" repository to Ubuntu, then do it now:
sudo add-apt-repository universe
sudo apt-get update
Now you need to install many libraries:
# Some general development libraries
sudo apt-get -y install build-essential make cmake cmake-curses-gui g++
# libav video input/output development libraries
sudo apt-get -y install libavformat-dev libavutil-dev libswscale-dev
# Video4Linux camera development libraries
sudo apt-get -y install libv4l-dev
# Eigen3 math development libraries
sudo apt-get -y install libeigen3-dev
# OpenGL development libraries (to allow creating graphical windows)
sudo apt-get -y install libglew1.6-dev
# GTK development libraries (to allow creating graphical windows)
sudo apt-get -y install libgtk2.0-dev
Download the source code of OpenCV for Linux onto the device. eg: Open a web-browser to "www.opencv.org" & click on "OpenCV for Linux/Mac", or from the command-line you can run this on the device:
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
Unzip the OpenCV source code:
cd Downloads
unzip 3.1.0.zip
mv opencv-3.1.0 ~
Configure OpenCV using CMake:
cd ~/opencv-3.1.0
mkdir build
cd build
cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN="3.2" -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DWITH_OPENGL=ON -DWITH_QT=ON -DBUILD_PERF_TESTS=OFF ..
sudo make -j4 install
Finally, make sure your system searches the "/usr/local/lib" folder for libraries:
echo "# Use OpenCV and other custom-built libraries." >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" >> ~/.bashrc
source ~/.bashrc
编译FAQ
错误1
error: #error Please include the appropriate gl headers before including cuda_gl_interop.h
#error Please include the appropriate gl headers before including cuda_gl_interop.h
错误2
/home/ubuntu/build/opencv/modules/highgui/src/window_QT.cpp:3150:12: error: 'GL_PERSPECTIVE_CORRECTION_HINT' was not declared in this scope
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
可以尝试下面的解决办法:
there is a workaround, if you delete folllowing lines in /usr/local/cuda/include/cuda_gl_interop.h
#ifndef GL_VERSION
#error Please include the appropriate gl headers before including cuda_gl_interop.h
#endif
#else
then gl headers is anyway included and opencv compiles.. with some rain dancing for me)
in my case, i had to add
#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
to modules/highgui/src/window_QT.cpp and turn off TBB support and cvv module (i was building with opencv_contrib)
ref: https://github.com/Itseez/opencv/issues/5205
ref: http://code.opencv.org/issues/3411
tk1 qt安装方式
注意:下面所有操作都是在tk1系统里进行的
方法一,直接采用仓库里已经提供到安装包。优点:简单;缺点:一般不是最新的版本,而且是基于OpenES的,对于之前代码是基OpenGL编写的需要做到OpenES的移植。具体安装步骤:
sudo apt-get install build-essential qt5-default qtcreator -y
which will load Qt Creator. Once Qt Creator is installed, there is still a little setup needed.
Open Qt Creator, and go to:
Tools->Options->Build & Run->Compilers
Click the ‘Add’ button and select ‘GCC’. In the ‘Compiler path:’ text box, place the path to the gcc compiler. On a standard installation the path is: /usr/bin/gcc.
You should also check the ‘Kits’ setting, available from the ‘Kits’ tab. Selecting the Desktop (default) kit, you should see Compiler: GCC. The name GCC should match the Compiler named in the previous tab.
The installation was shown on Linux for Tegra (L4T) release 21.3. Note that no special compiler flags were set. Also, CUDA was not configured.
ref: http://jetsonhacks.com/2015/04/22/install-qt-creator-on-nvidia-jetson-tk1/
方法二,从源代码编译。优点:能够基于任意版本(比如最新的qt)编译,且可以基于OpenGL而不基于OpenES;缺点:复杂,编译时间长。详细步骤参考下面两个链接:
http://blog.csdn.net/deyili/article/details/51012106
blog.csdn.net/deyili/article/details/49868987
需要注意的是,如果遇到如下编译错误:
zlib.h:86:5: error: 'z_const' does not name a type
,那么尝试在configue的时候去掉-zlib
如果在configure的时候xcb不过,通过官方解决方法(安装xcb包http://doc.qt.io/qt-5/linux-requirements.html), 如果还解决不了,那么尝试直接修改configure,如下:
#if [ "$CFG_XKBCOMMON" != no ] && compileTest qpa/xcb "xcb" $QMAKE_CFLAGS_XCB $QMAKE_LIBS_XCB; then
if [ "$CFG_XKBCOMMON" != no ]; then
编译Qt Creator
同样给出参考链接,里面已经写的很详细了。
关于OpenGL和OpenES的Qt
This board is powerful enough to build everything on its own without any cross-compilation. Configuring and building Qt is no different than in any desktop Linux environment. One option that needs special consideration however is -opengl es2 because Qt can be built either in a GLX + OpenGL or EGL + OpenGL ES configuration.
For example, the following configures Qt to use GLX and OpenGL:
configure -release -nomake examples -nomake tests
while adding -opengl es2 requests the usage of EGL and OpenGL ES:
configure -release -opengl es2 -nomake examples -nomake tests
If you are planning to run applications relying on modern, non-ES OpenGL features, or use CUDA, then go for the first. If you however have some existing code from the mobile or embedded world relying on EGL or OpenGL ES then it may be useful to go for #2.
The default platform plugin will be xcb, so running Qt apps without specifying the platform plugin will work just fine. This is the exact same plugin that is used on any ordinary X11-based Linux desktop system.
http://blog.qt.io/blog/2015/03/03/qt-weekly-28-qt-and-cuda-on-the-jetson-tk1/
另外一个问题(在iss上出现过的视频断层问题tearing,应该可以通过该方法解决)
Vsync gotchas
Once the build is done, you will most likely run some OpenGL-based Qt apps. And then comes the first surprise: applications are not synchronized to the vertical refresh rate of the screen.
When running for instance the example from qtbase/examples/opengl/qopenglwindow, we expect a nice and smooth 60 FPS animation with the rendering thread throttled appropriately. This unfortunately isn’t the case. Unless the application is fullscreen. Therefore many apps will want to replace calls like show() or showMaximized() with showFullScreen(). This way the thread is throttled as expected.
A further surprise may come in QWidget-based applications when opening a popup or a dialog. Unfortunately this also disables synchronization, even though the main window still covers the entire screen. In general we can conclude that the standard embedded recommendation of sticking to a single fullscreen window is very valid for this board too, even when using xcb, although for completely different reasons.
http://blog.qt.io/blog/2015/03/03/qt-weekly-28-qt-and-cuda-on-the-jetson-tk1/
cuda于Qt的结合
blog.qt.io/blog/2015/03/03/qt-weekly-28-qt-and-cuda-on-the-jetson-tk1/
FAQ
opencv error: the function/feature is not implemented
http://answers.opencv.org/question/84639/opencv-error-the-functionfeature-is-not-implemented/
/usr/include/qt4/QtOpenGL/qgl.h:85:17: error: 'GLdouble' has a previous declaration as 'typedef GLfloat GLdouble'
http://answers.ros.org/question/179989/rgbdslam_v2-error-with-make/
总结
评估过程可以说非常的顺利,一周内将整个项目全部移植了过来,而且基本没有代码改动_!!!!经过测试,我们的拼接算法单路能够带到65帧,2路能够代码35帧,3路没测试,因为tk1只有2G内存,系统本身用了将近700MB,而我们程序2路的时候用了1000多M,只剩50多M了。总的来说,对于移植到TX1上,心里更加有底了…………
参考
完!
2016年5月
nvidia tk1使用记录--基本环境搭建的更多相关文章
- nvidia tx1使用记录--基本环境搭建
前言 之前有专门写过一篇nvidia tk1使用记录--基本环境搭建,本以为自己有过tk1的经验后,在tx1上搭建和它一样的环境会轻车熟路,结果却是在nvidia tx1上花的时间居然比tk1还多.我 ...
- 【golang学习记录】环境搭建
[golang学习记录]环境搭建 一. 概述 本文是[golang学习记录]系列文章的第一篇,安装Go语言及搭建Go语言开发环境,接下来将详细记录自己学习 go 语言的过程,一方面是为了巩固自己学到的 ...
- 开启我的Android之旅-----记录Android环境搭建遇到的问题
在现在这个离不开手机的时代,对于手机APP的开发也是一个很大的市场,所以自己也想去探一探手机APP开发,在我们进行Android开发的第一步就是搭建环境,具体怎么搭建我就不说,这里记录一下在搭建环境的 ...
- 1、大型项目的接口自动化实践记录--robotframework环境搭建
因为人力.团队技术问题,选用robotframework来做自动化,首先说下环境搭建 齐涛道长的入门教程非常棒:http://blog.csdn.net/tulituqi/article/detail ...
- 自己记录java环境搭建之-maven
简述: 现需要在Eclipse中配置Maven插件,同时安装maven应用,配置Maven环境变量,建立Maven管理的工程,并用Maven导入Gson包, 编写简易Json输出程序 步骤: 1. 首 ...
- QT学习记录之环境搭建
作者:朱金灿 来源:http://blog.csdn.net/clever101 1. 安装qt-win-opensource-4.8.5-vs2008.exe(对应的IDE是VS2008),安装路径 ...
- Springboot学习记录1--概念介绍以及环境搭建
摘要:springboot学习记录,环境搭建: 官方文档地址:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/ht ...
- 深度学习环境搭建:window10+CUDA10.0+CUDNN+pytorch1.2.0
去年底入手一台联想Y7000P,配置了Nvidia GeForce GTX 1660 Ti GPU,GPU内存6G,但是因为有GPU服务器,所以一直没有在这台笔记本上跑过模型,如今经过一番折腾,终于在 ...
- Windebug双机调试环境搭建
Windebug双机调试环境搭建 开始进行内核编程/驱动编程的调试工作是非常烦人的,由于程序运行与内核层不受操作系统的管控,所以容易引起主机蓝屏和崩溃是常有的事.这也就使得内核程序的调试成了一大 ...
随机推荐
- [剑指Offer] 49.把字符串转换成整数
题目描述 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数. 数值为0或者字符串不是一个合法的数值则返回0 [思路]考虑所有特殊情况 1.数字前面有空格,如s=" 12 ...
- Ajax在jQuery中的应用(加载异步数据、请求服务器数据)
加载异步数据 jQuery中的load()方法 load(url,[data],[callback]) url:被加载的页面地址 [data]:可选项表示发送到服务器的数据,其格式为 key/valu ...
- WPF对某控件添加右键属性
代码创建右键属性 ContextMenu cm = new ContextMenu(); MenuItem mi = new MenuItem(); mi.Header = "打开此文件所有 ...
- RT-thread内核之事件
一.事件控制块:在include/rtdef.h中 #ifdef RT_USING_EVENT /** * flag defintions in event */ #define RT_EVENT_F ...
- 【bzoj5085】最大 二分+暴力
题目描述 给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形的价值. 输入 第一行两个数n,m,接下来n行每行m个数,用来描述矩形 n, m ≤ 1 ...
- 【bzoj4417】[Shoi2013]超级跳马 矩阵乘法
题目描述 现有一个n行m列的棋盘,一只马欲从棋盘的左上角跳到右下角.每一步它向右跳奇数列,且跳到本行或相邻行.跳越期间,马不能离开棋盘.例如,当n = 3, m = 10时,下图是一种可行的跳法. ...
- 【bzoj1010】[HNOI2008]玩具装箱toy 斜率优化dp
题目描述 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具, ...
- Go语言【第四篇】:Go运算符
Go语言运算符 运算符用于在程序运行时执行数据或逻辑运算,Go语言内置的运算符有: 算数运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 其他运算符 算数运算符 下表列出了所有Go语言的算数运算符 ...
- linux文件服务器:samba服务器
windows上,需要和linux虚拟机进行方便的文件交互,总结一下遇到的问题. 1.samba简介 windows和windows之间共享文件可以用“网上邻居”,linux和linux间共享文件用 ...
- Socket网络编程实例1
Socket: 对所有上层协议(TCP/IP,UDP等)的底层封装. 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 建立网络通信连接至少要一对端口号(so ...