2016-02-24 27 views
6

Sau một loạt các cơn đau, tôi đã cài đặt Theano trên một máy có card đồ họa AMD - Radeon HD 5450 (Cedar).OpenCL Theano - Làm cách nào để vô hiệu hóa CUDA?

Bây giờ, hãy xem xét mã sau đây.

import numpy 
import theano 
import theano.tensor as T 
rng = numpy.random 

N = 400   #number of samples 
feats = 784  #dimensionality of features 
D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=2)) 
training_steps = 10000 

# theano symbolic variables 
x = T.matrix("x") 
y = T.vector("y") 
w = theano.shared(rng.randn(784), name="w") 
b = theano.shared(0., name="b") 

print("Initial Model:") 
print(str(w.get_value()) + " " + str(b.get_value())) 

p_1 = 1/(1 + T.exp(-T.dot(x, w) - b))  # probability of target being 1 
prediction = p_1 > 0.5      # prediction threshold 
xent = -y * T.log(p_1) - (1-y)*T.log(1-p_1) # cross-entropy loss function 
cost = xent.mean() + 0.01 * (w**2).sum() # cost - to be minimized 
gw, gb = T.grad(cost, [w, b]) 

#compile it 
train = theano.function(
         inputs = [x, y], 
         outputs = [prediction, xent], 
         updates = {w: w - 0.1*gw, b: b - 0.1*gb} ) 

predict = theano.function(inputs = [x], outputs = prediction) 

#train it 
for i in range (training_steps): 
    pred, err = train(D[0], D[1]) 

print("Final Model: ") 
print(str(w.get_value()) + " " + str(b.get_value())) 
print("Target values for D: " + str(D[1])) 
print("Predictions on D: " + str(D[0])) 

Tôi nghĩ mã này sẽ hoạt động tốt. Nhưng tôi nhận được một loạt lỗi:

ERROR (theano.gof.opt): Optimization failure due to: local_gpua_hgemm 
ERROR (theano.gof.opt): node: dot(x.T, Elemwise{sub,no_inplace}.0) 
ERROR (theano.gof.opt): TRACEBACK: 
ERROR (theano.gof.opt): Traceback (most recent call last): 
    File "/home/user/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 1772, in process_node 
    replacements = lopt.transform(node) 
    File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 140, in local_opt 
    new_op = maker(node, context_name) 
    File "/home/user/anaconda3/lib/python3.5/site-packages/theano/sandbox/gpuarray/opt.py", line 732, in local_gpua_hgemm 
    if nvcc_compiler.nvcc_version < '7.5': 
TypeError: unorderable types: NoneType() < str() 

Và tôi nhận được cùng một tập hợp thư nhiều lần. Sau đó, ở cuối:

File "/home/user/anaconda3/lib/python3.5/site-packages/pygpu-0.2.1-py3.5-linux-x86_64.egg/pygpu/elemwise.py", line 286, in __init__ 
    **self.flags) 
    File "pygpu/gpuarray.pyx", line 1950, in pygpu.gpuarray.GpuKernel.__cinit__ (pygpu/gpuarray.c:24214) 
    File "pygpu/gpuarray.pyx", line 467, in pygpu.gpuarray.kernel_init (pygpu/gpuarray.c:7174) 
pygpu.gpuarray.UnsupportedException: ('The following error happened while compiling the node', GpuElemwise{Composite{((-i0) - i1)}}[(0, 0)]<gpuarray>(GpuFromHost<None>.0, InplaceGpuDimShuffle{x}.0), '\n', b'Device does not support operation') 

Điều này có nghĩa là tôi không thể sử dụng GPU này hoặc tôi đã làm điều gì sai trong mã của mình. Hơn nữa, từ các lỗi, có vẻ như đã có một tìm kiếm cho nvcc. Nhưng tôi không có CUDA, tôi có opencl.

>>> import theano 
Mapped name None to device opencl0:0: Cedar 

thêm:

>>> from theano import config 
>>> config.device 
'opencl0:0' 
>>> config.cuda 
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9dee7d30> 
>>> config.nvcc 
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fba9e5967f0> 
>>> config.gpu 
<theano.configparser.AddConfigVar.<locals>.SubObj object at 0x7fbaa9f61828> 

Vậy làm thế nào để tôi đi từ đây? Có cách nào để đảm bảo clcc được tìm kiếm thay vì nvcc.

PS_1: xin chào các tác phẩm thế giới. PS_2: Hệ thống = 14.04 64 bit

Trả lời

7

OpenCL chưa được hỗ trợ bởi Theano. Do đó, chỉ hỗ trợ GPU NVIDIA.

Trạng thái của OpenCL là recorded on GitHub.

Bạn cần tắt hoạt động GPU bằng cách đặt device=cpu trong cấu hình Theano của bạn. Có nhiều cách để thực hiện việc này (tức là thông qua biến môi trường THEANO_FLAGS hoặc thông qua tệp .theanorc; see documentation).

Trước khi chạy kịch bản, hãy thử cài đặt

export THEANO_FLAGS=device=cpu,floatX=float64 

tình hình của bạn có thể cần các tùy chọn cấu hình bổ sung. Xem the documentation để biết thêm.

+0

Có, cảm ơn bạn. Tôi đã đọc vấn đề này. Nhưng tôi tìm thấy vài tài liệu tham khảo về trò chuyện đề cập đến nó có thể hoạt động. Tôi đã mở một vấn đề khác - https://github.com/Theano/Theano/issues/4112 và tôi có thể đóng góp vào việc sửa chữa nó. Nhưng chạy trên CPU nên tránh, vì nó chỉ đơn giản hóa ra là không thực tế trong việc giải quyết bất kỳ vấn đề có kích thước vừa phải. Tùy chọn khác tôi đang khám phá là OpenCL Caffe. – Adorn

Các vấn đề liên quan