提交 cc574b89 authored 作者: lamblin's avatar lamblin

Merge pull request #1366 from nouiz/unuse_gpu

Add theano.sandbox.cuda.unuse()
......@@ -66,6 +66,16 @@ multiple time in a DB. Tryed to register "%s" again under the new name "%s".
obj, tag)
self.__db__[tag].add(obj)
def remove_tags(self, name, *tags):
obj = self.__db__[name]
assert len(obj) == 1
obj = obj.copy().pop()
for tag in tags:
if tag in self._names:
raise ValueError('The tag of the object collides with a name.',
obj, tag)
self.__db__[tag].remove(obj)
def __query__(self, q):
if not isinstance(q, Query):
raise TypeError('Expected a Query.', q)
......
......@@ -383,11 +383,6 @@ def use(device,
" the Theano mailing list to tell us about"
" this new GPU as we don't know any with"
" this property")
if move_shared_float32_to_gpu:
handle_shared_float32(True)
if enable_cuda:
cuda_enabled = True
if config.print_active_device:
print >> sys.stderr, "Using gpu device %d: %s" % (
......@@ -412,11 +407,17 @@ def use(device,
" No fallback to the cpu or other gpu device."),)
raise
elif use.device_number != device:
elif use.device_number != device and device != 'gpu':
_logger.warning(("Ignoring call to use(%s), GPU number %i "
"is already in use."),
str(device), use.device_number)
if move_shared_float32_to_gpu:
handle_shared_float32(True)
if enable_cuda:
cuda_enabled = True
if default_to_move_computation_to_gpu:
optdb.add_tags('gpu_opt',
'fast_run',
......@@ -437,15 +438,36 @@ def use(device,
use.device_number = None
def unuse():
"""
This undo what was done by the call to
use('gpu[0-9]', default_to_move_computation_to_gpu=True,
move_shared_float32_to_gpu=True,
enable_cuda=True)
This is used in Pylearn2 tests to enable/disable the GPU when needed.
After this call, the rest of Theano think the GPU shouldn't be used by default.
"""
global cuda_enabled
cuda_enabled = False
handle_shared_float32(False)
optdb.remove_tags('gpu_opt',
'fast_run',
'inplace')
optdb.remove_tags('gpu_after_fusion',
'fast_run',
'inplace')
def handle_shared_float32(tf):
"""Set the default shared type for float32 tensor to CudaNdarrayType
This function is intended to be called from use(gpu_index), not directly.
"""
if tf:
import theano.compile
theano.compile.shared_constructor(float32_shared_constructor)
else:
theano.compile.shared_constructor(float32_shared_constructor, True)
assert (float32_shared_constructor not in
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论