Skip to main content
 首页 » 编程设计

python之Theano 无法使用 GPU

2024年12月31日14pengyingh

(theano_p27) ubuntu@ip-***-**-**-***:~$ device=cuda0,floatX=float32 GPUARRAY_CUDA_VERSION=80 python test.py 
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions. 
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled 
Traceback (most recent call last): 
File "/home/ubuntu/anaconda3/envs/theano_p27/lib/python2.7/site-packages/theano/gpuarray/__init__.py", line 227, in <module> 
use(config.device) 
File "/home/ubuntu/anaconda3/envs/theano_p27/lib/python2.7/site-packages/theano/gpuarray/__init__.py", line 214, in use 
init_dev(device, preallocate=preallocate) 
File "/home/ubuntu/anaconda3/envs/theano_p27/lib/python2.7/site-packages/theano/gpuarray/__init__.py", line 99, in init_dev 
**args) 
File "pygpu/gpuarray.pyx", line 658, in pygpu.gpuarray.init 
File "pygpu/gpuarray.pyx", line 587, in pygpu.gpuarray.pygpu_init 
GpuArrayException: cuInit: CUDA_ERROR_UNKNOWN: unknown error 
[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)] 
Looping 1000 times took 2.717710 seconds 
Result is [1.2317803 1.6187934 1.5227807 ... 2.2077181 2.2996776 Used the cpu 

我正在尝试使用 Amazon Web Services EC2 来运行 GPU,当我尝试运行测试以使我的代码运行我的 gnu 时出现此错误,但它给了我这个错误。

请帮忙

编辑:我运行的代码是Theano网站上的测试代码

from theano import function, config, shared, tensor 
import numpy 
import time 
 
vlen = 10 * 30 * 768  # 10 x #cores x # threads per core 
iters = 1000 
 
rng = numpy.random.RandomState(22) 
x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) 
f = function([], tensor.exp(x)) 
print(f.maker.fgraph.toposort()) 
t0 = time.time() 
for i in range(iters): 
    r = f() 
    t1 = time.time() 
print("Looping %d times took %f seconds" % (iters, t1 - t0)) 
print("Result is %s" % (r,)) 
if numpy.any([isinstance(x.op, tensor.Elemwise) and 
          ('Gpu' not in type(x.op).__name__) 
          for x in f.maker.fgraph.toposort()]): 
    print('Used the cpu') 
else: 
    print('Used the gpu') 

请您参考如下方法:

回应后续评论。为了在具有深度学习 AMI 的 AWS 上配置和使用 GPU,建议使用以下实例 (source):

Amazon EC2 P3 Instances have up to 8 NVIDIA Tesla V100 GPUs.

Amazon EC2 P2 Instances have up to 16 NVIDIA NVIDIA K80 GPUs.

Amazon EC2 G3 Instances have up to 4 NVIDIA Tesla M60 GPUs.

Check out EC2 Instance Types and choose Accelerated Computing to see the different GPU instance options.

另外你可以试试Elastic GPUs .

最后,它为了使用您通常需要从 Nvidia 站点安装适当驱动程序的 GPU 实例。查看上面引用的 GPU 类型文本。下载驱动并运行;例如:

./NVIDIA-Linux-x86_64-384.81.run 

您还可以传递 -silent 标志以使用配置管理或其他方式安装它。另外,请记住,您必须根据要使用的实例大小安装驱动程序。如果您在 p3.2xlarge 上安装驱动程序的位置创建 AMI 镜像,然后尝试在 p3.8xlarge 上运行某些东西,您可能需要重新安装司机。