Linux平台安装

1、平台

  • Linux 平台:推荐ubuntu:20.04.4-LTS-desktop
  • 不推荐虚拟机安装:虚拟机中的显卡不是真实的物理显卡,在CUDA安装及后续的项目编译中会出现问题。

ubuntu:20.04-LTS-desktop版本系统与本项目运行环境契合度较高,项目编译起来问题较少。ubuntu:18.04-LTS-desktop版本OpenGL版本低于4.3,而且升级较为麻烦。ubuntu22.04-LTS-desktop版本系统g++、gcc以及cuda的版本较高。因此笔者选用ubuntu:20.04-LTS-desktop版本系统作为运行环境,其他版本的Linux系统,读者可以自行尝试。

2、依赖

  • OpenGL version:4.6+
$ glxinfo | grep "OpenGL version"
OpenGL version string: 4.6.0 NVIDIA 510.47.03
  • 安装mesa-utils
$ sudo apt install mesa-utils

​ 查看驱动版本:

$ nvidia-smi
Fri Aug 12 14:51:28 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.47.03    Driver Version: 510.47.03    CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
| 30%   31C    P8    18W / 220W |    171MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1338      G   /usr/lib/xorg/Xorg                 36MiB |
|    0   N/A  N/A      3416      G   /usr/lib/xorg/Xorg                 35MiB |
|    0   N/A  N/A      3546      G   /usr/bin/gnome-shell               86MiB |
+-----------------------------------------------------------------------------+

调用nvidia-smi指令时有可能会出现找不到的问题,其原因通常是Ubuntu 20.04没有安装最新显卡驱动。较为简单的方法可以通过Software & Updates –>Additional Drivers选取合适的显卡驱动重新安装,安装之后重启系统。

  • CUDA Version: 11+
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0

CUDA安装参见官网,安装成功后需要配置环境变量,打开.bashrc文件:

$ sudo gedit ~/.bashrc

在文件结尾添加:

export PATH=/usr/local/cuda-11.6/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64:$LD_LIBRARY_PATH

激活配置文件:

source ~/.bashrc
  • cmake version: 3.10+

安装CMake:

$ sudo apt install cmake

查看cmake版本:

$ cmake --version
cmake version 3.16.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

同时推荐安装cmake-gui。PeriDyno项目编译可选参数较多,使用图形化界面可以便捷的选择需要编译的库。

值得注意的是,默认安装的cmake版本较低,有可能出现与最新版本CUDA不兼容的情况。如果出现 “The CMAKE_CUDA_COMPILER: /usr/local/ is not a full path to an existing compiler tool ”的错误,请安装高版本cmake。安装方式如下:

$ sudo apt remove cmake
$ sudo apt autoremove
$ sudo snap install cmake --classic

3、安装项目

(1)更新系统软件环境:

$ sudo apt-get update

(2)安装C++编译器:

$ sudo apt install g++
$ sudo apt install gcc

(3)安装依赖包:

$ sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libxrandr-dev libxinerama-dev libxcursor-dev 
$ sudo apt install -y mesa-common-dev  libgl-dev 

(4)克隆项目及子模块:

$ git clone -b linux --recursive https://gitee.com/peridyno/peridyno.git

注意,此时需要选择PeriDyno代码仓库中的linux分支。

(5)创建build文件夹:

$ mkdir build 
$ cd build 

4、编译项目

  • cmake项目,其中参数 -D PERIDYNO_EXMAPLE=ON 表示编译PeriDyno中的exmaple工程:
hehao@hehao:~/peridyno-gitee/build$ cmake -D PERIDYNO_EXMAPLE=ON ..
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Using X11 for window creation
-- Imath is configuring as a cmake sub project
-- Configure Imath 3.2.0-dev, library API version: 29.0.0
-- CMAKE SYSTEM NAME: Linux
-- The install dir is /usr/local
-- Found package Imath
   * Alembic Configuration          ===
   * USE_ARNOLD                     OFF
   * USE_BINARIES                   OFF
   * USE_EXAMPLES                   OFF
   * USE_HDF5                       OFF
   * USE_MAYA                       OFF
   * USE_PRMAN                      OFF
   * USE_PYALEMBIC                  OFF
   * USE_STATIC_BOOST               OFF
   * USE_STATIC_HDF5                OFF
   * USE_TESTS                      OFF
   * ALEMBIC_ILMBASE_LINK_STATIC    OFF
   * ALEMBIC_SHARED_LIBS            ON
   * PYALEMBIC_PYTHON_MAJOR         3
   * DOCS_PATH                      OFF
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/blur.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/axis.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/axis.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/background.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/bbox.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/bbox.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/plane.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/helper/plane.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/instance.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/instance.geom.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/instance.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/line.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/line.geom.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/line.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/point.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/point.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/screen.vert.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/ssao.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/surface.frag.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/surface.geom.glsl
Process: /home/hehao/Documents/peridyno/peridyno/src/Rendering/Engine/OpenGL/shader/surface.vert.glsl
-- Configuring done
-- Generating done	
CMake Warning:
  Manually-specified variables were not used by the project:
    PERIDYNO_EXMAPLE
