加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

CUDA需要root访问权限?

发布时间:2020-12-14 02:18:29 所属栏目:Linux 来源:网络整理
导读:我在Ubuntu 10.04上使用GeForce 8400M GS,我正在学习CUDA编程.我正在编写并运行一些基本程序.我正在使用cudaMalloc,它一直给我一个错误,直到我以root身份运行代码.但是,我必须只以root身份运行一次代码.在那之后,即使我以普通用户身份运行代码,我也不会在mal
我在Ubuntu 10.04上使用GeForce 8400M GS,我正在学习CUDA编程.我正在编写并运行一些基本程序.我正在使用cudaMalloc,它一直给我一个错误,直到我以root身份运行代码.但是,我必须只以root身份运行一次代码.在那之后,即使我以普通用户身份运行代码,我也不会在malloc上出错.这是怎么回事?

解决方法

这可能是由于您的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程序.如果我对问题是对的,那就应该修复.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读