美文网首页
GPU nvidia c++ 开发流程

GPU nvidia c++ 开发流程

作者: uriah | 来源:发表于2020-03-31 17:54 被阅读0次

    简介:

    深度学习算法使用nvidia GPU可以加速推理速度。但开发具有一定的困难。记录一下自己的安装流程
    
    1. native 开发流程

      1. 安装nvidia driver,请参考一下工程。
      https://gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07
      

      安装完成后,重启电脑, 使用 nvidia-smi 查看显卡是否安装成功

      1. 安装 cuda
      https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#package-manager-installation
      
      1. cudnn 安装
      https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#install-linux
      

      建议tar包安装

      Navigate to your <cudnnpath> directory containing the cuDNN Tar file.
      Unzip the cuDNN package.
      $ tar -xzvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
      
      Copy the following files into the CUDA Toolkit directory, and change the file permissions.
      $ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
      $ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
      $ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
      
      1. tensorrt安装(optional,如果工程有tensorrt依赖的话)
      https://docs.nvidia.com/deeplearning/sdk/tensorrt-install-guide/index.html#installing
      

      建议tar包安装

      Download the TensorRT tar file that matches the Linux distribution you are using.
      Choose where you want to install TensorRT. This tar file will install everything into a subdirectory called TensorRT-7.x.x.x.
      Unpack the tar file.
      version=”7.x.x.x”
      os=”<os>”
      arch=$(uname -m)
      cuda=”cuda-x.x”
      cudnn=”cudnn7.x”
      tar xzvf TensorRT-${version}.${os}.${arch}-gnu.${cuda}.${cudnn}.tar.gz
      Where:
      7.x.x.x is your TensorRT version
      <os> is:
      Ubuntu-16.04
      Ubuntu-18.04
      CentOS-7.6
      cuda-x.x is CUDA version 9.0, 10.0, or 10.2.
      cudnn7.x is cuDNN version 7.6.
      This directory will have sub-directories like lib, include, data, etc…
      ls TensorRT-${version}
      bin  data  doc  graphsurgeon  include  lib  python  samples  targets  TensorRT-Release-Notes.pdf  uff
      Add the absolute path to the TensorRTlib directory to the environment variable LD_LIBRARY_PATH:
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<TensorRT-${version}/lib>
      
    2. docker 开发流程

      1.安装nvidia driver,请参考上面流程

      2.安装nvidia docker,请参考

      https://github.com/NVIDIA/nvidia-docker
      

      3 . 下载 nvidia/docker相关 镜像并编译

    3 . PKG-CONFIG 方式管理cuda 和tensorrt

    1 . 请先理解pkg-config

    https://zh.wikipedia.org/wiki/Pkg-config
    

    2 . cuda.pc模板如下

    cudaroot=/usr/local/cuda
    libdir=${cudaroot}/lib64
    includedir=${cudaroot}/include
    
    Name: cuda
    Description: CUDA Driver Library
    Version: 10.0
    Libs: -L${libdir} -lcublas -lcudart -lcurand -lcudnn
    Cflags: -I${includedir}
    

    3 . tensorrt.pc 模板如下

    root=/home/gh/TensorRT-7.0.0.11
    libdir=${root}/lib
    includedir=${root}/include
    includecommondir=${root}/include
    
    Name: tensorrt
    Description: tensorrt for c++
    Version: 7.0.0.11
    Libs: -L${libdir} -lnvcaffe_parser -lnvinfer -lnvparsers -lnvinfer_plugin  -lnvonnxparser -lmyelin
    Cflags: -I${includedir} -I${includecommondir}
    
    

    4 .  模板放到PKG_CONFIG_PATH使用的地址。比方说ubuntu 地址为 /usr/local/lib/pkgconfig , centos 路径为 /usr/local/lib64/pkgconfig

    5 . CMakeLists.txt 使用

    find_package(PkgConfig)
    
    pkg_search_module(CUDA REQUIRED cuda)
    include_directories(${CUDA_INCLUDE_DIRS})
    link_directories(${CUDA_LIBRARY_DIRS})
    
    pkg_search_module(TENSORRT REQUIRED tensorrt)
    include_directories(${TENSORRT_INCLUDE_DIRS})
    link_directories(${TENSORRT_LIBRARY_DIRS} )
    

    相关文章

      网友评论

          本文标题:GPU nvidia c++ 开发流程

          本文链接:https://www.haomeiwen.com/subject/arlguhtx.html