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

Merge pull request #4841 from Erotemic/lint_cuda_init_indentation

Linting: Pep8 indentation, consistent quotes
...@@ -6,6 +6,7 @@ import os ...@@ -6,6 +6,7 @@ import os
import shutil import shutil
import stat import stat
import sys import sys
import textwrap
import warnings import warnings
import theano import theano
...@@ -82,10 +83,10 @@ def set_cuda_disabled(): ...@@ -82,10 +83,10 @@ def set_cuda_disabled():
cuda_path = os.path.abspath(os.path.split(__file__)[0]) cuda_path = os.path.abspath(os.path.split(__file__)[0])
cuda_ndarray_loc = os.path.join(config.compiledir, 'cuda_ndarray') cuda_ndarray_loc = os.path.join(config.compiledir, 'cuda_ndarray')
cuda_ndarray_so = os.path.join(cuda_ndarray_loc, cuda_ndarray_so = os.path.join(
'cuda_ndarray.' + get_lib_extension()) cuda_ndarray_loc, 'cuda_ndarray.' + get_lib_extension())
libcuda_ndarray_so = os.path.join(cuda_ndarray_loc, libcuda_ndarray_so = os.path.join(
'libcuda_ndarray.' + get_lib_extension()) cuda_ndarray_loc, 'libcuda_ndarray.' + get_lib_extension())
def try_import(): def try_import():
...@@ -280,22 +281,24 @@ def dnn_available(): ...@@ -280,22 +281,24 @@ def dnn_available():
dnn_available.msg = "Device not supported" dnn_available.msg = "Device not supported"
dnn_available.avail = False dnn_available.avail = False
else: else:
preambule = """ preambule = textwrap.dedent(
#include <stdio.h>
#include <cuda.h>
#include <cudnn.h>
#include <cudnn_helper.h>
""" """
#include <stdio.h>
#include <cuda.h>
#include <cudnn.h>
#include <cudnn_helper.h>
""")
body = """ body = textwrap.dedent(
cudnnHandle_t _handle = NULL; """
cudnnStatus_t err; cudnnHandle_t _handle = NULL;
if ((err = cudnnCreate(&_handle)) != CUDNN_STATUS_SUCCESS) { cudnnStatus_t err;
if ((err = cudnnCreate(&_handle)) != CUDNN_STATUS_SUCCESS) {
fprintf(stderr, "could not create cuDNN handle: %s", fprintf(stderr, "could not create cuDNN handle: %s",
cudnnGetErrorString(err)); cudnnGetErrorString(err));
return 1; return 1;
} }
""" """)
params = ["-l", "cudnn", "-I" + os.path.dirname(__file__)] params = ["-l", "cudnn", "-I" + os.path.dirname(__file__)]
if config.dnn.include_path: if config.dnn.include_path:
params.append("-I" + config.dnn.include_path) params.append("-I" + config.dnn.include_path)
...@@ -367,24 +370,26 @@ class DnnVersion(GpuOp): ...@@ -367,24 +370,26 @@ class DnnVersion(GpuOp):
return ['-Wl,-rpath,' + config.dnn.library_path] return ['-Wl,-rpath,' + config.dnn.library_path]
def c_support_code(self): def c_support_code(self):
return """ return textwrap.dedent(
#if PY_MAJOR_VERSION >= 3 """
#define PyInt_FromLong PyLong_FromLong #if PY_MAJOR_VERSION >= 3
#endif #define PyInt_FromLong PyLong_FromLong
""" #endif
""")
def make_node(self): def make_node(self):
return theano.gof.Apply(self, [], [theano.gof.Generic()()]) return theano.gof.Apply(self, [], [theano.gof.Generic()()])
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
o = outputs[0] o = outputs[0]
return """ return textwrap.dedent(
"""
#if defined(CUDNN_VERSION) #if defined(CUDNN_VERSION)
%(o)s = PyTuple_Pack(2, PyInt_FromLong(CUDNN_VERSION), PyInt_FromLong(cudnnGetVersion())); %(o)s = PyTuple_Pack(2, PyInt_FromLong(CUDNN_VERSION), PyInt_FromLong(cudnnGetVersion()));
#else #else
%(o)s = PyInt_FromLong(-1); %(o)s = PyInt_FromLong(-1);
#endif #endif
""" % locals() """) % locals()
def do_constant_folding(self, node): def do_constant_folding(self, node):
# Needed as we do not want to cache this information. # Needed as we do not want to cache this information.
...@@ -423,10 +428,11 @@ if cuda_available: ...@@ -423,10 +428,11 @@ if cuda_available:
import cuda_ndarray.cuda_ndarray import cuda_ndarray.cuda_ndarray
if cuda_ndarray_so != cuda_ndarray.cuda_ndarray.__file__: if cuda_ndarray_so != cuda_ndarray.cuda_ndarray.__file__:
_logger.warning("cuda_ndarray was loaded from %s, but Theano expected " _logger.warning("cuda_ndarray was loaded from %s, but Theano expected "
"to load it from %s. This is not expected as theano should " "to load it from %s. This is not expected as theano "
"compile it automatically for you. Do you have a directory " "should compile it automatically for you. Do you have "
"called cuda_ndarray in your LD_LIBRARY_PATH environment " "a directory called cuda_ndarray in your "
"variable? If so, please remove it as it is outdated.", "LD_LIBRARY_PATH environment variable? If so, please "
"remove it as it is outdated.",
cuda_ndarray.cuda_ndarray.__file__, cuda_ndarray.cuda_ndarray.__file__,
cuda_ndarray_so) cuda_ndarray_so)
...@@ -443,8 +449,8 @@ if cuda_available: ...@@ -443,8 +449,8 @@ if cuda_available:
ftensor3, ftensor4, ftensor3, ftensor4,
scalar, vector, matrix, row, col, scalar, vector, matrix, row, col,
tensor3, tensor4) tensor3, tensor4)
from .basic_ops import (host_from_gpu, gpu_from_host, from .basic_ops import (host_from_gpu, gpu_from_host, as_cuda_array,
as_cuda_array, as_cuda_ndarray_variable) as_cuda_ndarray_variable)
import cuda_ndarray import cuda_ndarray
from . import opt, dnn from . import opt, dnn
from .rng_curand import CURAND_RandomStreams from .rng_curand import CURAND_RandomStreams
...@@ -494,10 +500,11 @@ def use(device, ...@@ -494,10 +500,11 @@ def use(device,
raise EnvironmentError("You forced the use of gpu device %s, " raise EnvironmentError("You forced the use of gpu device %s, "
"but CUDA initialization failed " "but CUDA initialization failed "
"with error:\n%s" % ( "with error:\n%s" % (
device, cuda_initialization_error_message)) device,
cuda_initialization_error_message))
elif not nvcc_compiler.is_nvcc_available(): elif not nvcc_compiler.is_nvcc_available():
_logger.error('nvcc compiler not found on $PATH.' _logger.error("nvcc compiler not found on $PATH. "
' Check your nvcc installation and try again.') "Check your nvcc installation and try again.")
return return
elif not cuda_available: elif not cuda_available:
error_addendum = "" error_addendum = ""
...@@ -506,9 +513,9 @@ def use(device, ...@@ -506,9 +513,9 @@ def use(device,
error_addendum = (" (error: %s)" % error_addendum = (" (error: %s)" %
cuda_initialization_error_message) cuda_initialization_error_message)
except NameError: except NameError:
# cuda_initialization_error_message is not available b/c compilation failed # cuda_initialization_error_message is not available b/c compilation failed
pass pass
_logger.warning('CUDA is installed, but device %s is not available %s', _logger.warning("CUDA is installed, but device %s is not available %s",
device, error_addendum) device, error_addendum)
return return
...@@ -701,10 +708,9 @@ elif config.init_gpu_device.startswith('gpu'): ...@@ -701,10 +708,9 @@ elif config.init_gpu_device.startswith('gpu'):
"We can use the Theano flag init_gpu_device" "We can use the Theano flag init_gpu_device"
" only when the Theano flag device=='cpu'") " only when the Theano flag device=='cpu'")
_logger.warning(("GPU device %s will be initialized, and used if a GPU is " _logger.warning(("GPU device %s will be initialized, and used if a GPU is "
"needed. " "needed. However, no computation, nor shared variables, "
"However, no computation, nor shared variables, will be implicitly " "will be implicitly moved to that device. If you want "
"moved to that device. If you want that behavior, use the 'device' " "that behavior, use the 'device' flag instead."),
"flag instead."),
config.init_gpu_device) config.init_gpu_device)
use(device=config.init_gpu_device, use(device=config.init_gpu_device,
force=config.force_device, force=config.force_device,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论