-- Build files have been written to: /home/hehao/Documents/peridyno/peridyno/build
  • 如果安装了cmake-gui图形界面:

  • make项目

可以使用 make -j8 指令加快编译速度,其中 -j8 表示使用8个线程同时编译:

hehao@hehao:~/peridyno-gitee/build$ make
[  2%] Built target Imath
[  6%] Built target glfw
[  7%] Built target glad
[  9%] Built target imgui
[ 12%] Built target Core
[ 38%] Built target Alembic
[ 58%] Built target Framework
[ 60%] Built target RenderCore
[ 60%] Built target ABCExporter
[ 62%] Built target ImWidgets
[ 65%] Built target IO
Scanning dependencies of target GLRenderEngine
[ 67%] Built target Volume
[ 69%] Built target HeightField
[ 70%] Built target RigidBody
[ 75%] Built target ParticleSystem
[ 75%] Building CXX object src/Rendering/Engine/OpenGL/CMakeFiles/GLRenderEngine.dir/gl/Program.cpp.o
[ 79%] Built target Peridynamics
[ 79%] Linking CUDA device code CMakeFiles/GLRenderEngine.dir/cmake_device_link.o
[ 79%] Linking CXX static library ../../../../lib/Release/libGLRenderEngine.a
[ 85%] Built target GLRenderEngine
[ 86%] Linking CUDA device code CMakeFiles/GlfwGUI.dir/cmake_device_link.o
[ 86%] Linking CXX shared library ../../../../lib/Release/libdynoGlfwGUI-0.6.0.so
[ 86%] Built target GlfwGUI
[ 86%] Linking CUDA device code CMakeFiles/GL_GlfwGUI.dir/cmake_device_link.o
[ 86%] Linking CUDA device code CMakeFiles/GL_Bricks.dir/cmake_device_link.o
[ 87%] Linking CUDA device code CMakeFiles/GL_Buoyancy.dir/cmake_device_link.o
[ 87%] Linking CUDA device code CMakeFiles/GL_InstanceVisualizer.dir/cmake_device_link.o
[ 88%] Linking CUDA device code CMakeFiles/GL_CapillaryWave.dir/cmake_device_link.o
[ 88%] Linking CUDA device code CMakeFiles/GL_Cloth.dir/cmake_device_link.o
[ 88%] Linking CUDA device code CMakeFiles/GL_Elasticity.dir/cmake_device_link.o
[ 88%] Linking CUDA device code CMakeFiles/GL_CollisionMask.dir/cmake_device_link.o
[ 88%] Linking CXX executable ../../bin/Release/GL_GlfwGUI
[ 89%] Linking CXX executable ../../bin/Release/GL_Buoyancy
[ 89%] Linking CXX executable ../../bin/Release/GL_Bricks
[ 89%] Linking CXX executable ../../bin/Release/GL_Elasticity
[ 89%] Linking CXX executable ../../bin/Release/GL_CapillaryWave
[ 89%] Linking CXX executable ../../bin/Release/GL_CollisionMask
[ 89%] Linking CXX executable ../../bin/Release/GL_InstanceVisualizer
[ 89%] Linking CXX executable ../../bin/Release/GL_Cloth
[ 89%] Built target GL_GlfwGUI
[ 90%] Linking CUDA device code CMakeFiles/GL_Ocean.dir/cmake_device_link.o
[ 91%] Built target GL_CollisionMask
[ 91%] Built target GL_Elasticity
[ 91%] Built target GL_Cloth
[ 91%] Built target GL_Buoyancy
[ 92%] Built target GL_Bricks
[ 93%] Built target GL_InstanceVisualizer
[ 93%] Built target GL_CapillaryWave
[ 93%] Linking CUDA device code CMakeFiles/GL_OceanPatch.dir/cmake_device_link.o
[ 93%] Linking CUDA device code CMakeFiles/GL_ParticleEmitter.dir/cmake_device_link.o
[ 94%] Linking CUDA device code CMakeFiles/GL_ParticleFluid.dir/cmake_device_link.o
[ 94%] Linking CUDA device code CMakeFiles/GL_Plasticity.dir/cmake_device_link.o
[ 94%] Linking CUDA device code CMakeFiles/GL_Timing.dir/cmake_device_link.o
[ 94%] Linking CUDA device code CMakeFiles/GL_TwoTets.dir/cmake_device_link.o
[ 94%] Linking CXX executable ../../bin/Release/GL_Ocean
[ 94%] Linking CUDA device code CMakeFiles/GL_TwoBoxes.dir/cmake_device_link.o
[ 94%] Linking CXX executable ../../bin/Release/GL_ParticleFluid
[ 94%] Built target GL_Ocean
[ 96%] Linking CXX executable ../../bin/Release/GL_Timing
[ 96%] Linking CXX executable ../../bin/Release/GL_OceanPatch
[ 96%] Linking CXX executable ../../bin/Release/GL_Plasticity
[ 96%] Linking CXX executable ../../bin/Release/GL_ParticleEmitter
[ 96%] Linking CXX executable ../../bin/Release/GL_TwoTets
[ 97%] Linking CUDA device code CMakeFiles/GL_Wireframe.dir/cmake_device_link.o
[ 97%] Linking CXX executable ../../bin/Release/GL_TwoBoxes
[ 97%] Linking CXX executable ../../bin/Release/GL_Wireframe
[ 98%] Built target GL_ParticleFluid
[ 98%] Built target GL_OceanPatch
[ 98%] Linking CUDA device code CMakeFiles/GL_GhostSPH.dir/cmake_device_link.o
[ 98%] Built target GL_Timing
[ 99%] Built target GL_TwoTets
[ 99%] Built target GL_ParticleEmitter
[ 99%] Built target GL_Plasticity
[ 99%] Built target GL_TwoBoxes
[100%] Linking CXX executable ../../../bin/Release/GL_GhostSPH
[100%] Built target GL_Wireframe
[100%] Built target GL_GhostSPH
  • 运行PeriDyno示例:
