当前位置: 首页 > news >正文

Ubuntu 20.04 源码编译Paddle2.2.2

做研发,总是要不停装新机器和新系统。今天尝试了一下编译Paddle2.2.2。

先说结果:

(1)Ubuntu20.04 + Python3.8.10 + gcc-8

(2)cuda和cudnn的版本分别是:
cuda_11.4.3_470.82.01_linux.run
cudnn-11.4-linux-x64-v8.2.4.15.tgz

下面介绍过程和碰到的问题,首先参考Paddle官网的说明,

源码编译 — Paddle-Inference documentation

找到那段“基于 Ubuntu 18.04”的说明,我们一步步根据这个说明来编译安装。

一:环境准备

首先是安装必须的工具,官网上是说

sudo apt-get install gcc g++ make cmake git vim unrar python3 python3-dev python3-pip swig wget patchelf libopencv-dev
pip3 install numpy protobuf wheel setuptools

我的系统里已经有python3.8.10这个默认的版本了,就没有再安装python3这些。opencv我昨天已经编译安装了opencv4.5.5这个版本的,所以也不需要重复安装,

Ubuntu20.04编译安装Opencv4.5.5_高精度计算机视觉的博客-CSDN博客

如果你没有自己编译安装opencv,那么就可以在这里选择安装libopencv-dev。patchefl这些都是必须的,没装的话无法编译通过,不嫌麻烦的话也可以在编译报错了之后再一步步安装。

cuda和cudnn的版本分别是:
cuda_11.4.3_470.82.01_linux.run
cudnn-11.4-linux-x64-v8.2.4.15.tgz

官方有这么一段话,

编译飞桨过程中可能会打开很多文件,Ubuntu 18.04 默认设置最多同时打开的文件数是1024(参见 ulimit -a),需要更改这个设定值。

在 /etc/security/limits.conf 文件中添加两行。

* hard noopen 102400
* soft noopen 102400

重启计算机,重启后执行以下指令,请将${user}切换成当前用户名。

su ${user}
ulimit -n 102400

 我都照做了。值得说明的是,如果你碰到下面这样的错误,

/usr/bin/ld: 找不到 ../operators/math/libsampler.a: Too many open files
/usr/bin/ld: 找不到 ../framework/libgenerator.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libgru_compute.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libmaxouting.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libpooling.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libsequence2batch.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libsequence_pooling.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libsoftmax.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libbeam_search.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libfc.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/liblapack_function.a: Too many open files
/usr/bin/ld: 找不到 ../platform/dynload/libdynload_lapack.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libmatrix_bit_code.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libunpooling.a: Too many open files
/usr/bin/ld: 找不到 ../operators/math/libvol2col.a: Too many open files
....

通常是因为你的"ulimit -n 102400"设置没起作用(比如你重启了机器,打开了新的终端等),所以重新设置一下就好了。我实际用的指令是

ulimit -n 20480

二:编译命令

使用 Git 将飞桨代码克隆到本地,并进入目录,切换到稳定版本(git tag显示的标签名,如 release/2.0)。 飞桨使用 develop 分支进行最新特性的开发,使用 release 分支发布稳定版本。在 GitHub 的 Releases 选项卡中,可以看到飞桨版本的发布记录。

git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
git checkout release/2.2

下面以 GPU 版本为例说明编译命令。其他环境可以参考“CMake编译选项表”修改对应的cmake选项。比如,若编译 CPU 版本,请将 WITH_GPU 设置为 OFF。

# 创建并进入 build 目录
~$ mkdir build_cuda && cd build_cuda
# 执行cmake指令
~$ cmake .. -DPY_VERSION=3 \
        -DWITH_TESTING=OFF \
        -DWITH_MKL=ON \
        -DWITH_GPU=ON \
        -DON_INFER=ON \
        ..
~$ nproc
12 

使用make编译

make -j12

编译成功后可在dist目录找到生成的.whl包

比如我的编译生成包在这里,
~/ocr/01/Paddle/build_cuda/python/dist/paddlepaddle_gpu-0.0.0-cp38-cp38-linux_x86_64.whl

官方给出的版本是(前面官方明明说是GPU版本,可看上去很像CPU版本),
pip3 install python/dist/paddlepaddle-2.0.0-cp38-cp38-linux_x86_64.whl

不清楚为什么会有这样的版本区别。

预测库编译

make inference_lib_dist -j4

cmake编译环境表

