Installed beignet to use OpenCL on Intel, but OpenCL programs only work when run as root

蹲街弑〆低调 提交于 2019-12-05 21:42:58

I know this is kinda resurrecting an old thread, but I recently solved this problem and haven't found any solutions posted online, so here goes...

With the latest kernels rnodes is enabled by default, but this still doesn't work... Next step is to check the ownership of the /dev/dri files... e.g. on my system, I get:

$ ls -l /dev/dri
total 0
crw-rw---- 1 root video 226,   0 May 16 21:30 card0
crw-rw---- 1 root video 226,  64 May 16 21:30 controlD64
crw-rw---- 1 root video 226, 128 May 16 21:30 renderD128

Hinting I either need to be root user or a member of the "video" group to access the device...

Add the relevant user (i.e. the one you want to run the opencl program as) to the group:

usermod -a -G video <user>

Then relog and bingo no need to run as root anymore!

I'm no expert on beignet, but I know a thing or two about direct rendering, so this is what I could extract of reading some of the documentation.

beignet supports three modes:

  1. connect directly to the device with root (this is what you are doing)
  2. use dri2 to connect via the X server as a normal user
  3. use the device directly over a direct render node as a normal user

Before going any further, you need to check if direct rendering is enabled in your video card driver and in the environment you're running your scripts on. This is done with the following command in the same terminal you're running your scripts:

glxinfo | grep render

It should output something like Direct rendering: yes, which is great. The glxinfo gives you all sort of other info that could be useful on helping find the source of your problem, so be sure to update your question with the complete output of the command (without the | grep direct part).

Method 2 is the easiest method of using direct rendering, but requires the environment that is running the script to have a DISPLAY variable setting. If you're running it on a terminal emulator (like the Terminal app in Mint) it should be already set. You can check this by entering the following command:

echo $DISPLAY

it should print :0 or something like that. If it doesn't show anything, then your script doesn't know which screen (or video card) to render to. This could happen if you're working on a remote machine via SSH, or using the terminal screen directly without a desktop environment. You can of course set this variable with this command:

export DISPLAY=:0

You just have to be sure that's the correct display to render to (the one running your X server), you can check in the output of glxinfo.

Method 3 requires that your video card supports KVM (which apparently it does) and to enable rendering nodes. This is done when the system is booting up, so you need to modify your boot loader parameters to enable it. If you're booting using GRUB2, this is fairly simple (but, you know, back up any important thing in case anything goes wrong):

As root, you must edit the file /etc/defaults/grub and look for the following line (the … is because it can contain more parameters than just those two):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash …"

Then, you must add the parameter that enables the rendering nodes at the end of that variable:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash … drm.rnodes=1"

After that, you save the file and execute the following command as root:

sudo update-grub

Then reboot the computer, and your scripts should run as a normal user.

UPDATE: About the NVIDIA error that you're getting running as root, could it be possible that your laptop (because it's a laptop, right?) has hybrid graphic cards? if so, then you should be running OpenCL on the right card. Please update your question with the output of the following command:

lspci | grep -i vga

That should tell us exactly what hardware are you dealing with.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!