Skip to content

Instantly share code, notes, and snippets.

@kaushikcfd
Created November 6, 2017 20:38
Show Gist options
  • Save kaushikcfd/d476a94622cec4e53ddde150d527a159 to your computer and use it in GitHub Desktop.
Save kaushikcfd/d476a94622cec4e53ddde150d527a159 to your computer and use it in GitHub Desktop.
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
from time import time
import loopy as lp
import pyopencl as cl
import pyopencl.array
import pyopencl.clrandom
if __name__ == '__main__':
ctx = cl.create_some_context(interactive=True)
queue = cl.CommandQueue(ctx)
knl = lp.make_kernel(
"{[i, j, ii, jj]: 0<=i,j, ii, jj<n}",
"""
out[j, i] = a[i, j]{id=transpose}
out[ii, jj] = 2*out[ii, jj]{id=double}
""")
a = np.random.randn(16, 16)
knl = lp.set_options(knl, write_cl=True)
knl = lp.add_barrier(knl, "gb1", "id:transpose", "id:double")
knl = lp.split_iname(knl, "i", 2, outer_tag="g.0", inner_tag="l.0")
knl = lp.split_iname(knl, "j", 2, outer_tag="g.1", inner_tag="l.1")
'''
knl = lp.split_iname(knl, "ii", 2, outer_tag="g.2", inner_tag="l.2")
knl = lp.split_iname(knl, "jj", 2, outer_tag="g.3", inner_tag="l.3")
'''
evt, (out,) = knl(queue, a=a)
print(la.norm(out-2*a.T))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment