提交 2dfec943 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3125 from harlouci/flake8_v7

Flake8 misc
......@@ -7,13 +7,6 @@
# a,b scalar
from __future__ import print_function
s = """
result for shapes=(2000,2000) and iters=100
GTX 470 7.22s
GTX 285, 6.84s
GTX 480 5.83s
"""
import os
import sys
import time
......@@ -52,7 +45,7 @@ def execute(execute=True, verbose=True, M=2000, N=2000, K=2000,
print(' OMP_NUM_THREADS=', os.getenv('OMP_NUM_THREADS'))
print(' GOTO_NUM_THREADS=', os.getenv('GOTO_NUM_THREADS'))
print()
print ('Numpy config: (used when the Theano flag'
print('Numpy config: (used when the Theano flag'
' "blas.ldflags" is empty)')
numpy.show_config()
print('Numpy dot module:', numpy.dot.__module__)
......@@ -306,7 +299,6 @@ if __name__ == "__main__":
print()
print('Total execution time: %.2fs on %s.' % (t, impl))
print()
print ('Try to run this script a few times. Experience shows that'
print('Try to run this script a few times. Experience shows that'
' the first time is not as fast as followings calls. The'
' difference is not big, but consistent.')
from __future__ import print_function
import six.moves.cPickle as pickle
import os, sys
import os
import sys
import theano
from six import iteritems, itervalues
......@@ -90,6 +92,6 @@ useless = total - uniq
print("mod.{cpp,cu} total:", total)
print("mod.{cpp,cu} uniq:", uniq)
print("mod.{cpp,cu} with more than 1 copy:", more_than_one)
print("mod.{cpp,cu} useless:", useless, float(useless)/total*100, "%")
print("mod.{cpp,cu} useless:", useless, float(useless) / total * 100, "%")
print("nb directory", len(dirs))
......@@ -7,15 +7,20 @@ WARNING: In the test of this file there is a transpose that is used...
So there can be problem with shape and stride order...
"""
import six
try:
import cudamat
cudamat_available = True
import theano.sandbox.cuda as cuda
if cuda.cuda_available == False:
if cuda.cuda_available is False:
raise ImportError('Optional theano package cuda disabled')
if six.PY3:
long = int
def cudandarray_to_cudamat(x, copyif=False):
""" take a CudaNdarray and return a cudamat.CUDAMatrix object.
......@@ -43,7 +48,7 @@ try:
# Check if it is c contiguous
size = 1
c_contiguous = True
for i in range(x.ndim-1, -1, -1):
for i in range(x.ndim - 1, -1, -1):
if x.shape[i] == 1:
continue
if x._strides[i] != size:
......@@ -73,11 +78,10 @@ try:
cm_mat.data_device = ctypes.cast(x.gpudata, ctypes.POINTER(ctypes.c_float))
px = cudamat.CUDAMatrix(cm_mat)
px._base = x # x won't be __del__'ed as long as px is around.
px.mat_on_host = False # let cudamat know that we don't have a numpy
# array attached.
# let cudamat know that we don't have a numpy array attached.
px.mat_on_host = False
return px
def cudamat_to_cudandarray(x):
......@@ -91,7 +95,7 @@ try:
else:
strides = [1]
for i in x.shape[::-1][:-1]:
strides.append(strides[-1]*i)
strides.append(strides[-1] * i)
strides = tuple(strides[::-1])
import ctypes
......
......@@ -57,7 +57,7 @@ def make_auth_header():
def post_issue_comment(project, num, body):
url = 'https://api.github.com/repos/{project}/issues/{num}/comments'.format(project=project, num=num)
payload = json.dumps({'body': body})
r = requests.post(url, data=payload, headers=make_auth_header())
requests.post(url, data=payload, headers=make_auth_header())
def post_gist(content, description='', filename='file', auth=False):
......@@ -84,13 +84,13 @@ def get_pull_request(project, num, github_api=3):
github_api : version of github api to use
"""
if github_api == 2 :
if github_api == 2:
url = "http://github.com/api/v2/json/pulls/{project}/{num}".format(project=project, num=num)
elif github_api == 3:
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
response = requests.get(url)
response.raise_for_status()
if github_api == 2 :
if github_api == 2:
return json.loads(response.text)['pull']
return json.loads(response.text)
......@@ -100,12 +100,12 @@ def get_pulls_list(project, github_api=3):
github_api : version of github api to use
"""
if github_api == 3 :
if github_api == 3:
url = "https://api.github.com/repos/{project}/pulls".format(project=project)
else :
else:
url = "http://github.com/api/v2/json/pulls/{project}".format(project=project)
response = requests.get(url)
response.raise_for_status()
if github_api == 2 :
if github_api == 2:
return json.loads(response.text)['pulls']
return json.loads(response.text)
......@@ -2,6 +2,8 @@
This code can only work if gnumpy and theano are initialized on the
same gpu as theano.
"""
import six
from six.moves import reduce
try:
......@@ -12,9 +14,12 @@ try:
___const_garray = gnumpy.rand(1)
import theano.sandbox.cuda as cuda
if cuda.cuda_available == False:
if cuda.cuda_available is False:
raise ImportError('Optional theano package cuda disabled')
if six.PY3:
long = int
def cudandarray_to_garray(x, copyif=False):
""" take a CudaNdarray and return a gnumpy.garray object.
......@@ -38,7 +43,7 @@ try:
# Check if it is c contiguous
size = 1
c_contiguous = True
for i in range(x.ndim-1, -1, -1):
for i in range(x.ndim - 1, -1, -1):
if x.shape[i] == 1:
continue
if x._strides[i] != size:
......@@ -57,7 +62,7 @@ try:
# a cudamat object with no data_host.
cm_mat = cudamat.cudamat()
cm_mat.size[0] = reduce(lambda x, y: x*y, x.shape, 1)
cm_mat.size[0] = reduce(lambda x, y: x * y, x.shape, 1)
cm_mat.size[1] = 1
cm_mat.on_host = 0
cm_mat.on_device = 1
......@@ -72,8 +77,8 @@ try:
px._base = x # x won't be freed if the cudamat object isn't freed.
px.mat_on_host = False # let cudamat know that we don't have a numpy
# array attached.
# let cudamat know that we don't have a numpy array attached.
px.mat_on_host = False
# Note how gnumpy tracks its cudamat objects: it moves things to the
# _cmsReuseCache when the gnumpy array is deleted, thus the arrays
......@@ -100,7 +105,7 @@ try:
else:
strides = [1]
for i in x.shape[::-1][:-1]:
strides.append(strides[-1]*i)
strides.append(strides[-1] * i)
strides = strides[::-1]
for i in range(len(strides)):
if x.shape[i] == 1:
......
from __future__ import print_function
import time
import numpy
......@@ -13,8 +14,12 @@ print(f1.maker.fgraph.toposort())
print(f2.maker.fgraph.toposort())
for i in [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]:
o = numpy.zeros(i, dtype='float32')
t0 = time.time(); f1(o); t1 = time.time();
tf1 = t1-t0
t0 = time.time(); f2(); t1 = time.time();
t0 = time.time()
f1(o)
t1 = time.time()
tf1 = t1 - t0
t0 = time.time()
f2()
t1 = time.time()
print("%8i %6.1f ns %7.1f ns"%(i, tf1*1e6, (t1-t0)*1e6))
print("%8i %6.1f ns %7.1f ns" % (i, tf1 * 1e6, (t1 - t0) * 1e6))
......@@ -3,8 +3,6 @@ Function to detect memory sharing for ndarray AND sparse type AND CudaNdarray.
numpy version support only ndarray.
"""
__docformat__ = "restructuredtext en"
import numpy
from theano.tensor.basic import TensorType
......@@ -20,6 +18,8 @@ except ImportError:
return False
from theano.sandbox import cuda
from theano.sandbox import gpuarray
if cuda.cuda_available:
from theano.sandbox.cuda.type import CudaNdarrayType
......@@ -29,8 +29,9 @@ else:
def _is_cuda(a):
return False
__docformat__ = "restructuredtext en"
from theano.sandbox import gpuarray
if gpuarray.pygpu:
def _is_gpua(a):
return isinstance(a, gpuarray.pygpu.gpuarray.GpuArray)
......
from __future__ import print_function
from collections import MutableSet
from theano.compat import OrderedDict
import types
import weakref
from six import string_types
......@@ -37,7 +38,7 @@ def check_deterministic(iterable):
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# {{{ http://code.activestate.com/recipes/576696/ (r5)
import weakref
class Link(object):
# This make that we need to use a different pickle protocol
......@@ -61,6 +62,7 @@ class Link(object):
if len(state) == 3:
self.key = state[2]
class OrderedSet(MutableSet):
'Set the remembers the order elements were added'
# Big-O running times for all methods are the same as for regular sets.
......
......@@ -33,16 +33,14 @@ from theano.sandbox.cuda.basic_ops import (as_cuda_ndarray_variable,
from theano.sandbox.cuda.opt import gpu_seqopt
from theano.tensor.utils import hash_from_dict
from . import pycuda_init
if not pycuda_init.pycuda_available:
raise Exception("No pycuda available. You can't load pycuda_example.py")
import pycuda
from pycuda.elementwise import ElementwiseKernel
from pycuda.compiler import SourceModule
from pycuda.tools import VectorArg
import pycuda.gpuarray
from . import pycuda_init
if not pycuda_init.pycuda_available:
raise Exception("No pycuda available. You can't load pycuda_example.py")
def _replace_npy_types(c_arg):
c_arg = c_arg.replace('npy_float32', 'float')
......@@ -235,12 +233,11 @@ class PycudaElemwiseSourceModuleOp(GpuOp):
c_code = self.scalar_op.c_code(out_node, "some_name",
tuple([n + "[i]" for n in in_name]),
tuple(n + "[i]" for n in out_name), {})
c_code_param = ", ".join([
_replace_npy_types(var.type.dtype_specs()[1]) + " *" + name
c_code_param = ", ".join(
[_replace_npy_types(var.type.dtype_specs()[1]) + " *" + name
for var, name in chain(izip(inputs, in_name),
izip(out_node.outputs,
out_name))
] + ["int size"])
izip(out_node.outputs, out_name))] +
["int size"])
mod = SourceModule("""
__global__ void %s(%s)
{
......@@ -329,8 +326,8 @@ class PycudaElemwiseSourceModuleMakeThunkOp(Op):
c_code_param = ", ".join(
[_replace_npy_types(var.type.dtype_specs()[1]) + " *" + name
for var, name in chain(izip(node.inputs, in_name),
izip(node.outputs, out_name))]
+ ["int size"])
izip(node.outputs, out_name))] +
["int size"])
mod = SourceModule("""
__global__ void %s(%s)
......@@ -363,7 +360,7 @@ class PycudaElemwiseSourceModuleMakeThunkOp(Op):
else:
grid = (1, 1)
block = (inputs[0][0].shape[0], inputs[0][0].shape[1], 1)
out = pycuda_fct(inputs[0][0], inputs[1][0], z[0],
pycuda_fct(inputs[0][0], inputs[1][0], z[0],
numpy.intc(inputs[1][0].size), block=block,
grid=grid)
thunk.inputs = inputs
......@@ -393,12 +390,12 @@ def local_pycuda_gpu_elemwise(node):
pycuda_optimizer.register("local_pycuda_gpu_elemwise",
local_pycuda_gpu_elemwise)
"""
@local_optimizer([GpuElemwise])
def local_pycuda_gpu_elemwise_kernel(node):
"""
""
GpuElemwise -> PycudaElemwiseKernelOp
"""
""
if isinstance(node.op, GpuElemwise):
if not any([any(i.type.broadcastable) for i in node.inputs]):
new_op = PycudaElemwiseKernelOp(node.op.scalar_op,
......@@ -408,3 +405,4 @@ def local_pycuda_gpu_elemwise_kernel(node):
pycuda_optimizer.register("local_pycuda_gpu_elemwise_kernel",
local_pycuda_gpu_elemwise_kernel, 1.5)
"""
import numpy
import pycuda.gpuarray
from theano.sandbox import cuda
if cuda.cuda_available == False:
if cuda.cuda_available is False:
raise ImportError('Optional theano package cuda disabled')
......@@ -29,7 +28,7 @@ def to_gpuarray(x, copyif=False):
# Check if it is c contiguous
size = 1
c_contiguous = True
for i in range(x.ndim-1, -1, -1):
for i in range(x.ndim - 1, -1, -1):
if x.shape[i] == 1:
continue
if x._strides[i] != size:
......@@ -59,7 +58,7 @@ def to_cudandarray(x):
else:
strides = [1]
for i in x.shape[::-1][:-1]:
strides.append(strides[-1]*i)
strides.append(strides[-1] * i)
strides = tuple(strides[::-1])
ptr = int(x.gpudata) # in pycuda trunk, y.ptr also works, which is a little cleaner
z = cuda.from_gpu_pointer(ptr, x.shape, strides, x)
......
......@@ -2,12 +2,12 @@
Helper function to safely convert an array to a new data type.
"""
__docformat__ = "restructuredtext en"
import numpy
import theano
__docformat__ = "restructuredtext en"
def _asarray(a, dtype, order=None):
"""Convert the input to a Numpy array.
......@@ -45,11 +45,13 @@ def _asarray(a, dtype, order=None):
return rval.view(dtype=dtype)
else:
# Unexpected mismatch: better know what is going on!
raise TypeError('numpy.array did not return the data type we '
raise TypeError(
'numpy.array did not return the data type we '
'asked for (%s %s #%s), instead it returned type '
'%s %s #%s: function '
'theano._asarray may need to be modified to handle this '
'data type.' %
(dtype, dtype.str, dtype.num, rval.dtype, rval.str, rval.dtype.num))
(dtype, dtype.str, dtype.num, rval.dtype, rval.str,
rval.dtype.num))
else:
return rval
import warnings
from six.moves import xrange
......@@ -26,7 +25,8 @@ def render_string(string, sub):
finalCode = string[0:i] % sub
except Exception as F:
if str(F) == str(E):
raise Exception(string[0:i]+"<<<< caused exception "+str(F))
raise Exception(
string[0:i] + "<<<< caused exception " + str(F))
i += 1
assert False
return finalCode
......@@ -35,7 +35,7 @@ def render_string(string, sub):
def pretty_format(string):
lines = string.split('\n')
lines = [ strip_leading_white_space(line) for line in lines ]
lines = [strip_leading_white_space(line) for line in lines]
indent = 0
for i in xrange(len(lines)):
......@@ -43,7 +43,7 @@ def pretty_format(string):
if indent < 0:
indent = 0
#
lines[i] = (' '*indent) + lines[i]
lines[i] = (' ' * indent) + lines[i]
indent += lines[i].count('{')
#
......
......@@ -184,20 +184,6 @@ whitelist_flake8 = [
"scan_module/scan_opt.py",
"scan_module/tests/test_scan.py",
"scan_module/tests/test_scan_opt.py",
"misc/elemwise_openmp_speedup.py",
"misc/gh_api.py",
"misc/check_blas.py",
"misc/latence_gpu_transfert.py",
"misc/cudamat_utils.py",
"misc/pycuda_utils.py",
"misc/pycuda_example.py",
"misc/ordered_set.py",
"misc/strutil.py",
"misc/gnumpy_utils.py",
"misc/may_share_memory.py",
"misc/safe_asarray.py",
"misc/pycuda_init.py",
"misc/check_duplicate_key.py",
"misc/tests/test_may_share_memory.py",
"misc/tests/test_pycuda_theano_simple.py",
"misc/tests/test_gnumpy_utils.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论