Skip to content
Snippets Groups Projects
Commit 2d2fed9b authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

More hacking while chatting with Matt

parent 1455930a
Branches master
No related tags found
No related merge requests found
......@@ -38,6 +38,10 @@ class Context:
.. attribute:: target
A :class:`Target` for code generation and execution.
.. note::
*program* may not define any names starting with underscores.
"""
def __init__(self, program, bindings, target):
......@@ -116,6 +120,9 @@ class Array:
An instance of :class:`loopy.types.LoopyType` or *None* to indicate
that the type of the array is not yet known.
.. attribute:: expression
"""
def __init__(self, context, shape, dtype, expression):
......@@ -146,7 +153,12 @@ def make_sym(context, name, shape, dtype=None):
context.update_program(context.program.copy(
arguments=context.program.arguments + [arg]))
# return Array(context,
# TODO make sure "name" is not taken
v_name = prim.Variable(name)
subscripts = tuple(prim.Variable(???) for i in range(len(shape)))
return Array(context, expression=v_name[subscripts])
def zeros(context, shape, dtype):
......
import numpy as np
import pyopencl as cl
import pyopencl.clrandom
import arrayzy as az
import loopy as lp
import numpy
import numpy.linalg as la
def matvec(a, b):
matvec_knl = lp.make_kernel(
"{[i,j]: 0<=i<m and 0<=j<n}",
"out[i] = sum(j, a[i,j]*x[j])")
return az.call_kernel(matvec_knl, a=a, b=b)
def main(dims=2, order=4):
cl_ctx = cl.create_some_context()
queue = cl.CommandQueue(cl_ctx)
ctx = az.make_context(queue) # queue??
a = cl.clrandom.rand(queue, (20, 20), dtype=np.float64)
x = cl.clrandom.rand(queue, (20,), dtype=np.float64)
a_l = az.bind(ctx, "a", a, shape="n,n")
# a_l = az.bind(ctx, "A", a)
x_l = az.make_sym(ctx, "x", "n", np.float64)
result = matvec(a_l.T, matvec(a_l, x_l).store())
# result = A.T @ A @ x
a_h = a.get()
assert la.norm(result.eval(x=x).get() - a_h.T @ a_h @ x) < 1e-12
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment