Example #1
0
def test_collocation_cuda():
    rect = odl.Rectangle([0, 0], [1, 1])
    part = odl.uniform_partition_fromintv(rect, [4, 2])
    space = odl.FunctionSpace(rect)
    dspace = odl.CudaRn(part.size)

    coll_op = PointCollocation(space, part, dspace)
    interp_op = LinearInterpolation(space, part, dspace)

    values = np.arange(1, 9, dtype='float64')
    ident_values = coll_op(interp_op(values))
    assert all_almost_equal(ident_values, values)
Example #2
0
def fn(request):
    size, dtype = request.param.split()
    return odl.CudaRn(int(size), dtype=dtype)
Example #3
0
"""Speed comparison between CPU and GPU spaces."""

# Imports for common Python 2/3 codebase
from __future__ import print_function, division, absolute_import
from future import standard_library

standard_library.install_aliases()
from builtins import range

import numpy as np
import odl
from odl.util.testutils import Timer

n = 10**7
iterations = 100
device_space = odl.CudaRn(n)
host_space = odl.Rn(n)
x = np.random.rand(n)
y = np.random.rand(n)
z = np.empty(n)

x_dev = device_space.element(x)
y_dev = device_space.element(y)
z_dev = device_space.element(z)
x_host = host_space.element(x)
y_host = host_space.element(y)
z_host = host_space.element(z)


def run_test(function, message):
    with Timer('+GPU ' + message):
Example #4
0
def test_init_cuda(exponent):
    # Normal discretization of unit interval
    space = odl.FunctionSpace(odl.Interval(0, 1), out_dtype='float32')
    part = odl.uniform_partition_fromintv(space.domain, 10)
    rn = odl.CudaRn(10, exponent=exponent)
    odl.DiscreteLp(space, part, rn, exponent=exponent)
Example #5
0
# Imports for common Python 2/3 codebase
from __future__ import print_function, division, absolute_import
from future import standard_library
standard_library.install_aliases()

# Internal
import odl

print('\n\n TESTING FOR Lp SPACE \n\n')

discr = odl.uniform_discr(0, 1, 10)
odl.diagnostics.SpaceTest(discr).run_tests()

print('\n\n TESTING FOR Rn SPACE \n\n')

spc = odl.Rn(10)
odl.diagnostics.SpaceTest(spc).run_tests()


print('\n\n TESTING FOR Cn SPACE \n\n')

spc = odl.Cn(10)
odl.diagnostics.SpaceTest(spc).run_tests()


if odl.CUDA_AVAILABLE:
    print('\n\n TESTING FOR CudaRn SPACE \n\n')

    spc = odl.CudaRn(10)
    odl.diagnostics.SpaceTest(spc, eps=0.0001).run_tests()
Example #6
0
# Do some tests to compare
n = 10**7
iterations = 10

# Perform some benchmarks with Rn adn CudaRn
opt_spc = odl.Rn(n)
simple_spc = SimpleRn(n)

x, y, z = np.random.rand(n), np.random.rand(n), np.random.rand(n)
ox, oy, oz = (opt_spc.element(x.copy()), opt_spc.element(y.copy()),
              opt_spc.element(z.copy()))
sx, sy, sz = (simple_spc.element(x.copy()), simple_spc.element(y.copy()),
              simple_spc.element(z.copy()))
if odl.CUDA_AVAILABLE:
    cu_spc = odl.CudaRn(n)
    cx, cy, cz = (cu_spc.element(x.copy()), cu_spc.element(y.copy()),
                  cu_spc.element(z.copy()))

print(" lincomb:")
with Timer("SimpleRn"):
    for _ in range(iterations):
        simple_spc.lincomb(2.13, sx, 3.14, sy, out=sz)
print("result: {}".format(sz[1:5]))

with Timer("Rn"):
    for _ in range(iterations):
        opt_spc.lincomb(2.13, ox, 3.14, oy, out=oz)
print("result: {}".format(oz[1:5]))

if odl.CUDA_AVAILABLE: