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

Merge pull request #812 from nouiz/mixed

Mixed
language: python
python:
- "2.6"
# - "2.7"
# - "3.2"
# command to install dependencies
install: "pip install . --use-mirrors"
# command to run tests
script: theano-nose
\ No newline at end of file
......@@ -44,9 +44,10 @@ file and run it.
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
print 'Used the','cpu' if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
print 'Used the', 'cpu' if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
The program just computes the exp() of a bunch of random numbers.
Note that we use the `shared` function to
......@@ -100,10 +101,11 @@ after the T.exp(x) is replaced by a GPU version of exp().
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
print 'Numpy result is', numpy.asarray(r)
print 'Used the','cpu' if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
print 'Used the', 'cpu' if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
The output from this program is
......@@ -155,10 +157,11 @@ that it has the un-wanted side-effect of really slowing things down.
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
print 'Numpy result is', numpy.asarray(r)
print 'Used the','cpu' if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
print 'Used the', 'cpu' if numpy.any([isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]) else 'gpu'
Running this version of the code takes just under 0.05 seconds, over 140x faster than
the CPU implementation!
......
......@@ -7,6 +7,7 @@ This is needed as we need to have parsed the previous
import os
import logging
import subprocess
import tempfile
import theano
from theano.configparser import (
......@@ -63,16 +64,19 @@ int main( int argc, const char* argv[] )
}
}
"""
p = os.path.join(config.compiledir, 'test_omp.c')
f = open(p, 'w')
f.write(code)
f.close()
p = subprocess.Popen(['g++', '-fopenmp', p], stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
p.wait()
if p.returncode != 0:
default_openmp = False
fd, path = tempfile.mkstemp(suffix='.c', prefix='test_omp_')
try:
os.write(fd, code)
os.close(fd)
proc = subprocess.Popen(['g++', '-fopenmp', path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
proc.wait()
if proc.returncode != 0:
default_openmp = False
finally:
os.remove(path)
except OSError, e:
default_openmp = False
......
......@@ -14,7 +14,7 @@ files=["/tmp/do_nightly_build_theano", "/tmp/do_nightly_build_pylearn",
"/tmp/do_nightly_build_deeplearning", "/tmp/do_nightly_build_pylearn2",
"/tmp/do_nightly_build_theano_python2.4"]
msgs=['Theano buildbot', 'Pylearn buildbot', 'Deep Learning Tutorial buildbot',
'Pylearn2 buildbot', 'Theano Python2.4']
'Pylearn2 buildbot', 'Theano Python2.4 buildbot']
print files
print msgs
......
......@@ -79,6 +79,19 @@ class HostFromGpu(GpuOp):
def infer_shape(self, node, xshp):
return xshp
def c_code(self, node, name, inputs, outputs, sub):
inp = inputs[0]
out = outputs[0]
fail = sub['fail']
return """
%(out)s = (PyArrayObject *) CudaNdarray_CreateArrayObj(%(inp)s);
if(!%(out)s)
%(fail)s;
""" % locals()
def c_code_cache_version(self):
return (1,)
host_from_gpu = HostFromGpu()
......
......@@ -300,10 +300,6 @@ class NVCC_compiler(object):
finally:
os.chdir(orig_dir)
if nvcc_stdout:
# this doesn't happen to my knowledge
print >> sys.stderr, "DEBUG: nvcc STDOUT", nvcc_stdout
for eline in nvcc_stderr.split('\n'):
if not eline:
continue
......@@ -334,11 +330,16 @@ class NVCC_compiler(object):
except Exception:
pass
print >> sys.stderr, l
print nvcc_stdout
raise Exception('nvcc return status', p.returncode,
'for cmd', ' '.join(cmd))
elif config.cmodule.compilation_warning and nvcc_stdout:
print nvcc_stdout
if nvcc_stdout:
# this doesn't happen to my knowledge
print >> sys.stderr, "DEBUG: nvcc STDOUT", nvcc_stdout
#touch the __init__ file
file(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
......
......@@ -2183,6 +2183,11 @@ class MaxAndArgmax(Op):
def make_node(self, x, axis=None):
x = _as_tensor_variable(x)
if isinstance(axis, Variable):
if not isinstance(axis, Constant):
raise TypeError("MaxAndArgmax need a constant axis")
axis = [axis.data]
if isinstance(axis, int):
axis = [axis]
elif isinstance(axis, (tuple, list)):
......@@ -2192,6 +2197,7 @@ class MaxAndArgmax(Op):
assert axis == range(x.type.ndim), (
"MaxAndArgmax does not support multiple"
" axes. the max fct supports it.")
# we make the axis all positive to make the infer_shape work
# with negative axis
if x.type.ndim > 0 and axis is not None:
......
......@@ -1790,7 +1790,8 @@ class T_max_and_argmax(unittest.TestCase):
data = rand(2, 3)
n = as_tensor_variable(data)
for (axis, np_axis) in [(-1, -1), (0, 0), (1, 1), (None, None),
([0, 1], None), ([1, 0], None)]:
([0, 1], None), ([1, 0], None),
(constant(0), 0)]:
v, i = eval_outputs(max_and_argmax(n, axis))
assert i.dtype == 'int64'
self.assertTrue(numpy.all(v == numpy.max(data, np_axis)))
......
......@@ -800,16 +800,17 @@ class T_using_gpu(unittest.TestCase):
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]):
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print 'Used the cpu'
else:
print 'Used the gpu'
if theano.config.device.find('gpu') > -1:
assert not numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()])
else:
assert numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()])
assert numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()])
......@@ -831,15 +832,16 @@ class T_using_gpu(unittest.TestCase):
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
print 'Numpy result is', numpy.asarray(r)
if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]):
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print 'Used the cpu'
else:
print 'Used the gpu'
assert not numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()])
assert not numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()])
......@@ -865,15 +867,16 @@ class T_using_gpu(unittest.TestCase):
t0 = time.time()
for i in xrange(iters):
r = f()
print 'Looping %d times took'%iters, time.time() - t0, 'seconds'
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', r
print 'Numpy result is', numpy.asarray(r)
if numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()]):
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print 'Used the cpu'
else:
print 'Used the gpu'
assert not numpy.any( [isinstance(x.op,T.Elemwise) for x in f.maker.fgraph.toposort()])
assert not numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()])
class T_fibby(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论