提交 d43cdf28 authored 作者: Frederic Bastien's avatar Frederic Bastien

made the theano flags force_device a bool.

上级 7a32c2df
......@@ -105,9 +105,11 @@ Config Attributes
.. attribute:: force_device
String value: either 'cpu', gpu, 'gpu0', 'gpu1', 'gpu2', or 'gpu3'
Bool value: either True or False
Default False
As the attribute 'device' except that if we can't use the gpu, we raise an error.
If True, we raise an error if we can't use the specified device. If False, we fall back to the cpu.
Have precedence over the device flag.
.. attribute:: floatX
......
......@@ -46,7 +46,7 @@ You can also set the device option in the .theanorc file's ``[global]`` section.
* You can choose one specific gpu by giving device the one of those values: gpu0, gpu1, gpu2, or gpu3.
* If you have more than 4 devices you are very lucky but you'll have to modify theano's *configdefaults.py* file and define more gpu devices to choose from.
* Using the 'device=gpu*' theano flag make theano fall back to the cpu if their is a problem with the gpu.
You can use the flag 'force_device=gpu*' to have theano raise an error when we can't use the gpu.
You can use the flag 'force_device=True' to have theano raise an error when we can't use the gpu.
.. note::
There is a compatibility issue affecting some Ubuntu 9.10 users, and probably anyone using
......
......@@ -75,7 +75,7 @@ import scalar
import gradient
import gof
if config.device.startswith('gpu') or config.force_device.startswith('gpu'):
if config.device.startswith('gpu'):
import theano.sandbox.cuda
## import scalar_opt
......
......@@ -16,8 +16,8 @@ AddConfigVar('device',
)
AddConfigVar('force_device',
"Have precedence over device if not equal cpu.",
EnumStr('cpu', 'gpu',*['gpu%i'%i for i in range(4)])
"Raise an error if we can't use the specified device",
BoolParam(False)
)
AddConfigVar('mode',
......@@ -80,6 +80,10 @@ AddConfigVar('traceback.limit',
"The number of stack to trace. -1 mean all.",
IntParam(5))
AddConfigVar('experimental.mrg',
"Another random number generator that work on the gpu",
BoolParam(False))
###
### To disable some warning about old bug that are fixed now.
......
......@@ -91,8 +91,6 @@ except Exception, e:
if cuda_available:
cuda_available=device_available()
if not cuda_available:
warning('CUDA is installed, but GPU device is not available')
if cuda_available:
#check if their is an old cuda_ndarray that was loading instead of the one we compiled!
......@@ -122,6 +120,12 @@ if cuda_available:
def use(device, force=False):
global cuda_enabled
if force and not cuda_available and device.startswith('gpu'):
raise Exception("You force to use a gpu device but cuda is not installed or their is no usable gpu device")
if not cuda_available:
warning('CUDA is installed, but GPU device is not available')
return
if device == 'gpu':
pass
elif device.startswith('gpu'):
......@@ -159,6 +163,15 @@ def use(device, force=False):
'fast_run',
'inplace')
if force:
try:
#in case the device if just gpu, we check that the driver init it correctly.
cuda_ndarray.cuda_ndarray.CudaNdarray.zeros((5,5))
except (Exception, NameError), e:#NameError when no gpu present as cuda_ndarray is not loaded.
e.args+=("ERROR: GPU did not work and we told to don't use the cpu. ",)
raise
use.device_number = None
def handle_shared_float32(tf):
......@@ -173,16 +186,5 @@ def handle_shared_float32(tf):
else:
raise NotImplementedError('removing our handler')
if cuda_available and config.force_device.startswith('gpu'):
use(config.force_device, True)
elif cuda_available and config.device.startswith('gpu'):
use(config.device)
if config.force_device.startswith('gpu'):
try:
#in case the device if just gpu, we check that the driver init it correctly.
cuda_ndarray.cuda_ndarray.CudaNdarray.zeros((5,5))
except (Exception, NameError), e:#NameError when no gpu present as cuda_ndarray is not loaded.
e.args+=("ERROR: GPU did not work and we told to don't use the cpu. ",)
raise
if config.device.startswith('gpu'):
use(config.device, config.force_device)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论