From dad4e8c967e7db3bde6bb0968ea165639bb60adc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 5 Feb 2017 21:36:02 -0600 Subject: [PATCH 1/5] Clean up use of 'iname' variable in generate_sequential_loop_dim_code (found by @mattwala) --- loopy/codegen/loop.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/loopy/codegen/loop.py b/loopy/codegen/loop.py index ad80475c1..2716730b9 100644 --- a/loopy/codegen/loop.py +++ b/loopy/codegen/loop.py @@ -376,10 +376,10 @@ def generate_sequential_loop_dim_code(codegen_state, sched_index): # move inames that are usable into parameters moved_inames = [] - for iname in dom_and_slab.get_var_names(dim_type.set): - if iname in usable_inames: - moved_inames.append(iname) - dt, idx = dom_and_slab.get_var_dict()[iname] + for das_iname in dom_and_slab.get_var_names(dim_type.set): + if das_iname in usable_inames: + moved_inames.append(das_iname) + dt, idx = dom_and_slab.get_var_dict()[das_iname] dom_and_slab = dom_and_slab.move_dims( dim_type.param, dom_and_slab.dim(dim_type.param), dt, idx, 1) @@ -422,8 +422,8 @@ def generate_sequential_loop_dim_code(codegen_state, sched_index): impl_lbound, impl_ubound) - for iname in moved_inames: - dt, idx = impl_loop.get_var_dict()[iname] + for moved_iname in moved_inames: + dt, idx = impl_loop.get_var_dict()[moved_iname] impl_loop = impl_loop.move_dims( dim_type.set, impl_loop.dim(dim_type.set), dt, idx, 1) @@ -432,7 +432,7 @@ def generate_sequential_loop_dim_code(codegen_state, sched_index): codegen_state .intersect(impl_loop) .copy(kernel=intersect_kernel_with_slab( - kernel, slab, iname))) + kernel, slab, loop_iname))) inner = build_loop_nest(new_codegen_state, sched_index+1) -- GitLab From b948121f8f0bed7631118ece87e066e0b3c98f8d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 5 Feb 2017 21:50:59 -0600 Subject: [PATCH 2/5] Make iname iteration order in generate_sequential_loop_dim_code deterministic --- loopy/codegen/loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/codegen/loop.py b/loopy/codegen/loop.py index 2716730b9..171b10e19 100644 --- a/loopy/codegen/loop.py +++ b/loopy/codegen/loop.py @@ -376,7 +376,7 @@ def generate_sequential_loop_dim_code(codegen_state, sched_index): # move inames that are usable into parameters moved_inames = [] - for das_iname in dom_and_slab.get_var_names(dim_type.set): + for das_iname in sorted(dom_and_slab.get_var_names(dim_type.set)): if das_iname in usable_inames: moved_inames.append(das_iname) dt, idx = dom_and_slab.get_var_dict()[das_iname] -- GitLab From 79ee80e5cbe754bceae61f2d83c4a5cd28db33c2 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 6 Feb 2017 15:21:23 -0600 Subject: [PATCH 3/5] Use 'orig_domain' as guiding domain in intersecting kernel with slab in sequential loop codegen --- loopy/codegen/loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/codegen/loop.py b/loopy/codegen/loop.py index 171b10e19..1a7d318bb 100644 --- a/loopy/codegen/loop.py +++ b/loopy/codegen/loop.py @@ -220,7 +220,7 @@ def intersect_kernel_with_slab(kernel, slab, iname): domch = DomainChanger(kernel, (iname,)) orig_domain = domch.get_original_domain() - orig_domain, slab = isl.align_two(orig_domain, slab) + orig_domain, slab = isl.align_two(slab, orig_domain) return domch.get_kernel_with(orig_domain & slab) -- GitLab From 0bae9645033881f048bd3a4dde654f4825526975 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 6 Feb 2017 15:22:08 -0600 Subject: [PATCH 4/5] Fix generated for loop code in test_tight_loop_bounds_codegen --- test/test_loopy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_loopy.py b/test/test_loopy.py index 4c3dbd6d0..851a7f076 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -1948,8 +1948,8 @@ def test_tight_loop_bounds_codegen(): for_loop = \ "for (int j = " \ - "(lid(0) == 0 && gid(0) == 0 ? 0 : -2 + 10 * gid(0) + 2 * lid(0)); " \ - "j <= (lid(0) == 0 && -1 + gid(0) == 0 ? 9 : 2 * lid(0)); ++j)" + "(gid(0) == 0 && lid(0) == 0 ? 0 : -2 + 2 * lid(0) + 10 * gid(0)); " \ + "j <= (-1 + gid(0) == 0 && lid(0) == 0 ? 9 : 2 * lid(0)); ++j)" assert for_loop in cgr.device_code() -- GitLab From ea2431c36aa88b06a6026ae48a1a0580b17c28a4 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 6 Feb 2017 15:22:22 -0600 Subject: [PATCH 5/5] Minor comment addition --- loopy/codegen/loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/loopy/codegen/loop.py b/loopy/codegen/loop.py index 1a7d318bb..a33446204 100644 --- a/loopy/codegen/loop.py +++ b/loopy/codegen/loop.py @@ -423,6 +423,7 @@ def generate_sequential_loop_dim_code(codegen_state, sched_index): impl_ubound) for moved_iname in moved_inames: + # move moved_iname to 'set' dim_type in impl_loop dt, idx = impl_loop.get_var_dict()[moved_iname] impl_loop = impl_loop.move_dims( dim_type.set, impl_loop.dim(dim_type.set), -- GitLab