如何从远程机器运行CUDA / OpenGL互操作(粒子)示例 [英] How to run CUDA/OpenGL interop (particle) sample from a remote machine

查看:3754
本文介绍了如何从远程机器运行CUDA / OpenGL互操作(粒子)示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在远程Ubuntu机器上从主机ubuntu计算机上运行CUDA粒子样本。
我遵循本教程:
http://devblogs.nvidia.com/parallelforall/remote-application-development-nvidia-nsight-eclipse-edition/ ,它运行在我的主机上,但不在我的远程机。



我在Nsight中得到以下输出:

  CUDA粒子模拟开始... 

grid:64 x 64 x 64 = 262144 cells
particle:16384
没有指定协议
freeglut(/ users / path / particles / Debug / particle):无法打开显示':0'
注销

程序从终端我得到:

  CUDA粒子模拟开始... 

grid:64 x 64 x 64 = 262144 cells
particles:16384
CUDA错误在../src/particleSystem_cuda.cu:85 code = 79(cudaErrorInvalidGraphicsContext)cudaGraphicsGLRegisterBuffer(cuda_vbo_resource,vbo,cudaGraphicsMapFlagsNone)

是否可以在主机上显示粒子模拟,而计算是在远程系统上进行? p>

是通过X11Forwarding实现的还是完全不同的错误?

解决方案

p>我要提供一个冗长的答案,因为我只是通过这个。不过,在继续此路径之前,我建议您尝试使用 NoMachine NX 这样的解决方案,有一些内置的这种能力。



