From 2080ead25e7e5f39d18504732700b7f24d467e41 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 18 Jan 2023 18:51:46 -0600 Subject: [PATCH 1/3] Fix some warning typos --- loopy/transform/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loopy/transform/data.py b/loopy/transform/data.py index 5b66a2283..e2c21e0dc 100644 --- a/loopy/transform/data.py +++ b/loopy/transform/data.py @@ -1025,7 +1025,7 @@ def allocate_temporaries_for_base_storage(kernel: LoopKernel, assert isinstance(tv.dtype, LoopyType) if tv.address_space is auto: - raise LoopyError("Ahen allocating base storage for temporary " + raise LoopyError("When allocating base storage for temporary " f"'{tv.name}', the address space of the temporary " "was not yet determined (set to 'auto').") @@ -1084,7 +1084,7 @@ def allocate_temporaries_for_base_storage(kernel: LoopKernel, warn("Base storage allocation was performed implicitly during " "preprocessing. This is deprecated and will stop working " "in 2023. Call loopy.allocate_temporaries_for_base_storage " - "explicitly to aovid this warning.", DeprecationWarning) + "explicitly to avoid this warning.", DeprecationWarning) return kernel.copy(temporary_variables=new_tvs) else: From ebe7358f1b2930405365208ec80733e9ae263da8 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 18 Jan 2023 18:52:17 -0600 Subject: [PATCH 2/3] Do not emit temporary decls for temporaries not used in a subkernel (whether they use base_storage or not) Co-authored-by: Kaushik Kulkarni <15399010+kaushikcfd@users.noreply.github.com> --- loopy/target/c/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index b83b89bc5..426d87fe5 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -899,14 +899,12 @@ def get_temporary_decls(self, codegen_state, schedule_index): ecm = self.get_expression_to_code_mapper(codegen_state) - for tv in sorted( - kernel.temporary_variables.values(), - key=lambda key_tv: key_tv.name): + for tv_name in sorted(sub_knl_temps): + tv = kernel.temporary_variables[tv_name] if not tv.base_storage: # global temp vars are mapped to arguments or global # declarations, no need to declare locally. - if tv.address_space != AddressSpace.GLOBAL and ( - tv.name in sub_knl_temps): + if tv.address_space != AddressSpace.GLOBAL: decl = self.get_temporary_var_declarator(codegen_state, tv) if tv.initializer is not None: From f6511354555e3f97fb37cf6ee0d30d077d59de27 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 17 Jan 2023 08:08:46 -0600 Subject: [PATCH 3/3] Test codegen for global temporaries with different base storages Co-authored-by: Andreas Kloeckner --- test/test_loopy.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/test_loopy.py b/test/test_loopy.py index ee5d1f767..70de35257 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -3392,6 +3392,43 @@ def test_creation_kwargs(): ksdfjlasdf=None) +def test_global_temps_with_multiple_base_storages(ctx_factory): + # See https://github.com/inducer/loopy/issues/737 + + n = 10 + ctx = ctx_factory() + cq = cl.CommandQueue(ctx) + + prg = lp.make_kernel( + "{[r0, r1]: 0<=r0,r1< %s}" % n, + """ + tmp0 = sum(r0, r0**2) + ... gbarrier + tmp1 = sum(r1, r1**3) + ... gbarrier + out = tmp0 + tmp1 + """, + [lp.TemporaryVariable("tmp0", + shape=lp.auto, + address_space=lp.AddressSpace.GLOBAL, + base_storage="base1"), + lp.TemporaryVariable("tmp1", + shape=lp.auto, + address_space=lp.AddressSpace.GLOBAL, + base_storage="base2"), + ...], + seq_dependencies=True + ) + + prg = lp.infer_unknown_types(prg) + prg = lp.allocate_temporaries_for_base_storage(prg) + print(prg) + + _, (out,) = prg(cq) + + assert out == sum(i**2 for i in range(n)) + sum(i**3 for i in range(n)) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1])