提交 56135c87 authored 作者: Frederic's avatar Frederic

Lift GpuAllocEmpty

上级 a9655e21
......@@ -779,6 +779,10 @@ class Op(utils.object2, PureOp, CLinkerOp):
def _props(self):
return tuple(getattr(self, a) for a in self.__props__)
def _props_dict(self):
return dict([(a, getattr(self, a))
for a in self.__props__])
def __hash__(self):
if hasattr(self, '__props__'):
return hash((type(self), self._props()))
......
......@@ -273,6 +273,13 @@ def local_gpuaalloc(node, context_name):
return GpuAlloc(context_name)(*node.inputs)
@register_opt('fast_compile')
@op_lifter([tensor.AllocEmpty])
def local_gpuaallocempty(node, context_name):
return GpuAllocEmpty(context_name=context_name,
**node.op._props_dict())(*node.inputs)
@register_opt()
@local_optimizer([GpuAlloc])
def local_gpualloc_memset_0(node):
......
......@@ -9,7 +9,8 @@ from theano.tensor.tests import test_basic
import theano.sandbox.gpuarray
from .. import basic_ops
from ..type import GpuArrayType, gpuarray_shared_constructor, get_context
from ..basic_ops import GpuAlloc, GpuReshape, GpuFromHost, host_from_gpu
from ..basic_ops import (
GpuAlloc, GpuAllocEmpty, GpuReshape, GpuFromHost, host_from_gpu)
from ..elemwise import GpuCAReduceCuda, GpuCAReduceCPY, GpuElemwise
from ..subtensor import GpuSubtensor
......@@ -151,6 +152,29 @@ def test_local_gpualloc_memset_0():
assert (numpy.asarray(f(2)) == 1).all()
def test_local_gpualloc_empty():
i = theano.tensor.iscalar()
ii = theano.tensor.iscalar()
# Test with vector
a = tensor.AllocEmpty('float32')(i)
f = theano.function([i], a, mode=mode_with_gpu)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, GpuAllocEmpty)
# This return not initilized data, so we can only check the shape
assert f(3).shape == (3,)
# Test with matrix
a = tensor.AllocEmpty('float32')(i, ii)
f = theano.function([i, ii], a, mode=mode_with_gpu)
topo = f.maker.fgraph.toposort()
assert len(topo) == 2
assert isinstance(topo[0].op, GpuAllocEmpty)
# This return not initilized data, so we can only check the shape
assert f(3, 4).shape == (3, 4)
def test_rebroadcast():
d = numpy.random.rand(10, 10).astype('float32')
v = theano.tensor.fmatrix()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论