您可以访问远程工作站,甚至是无头工作站,进行图形桌面访问,并且还可以访问CUDA和OpenGL加速,使用 VirtualGL和TurboVNC 的组合。下面的指令相当特定于一个特定的机器配置(例如linux OS等),所以如果你做出改变,他们可能会破裂,你必须弄清楚什么是不同的。对于CentOS 6.x,这应该是一个很好的食谱,对于其他方法,它只是一个指南。这个配方大多假设只添加一个特斯拉/ CUDA GPU。如果你有多个GPU要配置,它应该是可能的,但只有一个将被用于OpenGL加速 - 只需要在 xorg.conf 中配置一个。 / p>


  1. 此设置可以使用没有显示输出的Tesla卡(例如K40c)但是 - 见下面的注释*)。在这种情况下,它假定您有另一个显示卡用于初始远程工作站设置步骤。这种其他显示卡可以是任何卡,并且机器可以在设置之后转换为无头使用。如果您使用不同的显示GPU进行设置,您最初可以将Tesla或CUDA GPU退出系统。


  2. 安装Linux操作系统。我使用CentOS 6.2进行这个测试。如果你使用CentOS / RHEL 6.x操作系统,事情应该可以为你工作,大致如这里所述。如果你使用不同的操作系统,任何东西都可能不同。如果是这样,这些说明只是一个指南,而不是一个食谱。在安装CentOS 6.2期间,选择软件开发工作站选项,以获得我们将需要的大部分图形和开发位。应该在安装过程中提示您创建普通用户名(除了root)。我们将这个 myuser


  3. 禁用Nouveau。在CentOS 6.x上,这些步骤将以作为root 执行:

      blacklist nouveau \ noptions nouveau modeset = 0> /etc/modprobe.d/disable-nouveau.conf 
    dracut --force


  4. 关闭并安装您想要用于CUDA和/或OpenGL加速的特斯拉或其他CUDA GPU。再次打开机器电源。希望linux显示应该仍然出现在与您在步骤3中使用相同的显示器。如果您使用特斯拉(即非显示)卡,但是如果您使用一些其他CUDA显示器不应该有任何问题有能力的GPU(GeForce / Quadro),X显示器可能会在这一点上移动到刚刚安装的GPU。


  5. a href =http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html#abstract =nofollow> CUDA 7 。我使用runfile安装程序方法,并为所有问题(包括安装OpenGL库)选择是,并接受所有默认路径。如果您使用其他CUDA版本或其他安装方法,结果可能会有所不同。


  6. 安装VirtualGL和TurboVNC:

      wget http://sourceforge.net/projects/virtualgl/files/2.3.3/VirtualGL-2.3.3.x86_64.rpm/download 
    sudo rpm -i VirtualGL-2.3.3.x86_64.rpm
    wget http://sourceforge.net/projects/turbovnc/files/1.2.1/turbovnc-1.2.1.x86_64.rpm/download
    sudo rpm -i turbovnc-1.2.1.x86_64.rpm

    我不认为有什么特别的关于这些版本,但如果您使用不同的版本,结果可能会有所不同。


  7. 运行 nvidia-xconfig (以终端会话)以root 建立初始 /etc/X11/xorg.conf 文件,然后修改设备部分添加如下行:

      BusIDPCI:1:0:0

    其中PCI地址与您的GPU匹配(用 lspci nvidia-smi -a )对于无头操作,您可以选择向Screen部分添加一行,但我相信没有必要(即使是无头操作):

     选项UseDisplayDevicenone

    一个完整的示例 xorg.conf 出现在此答案的结尾。


  8.   unset SESSION_MANAGER 

    添加以下行:

      unset DBUS_SESSION_BUS_ADDRESS 


  9. 作为 myuser ,请按如下方式添加启动应用程序,使用gnome桌面实用程序..Startup应用程序)

      / opt / TurboVNC / bin / vncserver:5 -depth 24 

    :5 这里有些随意,您可以使用其他数字:2 如果你愿意,但不要使用:0 。其余假设您在此处选择了:5 。您将想要从终端会话运行此行(只需一次,再次作为 myuser ),以便设置/配置vncserver使用。第一次运行它时,它可能会提示您输入密码。


  10. 对于无头/无人值守的使用,有两种可能的选项。




    • 您可以为 myuser 创建自动登录。作为 root ,请编辑 /etc/gdm/custom.conf 以创建/添加:

        [daemon] 
      AutomaticLoginEnable = true
      AutomaticLogin = myuser




    我承认有些人可能认为自动登录是一种安全风险。如果是这种情况,您应该使用以下替代方法(首选):




    • 停止X服务器

    • 作为root,请运行 vglserver_config

    • 选择选项1

    • n 到所有3个问题(这将工作,但是这里也有安全问题,你可能希望查阅文档,并扩展管理必要的用户组并尝试除 n 之外的其他选择所有3个问题。)

    • 选择X退出

    • 重新启动X服务器



    没有自动登录,您将需要一个方法来启动vncserver进行远程访问,因为我们在步骤9中添加的启动应用程序将不会生效。一种方法是在启动后通过SSH连接登录到计算机,并且 myuser 启动vncserver:

      / opt / TurboVNC / bin / vncserver:5 -display 24 

    或者您可以探索在机器启动时自动运行应用程序的各种方法。


  11. 如果你还没有这样做,你可能会遇到这样的情况,想要构建CUDA样本。该方法包含在上述步骤5中链接的入门指南文档中。您可能需要确保为某些CUDA图形样本(例如 simpleGL )安装了合适的谷歌提供者,例如freeglut。


  12. 在关闭电源之前,您可能还需要修改远程工作站防火墙。为了我的目的,我只是禁用它(系统...管理...防火墙...禁用)。 TurboVNC使用默认情况下将被防火墙阻止的特定端口。




如果您希望使用防火墙但打开这些端口,则应该可以,但不在此配方的范围内。

您的远程工作站现已配置。如果您进行了所有上述更改,您可以切换到无头操作,如果添加xorg无显示选项,您可能实际上在下次重新启动时切换到无头。在重新启动之前,您可能需要记录远程工作站的IP地址。如果你要无头,可能很方便的配置一个静态IP。让我们假设您观察到远程工作站的IP地址是192.168.1.104。现在是重新启动远程工作站的时间。



在客户端计算机上,您应该安装 TurboVNC 客户端适合您的操作系统。运行TurboVNC客户端Viewer应用程序,并提供附加的IP作为连接到的机器:

  192.168。 1.104:5 

连接后,系统会提示您输入上述步骤9中提供的密码。此时,与 myuser 相关联的图形桌面应该在客户端计算机上打开。此图形桌面尚未具有与其相关联的完整3D图形加速。为了使用GPU的OpenGL(和CUDA / OpenGL互操作),有必要运行这样的应用程序前面加上 vglrun ,像这样:

  vglrun -d:0 glxgears 

您在这里指定:0 ,因为这是GPU图形加速关联的实际X显示(对于登录 myuser )。如果您构建了CUDA示例,可以尝试使用CUDA / OpenGL互操作应用程序:

  vglrun -d:0 / usr / local / cuda / samples / bin / x86_64 / linux / release / simpleGL 

