提交 172c047c authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: GitHub

Merge pull request #5870 from lamblin/fix_5869

Prevent gpu initialization when not required
...@@ -8,7 +8,8 @@ if theano.gpuarray.pygpu is None: ...@@ -8,7 +8,8 @@ if theano.gpuarray.pygpu is None:
raise SkipTest("pygpu not installed") raise SkipTest("pygpu not installed")
if (not theano.gpuarray.pygpu_activated and if (not theano.gpuarray.pygpu_activated and
not theano.config.init_gpu_device.startswith('gpu')): not theano.config.init_gpu_device.startswith('gpu') and
not theano.config.force_device):
theano.gpuarray.init_dev('cuda') theano.gpuarray.init_dev('cuda')
if not theano.gpuarray.pygpu_activated: if not theano.gpuarray.pygpu_activated:
......
...@@ -6,15 +6,10 @@ import theano ...@@ -6,15 +6,10 @@ import theano
from theano import tensor, config, Apply, Op from theano import tensor, config, Apply, Op
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from .config import mode_with_gpu, test_ctx_name
from ..basic_ops import CGpuKernelBase from ..basic_ops import CGpuKernelBase
from ..type import GpuArrayType, get_context from ..type import GpuArrayType, get_context
from pygpu.gpuarray import dtype_to_typecode
# This is an implementation to test that CGpuKernelBase works and also # This is an implementation to test that CGpuKernelBase works and also
# to use as an example in the docs. It is not used for user graphs. # to use as an example in the docs. It is not used for user graphs.
class GpuEye(CGpuKernelBase, Op): class GpuEye(CGpuKernelBase, Op):
...@@ -58,10 +53,16 @@ class GpuEye(CGpuKernelBase, Op): ...@@ -58,10 +53,16 @@ class GpuEye(CGpuKernelBase, Op):
for i in xrange(2)] for i in xrange(2)]
def get_op_params(self): def get_op_params(self):
from pygpu.gpuarray import dtype_to_typecode
return [('TYPECODE', str(dtype_to_typecode(self.dtype)))] return [('TYPECODE', str(dtype_to_typecode(self.dtype)))]
def test_cgpukernelbase(): def test_cgpukernelbase():
# Import inside the function to prevent the back-end from being
# initialized when reloading the GpuEye object from cache.
from .config import mode_with_gpu, test_ctx_name
op = GpuEye(dtype='int32', context_name=test_ctx_name) op = GpuEye(dtype='int32', context_name=test_ctx_name)
f = theano.function([], op(4, 5), mode=mode_with_gpu) f = theano.function([], op(4, 5), mode=mode_with_gpu)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论