以下介绍的编译方法都是通用步骤,根据环境对应修改cmake选项即可。

:编译时碰到的问题

系统默认的是gcc-9.4.0,编译时碰到的问题我列举在下面,

(1)file failed to open for reading (No such file or directory)  /home/mc/ocr/Paddle/NCCL_INCLUDE_DIR-NOTFOUND/nccl.h

参考:
https://github.com/PaddlePaddle/Paddle/pull/8540
https://github.com/PaddlePaddle/Paddle/issues/5035
https://docs.nvidia.com/deeplearning/nccl/install-guide/index.html

解决办法,安装libnccl

In the following commands, please replace <architecture> with your CPU architecture: x86_64, ppc64le, or sbsa, and replace <distro> with the Ubuntu version, for example ubuntu1604, ubuntu1804, or ubuntu2004.

说明:<distro>=ubunt2004<architecture>=x86_64

(1). Install the keys.
When installing using the network repo for Ubuntu 20.04/18.04:
---> sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/<distro>/<architecture>/7fa2af80.pub

(2). Install the repository.
or the local NCCL repository:
---> sudo dpkg -i nccl-repo-<version>.deb
For the network repository:
---> sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/<distro>/<architecture>/ /"

(3). Update the APT database:
sudo apt update

(4). Install the libnccl2 package with APT. Additionally, if you need to compile applications with NCCL, you can install the libnccl-dev package as well:
Note: If you are using the network repository, the following command will upgrade CUDA to the latest version.
---> sudo apt install libnccl2 libnccl-dev
If you prefer to keep an older version of CUDA, specify a specific version, for example:
---> sudo apt install libnccl2=2.4.8-1+cuda11.4 libnccl-dev=2.4.8-1+cuda11.4
---> sudo apt install libnccl2=2.4.8-1+cuda10.0 libnccl-dev=2.4.8-1+cuda10.0
Refer to the download page for exact package versions.

https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/libnccl2_2.11.4-1+cuda11.4_amd64.deb

https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/libnccl-dev_2.11.4-1+cuda11.4_amd64.deb

具体有哪些包你可以直接到nvidia的官网上去查,找到合适你的cuda版本的那个包就可以了。

(2)Could NOT find PY_google.protobuf (missing: PY_GOOGLE.PROTOBUF) 

-- Could NOT find PY_google.protobuf (missing: PY_GOOGLE.PROTOBUF) 
CMake Error at cmake/python_module.cmake:27 (message):
  python module google.protobuf is not found
Call Stack (most recent call first):
  cmake/external/python.cmake:71 (find_python_module)
  cmake/third_party.cmake:243 (include)
  CMakeLists.txt:334 (include)

这是一个小问题,主要是我的系统上有多个版本的python,关闭掉那些不用的版本就可以了,比如,使用anaconda的话,就

~$ conda deactivate

(3)error: moving a local object in a return statement prevents copy elision [-Werror=pessimizing-move]

/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h:54:23: note: remove 'std::move' call
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h: In instantiation of 'std::string paddle::string::format_string(const char*, ARGS&& ...) [with ARGS = {const char*}; std::string =
std::__cxx11::basic_string<char>]':
/opt/Paddle-1.8.3/paddle/fluid/framework/io/fs.cc:115:71:   required from here
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h:54:23: error: moving a local object in a return statement prevents copy elision [-Werror=pessimizing-move]
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h:54:23: note: remove 'std::move' call
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h: In instantiation of 'std::string paddle::string::format_string(const char*, ARGS&& ...) [with ARGS = {const char*, const char*, co
nst char*}; std::string = std::__cxx11::basic_string<char>]':
/opt/Paddle-1.8.3/paddle/fluid/framework/io/fs.cc:345:78:   required from here
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h:54:23: error: moving a local object in a return statement prevents copy elision [-Werror=pessimizing-move]
/opt/Paddle-1.8.3/paddle/fluid/string/string_helper.h:54:23: note: remove 'std::move' call
[  5%] Built target data_feed_proto

说明,这个问题和后面那个一样,是由编译器引起的,所以如果换编译器的话,下面的信息就不用理会。

如果只是针对这个问题,解决办法请参考这里,

std::move报错 · Issue #26878 · PaddlePaddle/Paddle · GitHub

我使用的这个指令,