$ cd bin/Release
$ ./GL_GlfwGUI
  • 运行效果如下:

5、安装Vulkan(可选)

git clone https://github.com/SaschaWillems/Vulkan.git
git submodule sync
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make

安装了Vulkan,可选择Vulkan模式进行编译:

6、Peridyno插件安装(可选)

PeriDyno支持插件导入。在正常情况下,为了提高编译速度,默认插件是不启用的。如需要使用插件,在cmake阶段勾选PERIDYNO_LIBRARY_PLUGIN选项:

重新Configure和Generate后将会出现可选的插件:

7、安装交互式Qt框架(可选)

  • 安装Qt组件:
sudo apt-get install build-essential

sudo apt-get install qtcreator

sudo apt-get install qt5-default

sudo apt-get install libqt5svg5*
  • cmake项目,其中参数 -D PERIDYNO_Qt5_GUI=ON 表示编译PeriDyno的Qt库:
hehao@hehao:~/peridyno-gitee/build$ cmake -D PERIDYNO_Qt5_GUI=ON ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- The CUDA compiler identification is NVIDIA 11.6.55
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: /usr/local/cuda-11.6/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-11.6/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda-11.6 (found version "11.6") 
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Using X11 for window creation
-- Found X11: /usr/include   
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hehao/peridyno-gitee/build
  • make项目,其中 -j8 表示使用8个线程同时编译,加快编译速度:
$ make -j8
hehao@hehao:~/peridyno-gitee/build$ make -j8
[  1%] Automatic MOC for target nodes
[  2%] Built target glad
[  6%] Built target glfw
[  9%] Built target Core
[  9%] Built target nodes_autogen
[ 11%] Built target imgui
[ 21%] Built target nodes
[ 44%] Built target Framework
[ 46%] Built target RenderCore
[ 50%] Built target IO
[ 52%] Built target ImWidgets
[ 54%] Built target Volume
[ 56%] Built target RigidBody
[ 63%] Built target GLRenderEngine
[ 63%] Automatic MOC and UIC for target QtGUI
[ 64%] Built target GlfwGUI
[ 66%] Built target Interaction
[ 70%] Built target Modeling
[ 70%] Built target QtGUI_autogen
[ 75%] Built target ParticleSystem
[ 75%] Built target GL_GlfwGUI
[ 76%] Built target GL_InstanceVisualizer
[ 78%] Built target GL_SegmentVisualizer
[ 78%] Built target GL_MouseInteractionInGraphicsPipeline
[ 78%] Built target GL_MouseInteraction
[ 78%] Built target GL_Topology
[ 80%] Built target HeightField
[ 84%] Built target Peridynamics
[ 97%] Built target QtGUI
[ 99%] Built target Qt_Bricks
[ 99%] Built target Qt_MarchingCubes
[ 99%] Built target Qt_ShowChinese
[ 99%] Built target Qt_Pickers
[ 99%] Built target Qt_GUI_Empty
[100%] Built target Qt_MouseInteractionInGraphicsPipeline

  • 运行效果如下: