我在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 fiNow 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 0Reboot 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.
更多推荐
发布评论