find SRCROOT -type f -name CMakeLists.txt -exec sed -i -e '$aset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pessimizing-move")' {} \;

 (4)avx512fintrin.h(9146): error: identifier "__builtin_ia32_rndscaless_round" is undefined

[ 10%] Building CXX object paddle/fluid/operators/math/CMakeFiles/pooling.dir/pooling.cc.o
/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512fintrin.h(9146): error: identifier "__builtin_ia32_rndscaless_round" is undefined

/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512fintrin.h(9155): error: identifier "__builtin_ia32_rndscalesd_round" is undefined

/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512fintrin.h(14797): error: identifier "__builtin_ia32_rndscaless_round" is undefined

/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512fintrin.h(14806): error: identifier "__builtin_ia32_rndscalesd_round" is undefined

/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512dqintrin.h(1365): error: identifier "__builtin_ia32_fpclassss" is undefined

/usr/lib/gcc/x86_64-linux-gnu/9/include/avx512dqintrin.h(1372): error: identifier "__builtin_ia32_fpclasssd" is undefined

 说明:这个问题是直接导致我放弃gcc-9.4.0的主要原因。因为这些builtin函数我们无法自己定义,也不能在编译器外找到他们,加上我对编译器并不了解,所以也没敢去修改源码,最后直接换成了gcc-8.4.0才编译成功。

如何更换gcc编译版本请参考这里,

Linux中如何安装特定的gcc版本_高精度计算机视觉的博客-CSDN博客

本文结束 

相关文章:

  • Ubuntu20.04源码编译PaddleOCR2.4
  • OpenCV导入时报错 ImportError: numpy.core.multiarray failed to import
  • OpenVINO2022.1+open_model_zoo例程的编译与使用
  • OpenCV cv::plugin::impl::DynamicLib::libraryLoad load ..opencv_core_parallel_tbb45 =>FAILED
  • OpenVINO之text_detection_demo
  • Paddle在windows10+vs2019上的源码编译(失败)
  • Tesseract-OCR试运行
  • Tesseract-OCR在Windows10(VS2019+vcpkg)平台上的编译与使用
  • Tesseract-OCR:在Windows10(VS2019+SW)平台上的编译与使用
  • Tesseract-OCR在Ubuntu20.04平台上使用
  • ROS2 Error: Could not find a package configuration file provided by “turtlebot3_msgs“
  • ROS2 + colcon build 常见的一些报错
  • ROS2进阶:安装与初体验(附choco介绍)
  • ROS2进阶:colcon的初步使用--‘colcon‘ is not recognized
  • ROS2进阶:基本指令与RVIZ2介绍
  • canvas绘制圆角头像
  • CentOS7简单部署NFS
  • CSS 专业技巧
  • java多线程
  • Java新版本的开发已正式进入轨道,版本号18.3
  • JDK 6和JDK 7中的substring()方法
  • Less 日常用法
  • MaxCompute访问TableStore(OTS) 数据
  • MQ框架的比较
  • mysql_config not found
  • React组件设计模式(一)
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 入手阿里云新服务器的部署NODE
  • 视频flv转mp4最快的几种方法(就是不用格式工厂)
  • 提升用户体验的利器——使用Vue-Occupy实现占位效果
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 小李飞刀:SQL题目刷起来!
  • [地铁译]使用SSD缓存应用数据——Moneta项目: 低成本优化的下一代EVCache ...
  • Python 之网络式编程
  • 浅谈sql中的in与not in,exists与not exists的区别
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • ​Spring Boot 分片上传文件
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • #调用传感器数据_Flink使用函数之监控传感器温度上升提醒
  • (¥1011)-(一千零一拾一元整)输出
  • (13)Hive调优——动态分区导致的小文件问题
  • (3)nginx 配置(nginx.conf)
  • (6)添加vue-cookie
  • (WSI分类)WSI分类文献小综述 2024
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (原創) 如何讓IE7按第二次Ctrl + Tab時,回到原來的索引標籤? (Web) (IE) (OS) (Windows)...
  • (转)IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
  • .NET 4.0网络开发入门之旅-- 我在“网” 中央(下)
  • .NET Core 成都线下面基会拉开序幕
  • .net framework 4.0中如何 输出 form 的name属性。
  • .NET设计模式(11):组合模式(Composite Pattern)
  • @EnableConfigurationProperties注解使用
  • @JoinTable会自动删除关联表的数据
  • [AutoSAR 存储] 汽车智能座舱的存储需求
  • [bzoj4240] 有趣的家庭菜园