From b9ae9410120b7f15ac57e6afec700a2cc71e50b8 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 5 Apr 2019 14:49:30 +0100 Subject: [PATCH 1/4] Squash deprecation warnings iname_to_tag -> iname_to_tags --- loopy/check.py | 5 +++-- loopy/transform/pack_and_unpack_args.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/loopy/check.py b/loopy/check.py index 977571fcf..796c5b4bd 100644 --- a/loopy/check.py +++ b/loopy/check.py @@ -185,8 +185,9 @@ def _get_all_unique_iname_tags(kernel): *kernel* that inherit from :class:`loopy.kernel.data.UniqueTag`. """ from loopy.kernel.data import UniqueTag - iname_tags = [kernel.iname_to_tag.get(iname) for iname in - kernel.all_inames()] + from itertools import chain + iname_tags = list(chain(*(kernel.iname_to_tags.get(iname, []) for iname in + kernel.all_inames()))) return set( tag for tag in iname_tags if isinstance(tag, UniqueTag)) diff --git a/loopy/transform/pack_and_unpack_args.py b/loopy/transform/pack_and_unpack_args.py index 67ea48326..a18326187 100644 --- a/loopy/transform/pack_and_unpack_args.py +++ b/loopy/transform/pack_and_unpack_args.py @@ -121,8 +121,9 @@ def pack_and_unpack_args_for_call_for_single_kernel(kernel, from pymbolic import var dim_type = isl.dim_type.set - ilp_inames = set(iname for iname in insn.within_inames if isinstance( - kernel.iname_to_tag.get(iname), (IlpBaseTag, VectorizeTag))) + ilp_inames = set(iname for iname in insn.within_inames + if all(isinstance(tag, (IlpBaseTag, VectorizeTag)) + for tag in kernel.iname_to_tags.get(iname, []))) new_ilp_inames = set() ilp_inames_map = {} for iname in ilp_inames: -- GitLab From 1e5bebd3e2e5c0df2060181fa41ec332e68ea574 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 5 Apr 2019 14:49:57 +0100 Subject: [PATCH 2/4] codegen: Handle multiple entries when collecting forward declarations If the codegen has produced a Collection with (say) some static arrays, we can't assume that the callee program ast has an fdecl property. So if it's a collection, spin over the contents. --- loopy/codegen/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index 8f3e15f28..e7a6f0d3e 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -620,7 +620,14 @@ def generate_code_v2(program): callee_prog_ast = callee_cgr.device_programs[0].ast collective_device_program = collective_device_program.copy( ast=Collection([callee_prog_ast, collective_device_program.ast])) - callee_fdecls.append(callee_prog_ast.fdecl) + if isinstance(callee_prog_ast, Collection): + for entry in callee_prog_ast.contents: + try: + callee_fdecls.append(entry.fdecl) + except AttributeError: + pass + else: + callee_fdecls.append(callee_prog_ast.fdecl) # collecting the function declarations of callee kernels for callee_fdecl in callee_fdecls: -- GitLab From 495513f20258bc6f3d328a6284d7c81fa4ba2ad0 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 5 Apr 2019 14:51:18 +0100 Subject: [PATCH 3/4] codegen: mark callee kernels as static They don't need to be visible outside of the single compilation unit, which will help the C compiler a bit. --- loopy/target/c/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index 6682b6ec3..4644935e0 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -579,9 +579,13 @@ class CASTBuilder(ASTBuilderBase): if self.target.fortran_abi: name += "_" + if codegen_state.kernel.is_called_from_host: + name = Value("void", name) + else: + name = Value("static void", name) return FunctionDeclarationWrapper( FunctionDeclaration( - Value("void", name), + name, [self.idi_to_cgen_declarator(codegen_state.kernel, idi) for idi in codegen_state.implemented_data_info])) -- GitLab From 453d6bdbcba60270014ab6d37a8f92a3e8fde01e Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Fri, 5 Apr 2019 09:34:30 -0500 Subject: [PATCH 4/4] reframes the conditional to check FunctionBody type --- loopy/codegen/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index e7a6f0d3e..f7f0c2902 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -580,6 +580,7 @@ def generate_code_v2(program): """ from loopy.kernel import LoopKernel from loopy.program import make_program + from cgen import FunctionBody if isinstance(program, LoopKernel): program = make_program(program) @@ -621,13 +622,14 @@ def generate_code_v2(program): collective_device_program = collective_device_program.copy( ast=Collection([callee_prog_ast, collective_device_program.ast])) if isinstance(callee_prog_ast, Collection): + # if there is a read only constant in the kernel for entry in callee_prog_ast.contents: - try: + if isinstance(entry, FunctionBody): callee_fdecls.append(entry.fdecl) - except AttributeError: - pass - else: + elif isinstance(callee_prog_ast, FunctionBody): callee_fdecls.append(callee_prog_ast.fdecl) + else: + raise NotImplementedError() # collecting the function declarations of callee kernels for callee_fdecl in callee_fdecls: -- GitLab