Example #1
0
def test_alloc_memset_0():
    i = tensor.iscalar()
    z = numpy.zeros((1,), dtype='float32')
    o = numpy.ones((1,), dtype='float32')
    ones = numpy.ones((2,), dtype='float32')

    # Test with 0
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(z)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc) and topo[0].op.memset_0
    assert (numpy.asarray(f(6)) == 0).all()

    # Test with 1
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(o)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc)
    assert not topo[0].op.memset_0
    assert (numpy.asarray(f(6)) == 1).all()

    # Test with 1, 1
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(ones)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc)
    assert not topo[0].op.memset_0
    assert (numpy.asarray(f(2)) == 1).all()
Example #2
0
def test_alloc_memset_0():
    i = tensor.iscalar()
    z = numpy.zeros((1, ), dtype='float32')
    o = numpy.ones((1, ), dtype='float32')
    ones = numpy.ones((2, ), dtype='float32')

    # Test with 0
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(z)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc) and topo[0].op.memset_0
    assert (numpy.asarray(f(6)) == 0).all()

    # Test with 1
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(o)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc)
    assert not topo[0].op.memset_0
    assert (numpy.asarray(f(6)) == 1).all()

    # Test with 1, 1
    a = basic_ops.gpu_alloc(cuda.gpu_from_host(tensor.constant(ones)), i)
    f = theano.function([i], a, mode=mode_with_gpu)
    topo = f.maker.fgraph.toposort()
    assert len(topo) == 1
    assert isinstance(topo[0].op, basic_ops.GpuAlloc)
    assert not topo[0].op.memset_0
    assert (numpy.asarray(f(2)) == 1).all()
Example #3
0
    def setUp(self):
        super(Test_local_elemwise_alloc, self).setUp()
        self.fast_run_mode = mode_with_gpu

        # self.vec = tensor.vector('vec', dtype=dtype)
        # self.mat = tensor.matrix('mat', dtype=dtype)
        # self.tens = tensor.tensor3('tens', dtype=dtype)

        # self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        # self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)

        self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)
        self.alloc_w_dep_tens = basic_ops.gpu_alloc(
            self.vec,
            self.tens.shape[0],
            self.tens.shape[1]
        )
        self.tv_wo_dep = basic_ops.gpu_alloc(self.vec, 5, 5)
        self.tm_wo_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.s = tensor.iscalar('s')
        self.tv_w_dep = basic_ops.gpu_alloc(self.vec, self.s, self.s)
        self.tm_w_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.row = tensor.row(dtype=self.dtype)
        self.o = basic_ops.gpu_alloc(self.row, 5, 5)
Example #4
0
    def setUp(self):
        super(Test_local_elemwise_alloc, self).setUp()
        self.fast_run_mode = mode_with_gpu

        # self.vec = tensor.vector('vec', dtype=dtype)
        # self.mat = tensor.matrix('mat', dtype=dtype)
        # self.tens = tensor.tensor3('tens', dtype=dtype)

        # self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        # self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)

        self.alloc_wo_dep = basic_ops.gpu_alloc(self.vec, 2, 2)
        self.alloc_w_dep = basic_ops.gpu_alloc(self.vec, *self.mat.shape)
        self.alloc_w_dep_tens = basic_ops.gpu_alloc(
            self.vec,
            self.tens.shape[0],
            self.tens.shape[1]
        )
        self.tv_wo_dep = basic_ops.gpu_alloc(self.vec, 5, 5)
        self.tm_wo_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.s = tensor.iscalar('s')
        self.tv_w_dep = basic_ops.gpu_alloc(self.vec, self.s, self.s)
        self.tm_w_dep = basic_ops.gpu_alloc(self.mat, 5, 5, 5)
        self.row = tensor.row(dtype=self.dtype)
        self.o = basic_ops.gpu_alloc(self.row, 5, 5)