def test_transfer_cuda_gpu(): import theano.sandbox.cuda as cuda_ndarray if cuda_ndarray.cuda_available is False: raise SkipTest("Can't test interaction with cuda if cuda not present") g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g') c = cuda_ndarray.CudaNdarrayType((False, False))('c') av = theano._asarray(rng.rand(5, 4), dtype='float32') gv = gpuarray.array(av) cv = cuda_ndarray.CudaNdarray(av) gvs = gv[:, ::-2] cvs = cv[:, ::-2] f = theano.function([c], gpu_from_cuda(c)) fv = f(cv) assert GpuArrayType.values_eq_approx(fv, gv) fvs = f(cvs) assert GpuArrayType.values_eq_approx(fvs, gvs) f = theano.function([g], cuda_from_gpu(g)) fv = f(gv) assert cuda_ndarray.CudaNdarrayType.values_eq_approx(fv, cv) fvs = f(gvs) assert cuda_ndarray.CudaNdarrayType.values_eq_approx(fvs, cvs)
def rand_gpuarray(*shape, **kwargs): r = rng.rand(*shape) * 2 - 1 dtype = kwargs.pop('dtype', theano.config.floatX) cls = kwargs.pop('cls', None) if len(kwargs) != 0: raise TypeError('Unexpected argument %s', kwargs.keys()[0]) return gpuarray.array(r, dtype=dtype, cls=cls)
def test_transfer_cpu_gpu(): a = T.fmatrix('a') g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g') av = numpy.asarray(rng.rand(5, 4), dtype='float32') gv = gpuarray.array(av) f = theano.function([a], gpu_from_host(a)) fv = f(av) assert GpuArrayType.values_eq(fv, gv) f = theano.function([g], host_from_gpu(g)) fv = f(gv) assert numpy.all(fv == av)
def test_transfer_strided(): # This is just to ensure that it works in theano # compyte has a much more comprehensive suit of tests to ensure correctness a = T.fmatrix('a') g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g') av = numpy.asarray(rng.rand(5, 8), dtype='float32') gv = gpuarray.array(av) av = av[:, ::2] gv = gv[:, ::2] f = theano.function([a], gpu_from_host(a)) fv = f(av) assert GpuArrayType.values_eq(fv, gv) f = theano.function([g], host_from_gpu(g)) fv = f(gv) assert numpy.all(fv == av)
def test_transfer_strided(): # This is just to ensure that it works in theano # compyte has a much more comprehensive suit of tests to ensure correctness a = T.fmatrix('a') g = GpuArrayType(dtype='float32', broadcastable=(False, False))('g') av = numpy.asarray(rng.rand(5, 8), dtype='float32') gv = gpuarray.array(av) av = av[:,::2] gv = gv[:,::2] f = theano.function([a], gpu_from_host(a)) fv = f(av) assert GpuArrayType.values_eq(fv, gv) f = theano.function([g], host_from_gpu(g)) fv = f(gv) assert numpy.all(fv == av)