Newer
Older
Andreas Klöckner
committed
print lp.CompiledKernel(ctx, knl).get_highlighted_code()
def test_arg_guessing(ctx_factory):
ctx = ctx_factory()
knl = lp.make_kernel(ctx.devices[0], [
"{[i,j]: 0<=i,j<n }",
],
"""
a = 1.5 + sum((i,j), i*j)
b[i, j] = i*j
c[i+j, j] = b[j,i]
""",
assumptions="n>=1")
print knl
print lp.CompiledKernel(ctx, knl).get_highlighted_code()
def test_arg_guessing_with_reduction(ctx_factory):
#logging.basicConfig(level=logging.DEBUG)
ctx = ctx_factory()
knl = lp.make_kernel(ctx.devices[0], [
"{[i,j]: 0<=i,j<n }",
],
"""
a = 1.5 + sum((i,j), i*j)
d = 1.5 + sum((i,j), b[i,j])
b[i, j] = i*j
c[i+j, j] = b[j,i]
""",
assumptions="n>=1")
print knl
print lp.CompiledKernel(ctx, knl).get_highlighted_code()
# }}}
def test_nonlinear_index(ctx_factory):
ctx = ctx_factory()
knl = lp.make_kernel(ctx.devices[0], [
"{[i,j]: 0<=i,j<n }",
],
"""
a[i*i] = 17
""",
[
lp.GlobalArg("a", shape="n"),
lp.ValueArg("n"),
],
assumptions="n>=1")
print knl
print lp.CompiledKernel(ctx, knl).get_highlighted_code()
def test_triangle_domain(ctx_factory):
ctx = ctx_factory()
knl = lp.make_kernel(ctx.devices[0], [
"{[i,j]: 0<=i,j<n and i <= j}",
],
"a[i,j] = 17",
assumptions="n>=1")
print knl
print lp.CompiledKernel(ctx, knl).get_highlighted_code()
def test_array_with_offset(ctx_factory):
ctx = ctx_factory()
queue = cl.CommandQueue(ctx)
n = 5
knl = lp.make_kernel(ctx.devices[0], [
"{[i,j]: 0<=i<n and 0<=j<m }",
],
"""
b[i,j] = 2*a[i,j]
""",
assumptions="n>=1 and m>=1",
default_offset=lp.auto)
cknl = lp.CompiledKernel(ctx, knl)
a_full = cl.clrandom.rand(queue, (n, n), np.float64)
a = a_full[3:10]
print cknl.get_highlighted_code({"a": a.dtype})
evt, (b,) = cknl(queue, a=a)
import numpy.linalg as la
assert la.norm(b.get() - 2*a.get()) < 1e-13
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
from py.test.cmdline import main
main([__file__])
# vim: foldmethod=marker