如果您在步骤10中使用vglserver_config配置了vglserver,那么您应该可以从vglrun命令中省略 -d:0 切换:

  vglrun glxgears 

目的( - 您很可能不能逐字使用此xorg文件),这里是一个完整的 xorg.conf 没有对 vglserver_config )进行任何修改:

 #nvidia-xconfig:X配置文件生成的nvidia-xconfig 
#nvidia-xconfig:版本346.46(buildmeister @ swio-display-x86-rhel47-06)二月17日星期二19:10:20 PST 2015

ServerLayout
标识符Layout0
屏幕0Screen0
InputDeviceKeyboard0CoreKeyboard
InputDeviceMouse0CorePointer
EndSection

SectionFiles
FontPath/ usr / share / fonts / default / Type1
EndSection

InputDevice默认
标识符Mouse0
驱动程序鼠标
选项Protocolauto
选项Device/ dev / input / Emulate3Buttonsno
选项ZAxisMapping4 5
EndSection

InputDevice部分
#从/ etc / sysconfig / keyboard
标识符Keyboard0
驱动程序kbd
选项XkbLayoutus
选项XkbModelpc105
EndSection

SectionMonitor
标识符Monitor0
VendorNameUnknown
ModelNameUnknown
HorizSync 28.0 - 52.0
VertRefresh 43.0 - 72.0
选项DPMS
EndSection

Device部分
标识符Device0
驱动程序nvidia
VendorNameNVIDIA Corporation
BusIDPCI:1:0:0
EndSection

部分屏幕
标识符Screen0
设备Device0
监视器Monitor0
DefaultDepth 24
选项UseDisplayDevicenone
SubSectionDisplay
深度24
模式1024x768
EndSubSection
EndSection

疑难解答:



打算回答详细的故障排除问题,因为我将无法测试每个配置。但是,如果客户端无法连接到远程工作站,则可能意味着vncserver没有正确启动,或者防火墙阻塞了。对于其他类型的故障排除, /var/log/Xorg.0.log 可能会提供一些线索。使用 nvidia-smi 确认您的CUDA驱动程序已正确安装。一般来说,无头操作很难排除故障,所以如果你可以安排一个显示能力的CUDA GPU初始设置和测试,它可能会更容易。



注意:
* K20m和K20Xm需要使用<$ c $来正确设置图形操作模式c> nvidia-smi 实用程序。 K20c 不能用于此目的,它是只计算的。 AFAIK,大多数其他支持NVIDIA CUDA的GPU都应该可用于此目的。具有cc2.0之前的计算能力的GPU不能与本文档中描述的CUDA 7驱动程序一起使用。



作为附加参考,此 nvidia白皮书将会很有用。


I am trying to run the CUDA particle sample on a remote Ubuntu machine from a host ubuntu machine. I followed this tutorial: http://devblogs.nvidia.com/parallelforall/remote-application-development-nvidia-nsight-eclipse-edition/ and it runs on my host, but not on my remote machine.

I get the following output in Nsight:

CUDA Particles Simulation Starting...

grid: 64 x 64 x 64 = 262144 cells
particles: 16384
No protocol specified
freeglut (/users/path/particles/Debug/particles): failed to open display ':0'
logout

If I run the program from the terminal I get:

CUDA Particles Simulation Starting...

grid: 64 x 64 x 64 = 262144 cells
particles: 16384
CUDA error at ../src/particleSystem_cuda.cu:85  code=79(cudaErrorInvalidGraphicsContext)  "cudaGraphicsGLRegisterBuffer(cuda_vbo_resource, vbo, cudaGraphicsMapFlagsNone)" 

Is it possible to display the particle simulation on my host machine, while the calculation is made on a remote system?

Is it achieved through X11Forwarding, or is it a completely different error?

解决方案

I'm going to provide a lengthy answer because I just worked through this. However, before proceeding down this path, I'd encourage you to try a solution like NoMachine NX which should already have some of this capability built-in. It may meet your needs.

You can get access to a remote workstation, even a headless workstation, for graphical desktop access, and also have access to CUDA and OpenGL acceleration, using a combination of VirtualGL and TurboVNC. The following instructions are fairly specific to a particular machine configuration (e.g. linux OS, etc.) so if you make changes, they will likely break, and you will have to figure out what is different. For CentOS 6.x, this should be a pretty good recipe, for other approaches, it's just a guide. This recipe mostly assumes just a single Tesla/CUDA GPU being added. If you have multiple GPUs to configure, it should be possible, but only one would be used for the OpenGL acceleration - only one should need to be configured in xorg.conf.

  1. This setup can be done with a Tesla card that has no display output (e.g. K40c, for example. K20 variants are a special case, however -- see note below * ). In that case, it assumes you have another display card for the initial remote workstation setup steps. This other display card can be any card, and the machine can be converted to "headless" use after setup. If you are using a different display GPU for setup, you can initially leave your Tesla or CUDA GPU out of the system.

  2. Install your Linux OS. I used CentOS 6.2 for this test. If you use a CentOS/RHEL 6.x OS, things should probably work for you pretty much as described here. If you use a different OS, anything may be different. If so, these instructions are just a guide, not a recipe. During install of CentOS 6.2, select "Software Development Workstation" option, to get most of the graphical and development bits we'll need. You should be prompted during setup to create an ordinary username (apart from root). We'll call this myuser.

  3. Disable Nouveau. On CentOS 6.x, these steps will do the trick as root:

    echo -e "blacklist nouveau\noptions nouveau modeset=0"  > /etc/modprobe.d/disable-nouveau.conf
    dracut --force
    

  4. Power down, and install the Tesla or other CUDA GPU(s) that you want to use for CUDA and/or OpenGL acceleration. Power up the machine again. Hopefully the linux display should still be appearing on the same display as you were using in step 3. There shouldn't be any problem if you are using a Tesla (i.e. non-display) card, but if you are using some other CUDA display-capable GPU (GeForce/Quadro), it's possible that the X display moved at this point, to the GPU(s) you just installed.

  5. install CUDA 7. I used the runfile installer method, and selected yes for all questions (including install of OpenGL libraries) and accept all default paths. If you use some other CUDA version or some other install method, your results may vary.

  6. Install VirtualGL and TurboVNC:

    wget http://sourceforge.net/projects/virtualgl/files/2.3.3/VirtualGL-2.3.3.x86_64.rpm/download
    sudo rpm -i VirtualGL-2.3.3.x86_64.rpm
    wget http://sourceforge.net/projects/turbovnc/files/1.2.1/turbovnc-1.2.1.x86_64.rpm/download
    sudo rpm -i turbovnc-1.2.1.x86_64.rpm
    

    I don't think there's anything special about these versions, but if you use different versions, your results may vary.

  7. run nvidia-xconfig (from a terminal session) as root to establish an initial /etc/X11/xorg.conf file, then modify the "Device" section to add a line like this:

    BusID    "PCI:1:0:0"
    

    where the PCI address matches your GPU (confirm with lspci or nvidia-smi -a) For headless operation, you may optionally want to add a line like this to the "Screen" section, but I believe it is not necessary (even for headless operation):

    Option         "UseDisplayDevice" "none"
    

    a complete sample xorg.conf appears at the end of this answer.

  8. as myuser, in ~/.vnc/xstartup.turbovnc, after this line:

    unset SESSION_MANAGER
    

    add the following line:

    unset DBUS_SESSION_BUS_ADDRESS
    

  9. as myuser, add a startup application as follows, using the gnome desktop utility (System...Preferences...Startup Applications)

    /opt/TurboVNC/bin/vncserver :5 -depth 24
    

    the :5 here is somewhat arbitrary, you can use other numbers like :2 if you wish, but do not use :0. The remainder assumes you have selected :5 here. You will want to run this line also (just once, again as myuser) from a terminal session, in order to setup/configure the vncserver for use. The first time you run it, it will probably prompt you for a password. Remember this password - you will need it for client access later.

  10. For headless/unattended use, there are two possible options.

    • you can create an autologin for myuser. As root, edit /etc/gdm/custom.conf to create/add:

      [daemon]
      AutomaticLoginEnable=true
      AutomaticLogin=myuser
      

    I acknowledge that some may consider an auto-login as a security risk. If that is the case, you should use the alternate ("preferred") method below:

    • stop the X server
    • as root, run vglserver_config
    • select option 1
    • answer n to all 3 questions (this will work, however there are security issues here as well. You may wish to consult the documentation, and expore managing the necessary user groups and experiment with other choices besides n to all 3 questions.)
    • select X to exit
    • restart the X server

    without an autologin, you will need a method to start the vncserver for remote access, since the startup application we added in step 9 won't take effect. One approach would be to simply login via an SSH connection to the machine after startup, and as myuser start the vncserver:

    /opt/TurboVNC/bin/vncserver :5 -display 24
    

    Or you can explore various methods for running applications automatically at machine start-up. There are so many possible approaches here, it's best if you just do a google search pertinent to your OS.

  11. If you have not already done so, you may want to build the CUDA samples. The method is covered in the getting started guide document linked in step 5 above. You may need to make sure you have a suitable glut provider installed, such as freeglut, for some of the CUDA graphical samples, such as simpleGL.

  12. Before powering down, you will probably also want to modify the remote workstation firewall. For my purposes, I just disabled it (System...Administration...Firewall...Disable). TurboVNC uses specific ports that will be blocked by the firewall by default. If you wish to use the firewall but open up these ports, it should be possible but is outside the scope of this recipe.

