CUDA需要root访问权限?

时间:2012-06-19 15:29:07

标签: cuda root

我在Ubuntu 10.04上使用GeForce 8400M GS,我正在学习CUDA编程。我正在编写并运行一些基本程序。我正在使用cudaMalloc,它一直给我一个错误,直到我以root身份运行代码。但是,我必须只以root身份运行一次代码。在那之后,即使我以普通用户身份运行代码,我也不会在malloc上出错。发生了什么事?

2 个答案:

答案 0 :(得分:7)

这可能是由于您的GPU未在启动时正确初始化。我在使用Ubuntu Server和其他没有自动启动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程序。如果我对问题是对的,那就应该修复。

答案 1 :(得分:0)

要使用Ubuntu 14.04,我按https://devtalk.nvidia.com/default/topic/699610/linux/334-21-driver-returns-999-on-cuinit-cuda-/nvidia-uvm添加到etc/modules,并在自定义udev规则中添加一行。使用以下行创建/etc/udev/rules.d/70-nvidia-uvm.rules

KERNEL=="nvidia_uvm", RUN+="/bin/bash -c '/bin/mknod -m 666 /dev/nvidia-uvm c $(grep nvidia-uvm /proc/devices | cut -d \  -f 1) 0;'"

我不明白为什么sudo modprobe nvidia-uvm可以创建合适的/dev/nvidia-uvmsudo cuda_program),但/etc/modules列表需要udev规则。

相关问题