From 535a8755cdbd73f2467d813f67b1c53a3bb16a27 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 27 Mar 2018 01:23:58 -0500 Subject: [PATCH] Added a test for slice --- test/test_transform.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/test_transform.py b/test/test_transform.py index b01024f23..ea7237633 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -230,6 +230,49 @@ def test_register_knl(ctx_factory): np.linalg.norm(2*x+3*y))) < 1e-15 +def test_slices(ctx_factory): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + n = 2 ** 4 + + x = np.random.rand(n, n, n, n, n) + y = np.random.rand(n, n, n, n, n) + + child_knl = lp.make_kernel( + "{[i, j]:0<=i, j < 16}", + """ + g[i, j] = 2*e[i, j] + 3*f[i, j] + """) + + parent_knl = lp.make_kernel( + "{[i, k, m]: 0<=i, k, m<16}", + """ + z[i, :, k, :, m] = linear_combo(x[i, :, k, :, m], y[i, :, k, :, m]) + """, + kernel_data=[ + lp.GlobalArg( + name='x', + dtype=np.float64, + shape=(16, 16, 16, 16, 16)), + lp.GlobalArg( + name='y', + dtype=np.float64, + shape=(16, 16, 16, 16, 16)), + lp.GlobalArg( + name='z', + dtype=np.float64, + shape=(16, 16, 16, 16, 16)), '...'], + ) + + knl = lp.register_callable_kernel( + parent_knl, 'linear_combo', child_knl) + + evt, (out, ) = knl(queue, x=x, y=y) + + assert (np.linalg.norm(2*x+3*y-out)/( + np.linalg.norm(2*x+3*y))) < 1e-15 + + def test_rename_argument(ctx_factory): ctx = ctx_factory() queue = cl.CommandQueue(ctx) -- GitLab