From 635e399a55236d478ed03e179b6210eec68c84fc Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Fri, 5 Jan 2018 13:47:59 -0600 Subject: [PATCH 1/7] Attempt to make small changes for private temporaries. --- loopy/transform/batch.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/loopy/transform/batch.py b/loopy/transform/batch.py index e7a86300f..6dbb03b7b 100644 --- a/loopy/transform/batch.py +++ b/loopy/transform/batch.py @@ -50,12 +50,14 @@ class _BatchVariableChanger(RuleAwareIdentityMapper): def needs_batch_subscript(self, name): tv = self.kernel.temporary_variables.get(name) + from loopy.kernel.data import temp_var_scope return ( (not self.sequential and (tv is not None - and not ( + and not (( tv.initializer is not None - and tv.read_only))) + and tv.read_only) or ( + tv.scope == temp_var_scope.PRIVATE)))) or name in self.batch_varying_args) @@ -142,9 +144,12 @@ def to_batched(knl, nbatches, batch_varying_args, batch_iname_prefix="ibatch", if not sequential: new_temps = {} + from loopy.kernel.data import temp_var_scope for temp in six.itervalues(knl.temporary_variables): - if temp.initializer is not None and temp.read_only: + if (temp.initializer is not None and temp.read_only) or ( + temp.scope == temp_var_scope.PRIVATE and temp.name not in + batch_varying_args): new_temps[temp.name] = temp else: new_temps[temp.name] = temp.copy( -- GitLab From e56b0ecd0191bdc9206b13756c753c59664ca576 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Sun, 7 Jan 2018 20:46:12 -0600 Subject: [PATCH 2/7] Minor bug in `parse_match` documentation --- loopy/match.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/match.py b/loopy/match.py index ab0038af8..ab5f11bb2 100644 --- a/loopy/match.py +++ b/loopy/match.py @@ -273,7 +273,7 @@ def parse_match(expr): """Syntax examples:: * ``id:yoink and writes:a_temp`` - * ``id:yoink and (not writes:a_temp or tagged:input)`` + * ``id:yoink and (not writes:a_temp or tag:input)`` """ if not expr: return All() -- GitLab From c4a49e4c4736d8e56757c9df98f6d38813681b0d Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 9 Jan 2018 19:20:56 -0600 Subject: [PATCH 3/7] Added test for the private temps in `to_batched` --- test/test_transform.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/test_transform.py b/test/test_transform.py index e50605b46..770e43617 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -105,6 +105,28 @@ def test_to_batched(ctx_factory): bknl(queue, a=a, x=x) +def test_to_batched_temp(ctx_factory): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + + knl = lp.make_kernel( + ''' { [i,j]: 0<=i,j Date: Tue, 9 Jan 2018 19:22:26 -0600 Subject: [PATCH 4/7] Changed documentations and attempt to shorten the code. --- loopy/transform/batch.py | 47 ++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/loopy/transform/batch.py b/loopy/transform/batch.py index 6dbb03b7b..d02c0fc35 100644 --- a/loopy/transform/batch.py +++ b/loopy/transform/batch.py @@ -38,6 +38,20 @@ __doc__ = """ # {{{ to_batched +def temp_needs_batching_if_not_sequential(tv, batch_varying_args): + from loopy.kernel.data import temp_var_scope + if tv.name in batch_varying_args: + return True + if tv.initializer is not None and tv.read_only: + # do not batch read_only temps if not in + # `batch_varying_args` + return False + if tv.scope == temp_var_scope.PRIVATE: + # do not batch private temps if not in `batch_varying args` + return False + return True + + class _BatchVariableChanger(RuleAwareIdentityMapper): def __init__(self, rule_mapping_context, kernel, batch_varying_args, batch_iname_expr, sequential): @@ -50,16 +64,17 @@ class _BatchVariableChanger(RuleAwareIdentityMapper): def needs_batch_subscript(self, name): tv = self.kernel.temporary_variables.get(name) - from loopy.kernel.data import temp_var_scope - return ( - (not self.sequential - and (tv is not None - and not (( - tv.initializer is not None - and tv.read_only) or ( - tv.scope == temp_var_scope.PRIVATE)))) - or - name in self.batch_varying_args) + + if name in self.batch_varying_args: + return True + if not self.sequential: + if tv is None: + return False + if not temp_needs_batching_if_not_sequential(tv, + self.batch_varying_args): + return False + + return True def map_subscript(self, expr, expn_state): if not self.needs_batch_subscript(expr.aggregate.name): @@ -91,6 +106,9 @@ def to_batched(knl, nbatches, batch_varying_args, batch_iname_prefix="ibatch", sequential=False): """Takes in a kernel that carries out an operation and returns a kernel that carries out a batch of these operations. + ***Note:* For temporaries in a kernel that are private or read only + globals, loopy does not does not batch these variables if not mentioned + explicitly in `batch_varying_args`. :arg nbatches: the number of batches. May be a constant non-negative integer or a string, which will be added as an integer argument. @@ -144,18 +162,15 @@ def to_batched(knl, nbatches, batch_varying_args, batch_iname_prefix="ibatch", if not sequential: new_temps = {} - from loopy.kernel.data import temp_var_scope for temp in six.itervalues(knl.temporary_variables): - if (temp.initializer is not None and temp.read_only) or ( - temp.scope == temp_var_scope.PRIVATE and temp.name not in - batch_varying_args): - new_temps[temp.name] = temp - else: + if temp_needs_batching_if_not_sequential(temp, batch_varying_args): new_temps[temp.name] = temp.copy( shape=(nbatches_expr,) + temp.shape, dim_tags=("c",) * (len(temp.shape) + 1), dim_names=_add_unique_dim_name("ibatch", temp.dim_names)) + else: + new_temps[temp.name] = temp knl = knl.copy(temporary_variables=new_temps) else: -- GitLab From c98820b8a2006285203a674dec5033da812ecf61 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Fri, 12 Jan 2018 17:33:10 -0600 Subject: [PATCH 5/7] Made doc changes to explain the behavior of temps in `to_bathced` better --- loopy/transform/batch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/loopy/transform/batch.py b/loopy/transform/batch.py index d02c0fc35..7e6b03581 100644 --- a/loopy/transform/batch.py +++ b/loopy/transform/batch.py @@ -106,9 +106,10 @@ def to_batched(knl, nbatches, batch_varying_args, batch_iname_prefix="ibatch", sequential=False): """Takes in a kernel that carries out an operation and returns a kernel that carries out a batch of these operations. - ***Note:* For temporaries in a kernel that are private or read only - globals, loopy does not does not batch these variables if not mentioned - explicitly in `batch_varying_args`. + .. note:: + For temporaries in a kernel that are private or read only + globals and if `sequential=True`, loopy does not does not batch these + variables unless explicitly mentioned in `batch_varying_args`. :arg nbatches: the number of batches. May be a constant non-negative integer or a string, which will be added as an integer argument. -- GitLab From feb226f23bb1909f1155a8bdeeec4dfd818da17c Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Fri, 12 Jan 2018 17:55:38 -0600 Subject: [PATCH 6/7] Compared the correctness of the test using `auto_test_vs_ref` --- test/test_transform.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/test_transform.py b/test/test_transform.py index 770e43617..ccbbd3da0 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -107,7 +107,6 @@ def test_to_batched(ctx_factory): def test_to_batched_temp(ctx_factory): ctx = ctx_factory() - queue = cl.CommandQueue(ctx) knl = lp.make_kernel( ''' { [i,j]: 0<=i,j Date: Sun, 14 Jan 2018 22:38:48 -0600 Subject: [PATCH 7/7] Fixing logical errors in `test_to_bathced` and `test_to_batched_temps` so that they actually check that the output is correct --- test/test_transform.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/test_transform.py b/test/test_transform.py index ccbbd3da0..0e10db362 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -96,13 +96,28 @@ def test_to_batched(ctx_factory): knl = lp.make_kernel( ''' { [i,j]: 0<=i,j