Your remote workstation is now configured. If you made all the changes above, you can switch to "headless" operation, and if you added the xorg no display option, you may in fact switch to "headless" on the next reboot. Before your reboot, you may want to make a note of the remote workstation IP address. If you are going "headless", it may be convenient to configure it with a static IP. Let's assume that you observed that the IP address of the remote workstation was 192.168.1.104. So now is the time to reboot your remote workstation.

On a client machine, you should install the TurboVNC client appropriate for your OS. Run the TurboVNC client "Viewer" app, and provide the IP appended by :5 as the machine to connect to:

192.168.1.104:5

Once you connect, you will be prompted for the password you provided in step 9 above. At this point, a graphical desktop associated with myuser should open up on your client machine. This graphical desktop does not yet have full 3D graphical acceleration associated with it. In order to make use of the GPU for OpenGL (and CUDA/OpenGL interop), it's necessary to run such applications prepended with vglrun, like so:

vglrun -d :0 glxgears

You are specifying :0 here because that is the actual X display that the GPU graphical acceleration is associated with (for the logged-in myuser). If you built the CUDA samples, you can try a CUDA/OpenGL interop app:

vglrun -d :0 /usr/local/cuda/samples/bin/x86_64/linux/release/simpleGL

In both of the above examples, if you have configured the vglserver using vglserver_config in step 10, then you should be able to omit the -d :0 switch from the vglrun command:

vglrun glxgears

For reference purposes (only - you most likely cannot use this xorg file verbatim), here is a complete xorg.conf (without any modifications from vglserver_config):

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 346.46  (buildmeister@swio-display-x86-rhel47-06)  Tue Feb 17 19:10:20 PST 2015

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
    FontPath        "/usr/share/fonts/default/Type1"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/input/mice"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    # generated from data in "/etc/sysconfig/keyboard"
    Identifier     "Keyboard0"
    Driver         "kbd"
    Option         "XkbLayout" "us"
    Option         "XkbModel" "pc105"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    HorizSync       28.0 - 52.0
    VertRefresh     43.0 - 72.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BusID          "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "UseDisplayDevice" "none"
    SubSection     "Display"
        Depth       24
        Modes      "1024x768"
    EndSubSection
EndSection

Troubleshooting:

I don't intend to respond to detailed troubleshooting questions, since I won't be able to test every configuration. However, if your client cannot connect at all to the remote workstation, it likely means that the vncserver is not properly started, or the firewall is blocking things. For other types of troubleshooting, /var/log/Xorg.0.log may give some clues. Use nvidia-smi to establish that your CUDA drivers are properly installed. And in general, headless operation is difficult to troubleshoot, so if you can arrange for a display-capable CUDA GPU for initial setup and testing, it may be easier. You can switch to a non-display GPU later.

Note: * K20m and K20Xm require proper setting of the graphics operation mode using the nvidia-smi utility. K20c cannot be used for this purpose, it is compute-only. AFAIK, most other NVIDIA CUDA-capable GPUs should be usable for this purpose. GPUs with compute capability prior to cc2.0 cannot be used with the CUDA 7 drivers described in this writeup, however.

As an additional reference, this nvidia whitepaper will be useful.

这篇关于如何从远程机器运行CUDA / OpenGL互操作(粒子)示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