Created
June 2, 2017 16:46
-
-
Save inducer/cc4e3e30f3d4c7a3f33c35246ff00cab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import loopy as lp | |
import pyopencl as cl | |
import numpy as np | |
from loopy.kernel.data import temp_var_scope as scopes | |
ctx = cl.create_some_context() | |
queue = cl.CommandQueue(ctx) | |
limit_max = 10 | |
k_lim = 5 | |
l_lim = 3 | |
ref_knl = lp.make_kernel([ | |
'{[k]: 0 <= k < k_lim}', | |
'{[l]: 0 <= l < l_lim}', | |
'{[i,j]: start <= i,j < end}', | |
], | |
""" | |
for k | |
for l | |
<> start = limits[k, l] | |
<> end = limits[k + 1, l] | |
out[k, l] = 1 | |
for j | |
for i | |
out[k, l] = out[k, l] * a[i, j] | |
end | |
end | |
end | |
end | |
""", | |
[lp.GlobalArg('a', shape=(limit_max, limit_max), dtype=np.float64), | |
lp.TemporaryVariable('limits', shape=(k_lim * 2, l_lim), dtype=np.int64, | |
initializer=np.random.randint(0, high=limit_max, size=(k_lim * 2, l_lim)), | |
scope=scopes.PRIVATE, read_only=True), | |
lp.GlobalArg('out', shape=(k_lim, l_lim))] | |
) | |
ref_knl = lp.fix_parameters(ref_knl, k_lim=k_lim, l_lim=l_lim) | |
print(ref_knl) | |
print(lp.generate_code(ref_knl)[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment