CUDA需要root权限?(Root access required for CUDA?)

编程入门 行业动态 更新时间:2024-10-27 17:21:09
CUDA需要root权限?(Root access required for CUDA?)

我在Ubuntu 10.04上使用GeForce 8400M GS,并且正在学习CUDA编程。 我正在撰写和运行几个基本程序。 我使用的是cudaMalloc,它一直给我一个错误,直到我以root身份运行代码。 但是,我只能以root身份运行代码一次。 之后,即使我以普通用户的身份运行代码,我也不会在malloc上遇到错误。 这是怎么回事?

I am using GeForce 8400M GS on Ubuntu 10.04 and I am learning CUDA programming. I am writing and running few basic programs. I was using cudaMalloc, and it kept giving me an error until I ran the code as root. However, I had to run the code as root only once. After that, even if I run the code as normal user, I do not get an error on malloc. What's going on?

最满意答案

这可能是由于您的GPU在启动时未正确初始化。 在使用Ubuntu服务器和其他未自动启动X服务器的安装时,我遇到了这个问题。 尝试以下解决方法:

为脚本创建一个目录以初始化您的GPU。 我通常使用/root/bin 。 在这个目录中,使用下面的代码创建一个名为cudainit.sh的文件(这个脚本来自Nvidia论坛)。

#!/bin/bash /sbin/modprobe nvidia if [ "$?" -eq 0 ]; then # Count the number of NVIDIA controllers found. N3D=`/usr/bin/lspci | grep -i NVIDIA | grep "3D controller" | wc -l` NVGA=`/usr/bin/lspci | grep -i NVIDIA | grep "VGA compatible controller" | wc -l` N=`expr $N3D + $NVGA - 1` for i in `seq 0 $N`; do mknod -m 666 /dev/nvidia$i c 195 $i; done mknod -m 666 /dev/nvidiactl c 195 255 else exit 1 fi

现在我们需要让这个脚本在启动时自动运行。 编辑/etc/rc.local看起来如下所示。

#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # # Init CUDA for all users # /root/bin/cudainit.sh exit 0

重新启动计算机并尝试以普通用户身份运行CUDA程序。 如果我对这个问题是正确的,那么它应该是固定的。

This is probably due to your GPU not being properly initialized at boot. I've come across this problem when using Ubuntu Server and other installations where an X server isn't being started automatically. Try the following to fix it:

Create a directory for a script to initialize your GPUs. I usually use /root/bin. In this directory, create a file called cudainit.sh with the following code in it (this script came from the Nvidia forums).

#!/bin/bash /sbin/modprobe nvidia if [ "$?" -eq 0 ]; then # Count the number of NVIDIA controllers found. N3D=`/usr/bin/lspci | grep -i NVIDIA | grep "3D controller" | wc -l` NVGA=`/usr/bin/lspci | grep -i NVIDIA | grep "VGA compatible controller" | wc -l` N=`expr $N3D + $NVGA - 1` for i in `seq 0 $N`; do mknod -m 666 /dev/nvidia$i c 195 $i; done mknod -m 666 /dev/nvidiactl c 195 255 else exit 1 fi

Now we need to make this script run automatically at boot. Edit /etc/rc.local to look like the following.

#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # # Init CUDA for all users # /root/bin/cudainit.sh exit 0

Reboot your computer and try to run your CUDA program as a regular user. If I'm right about what the problem is, then it should be fixed.

更多推荐

本文发布于:2023-07-24 08:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1243442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:权限   root   CUDA   required   access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!