From 0f9e50d2568a0abe239ddd0c20f4579745b9fa0d Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Wed, 30 Aug 2017 17:17:54 +0200 Subject: [PATCH 1/2] Allow arguments as base storage for temporary variables If the given base storage name of a temporary matches a name of an argument of the kernel, base_storage declaration is skipped and the argument is used instead. --- loopy/preprocess.py | 2 +- loopy/target/c/__init__.py | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/loopy/preprocess.py b/loopy/preprocess.py index ced1aaaa1..09cda0441 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -167,7 +167,7 @@ def find_temporary_scope(kernel): for temp_var in six.itervalues(kernel.temporary_variables): if temp_var.base_storage is not None: # no nesting allowed - if temp_var.base_storage in kernel_var_names: + if temp_var.base_storage in kernel.temporary_variables: raise LoopyError("base_storage for temporary '%s' is '%s', " "which is an existing variable name" % (temp_var.name, temp_var.base_storage)) diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index a2ad68250..25f1baea1 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -439,20 +439,21 @@ class CASTBuilder(ASTBuilderBase): assert tv.initializer is None offset = 0 - base_storage_sizes.setdefault(tv.base_storage, []).append( - tv.nbytes) - base_storage_to_scope.setdefault(tv.base_storage, []).append( - tv.scope) + if tv.base_storage not in kernel.arg_dict: + base_storage_sizes.setdefault(tv.base_storage, []).append( + tv.nbytes) + base_storage_to_scope.setdefault(tv.base_storage, []).append( + tv.scope) - align_size = tv.dtype.itemsize + align_size = tv.dtype.itemsize - from loopy.kernel.array import VectorArrayDimTag - for dim_tag, axis_len in zip(tv.dim_tags, tv.shape): - if isinstance(dim_tag, VectorArrayDimTag): - align_size *= axis_len + from loopy.kernel.array import VectorArrayDimTag + for dim_tag, axis_len in zip(tv.dim_tags, tv.shape): + if isinstance(dim_tag, VectorArrayDimTag): + align_size *= axis_len - base_storage_to_align_bytes.setdefault(tv.base_storage, []).append( - align_size) + base_storage_to_align_bytes.setdefault(tv.base_storage, []).append( + align_size) for idi in decl_info: cast_decl = POD(self, idi.dtype, "") -- GitLab From e5915e60f675cb816a24941b0152cd88f632097a Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Wed, 30 Aug 2017 19:20:07 +0200 Subject: [PATCH 2/2] fix flakes --- loopy/preprocess.py | 2 -- loopy/target/c/__init__.py | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 09cda0441..ab6865f5f 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -162,8 +162,6 @@ def find_temporary_scope(kernel): base_storage_to_aliases = {} - kernel_var_names = kernel.all_variable_names(include_temp_storage=False) - for temp_var in six.itervalues(kernel.temporary_variables): if temp_var.base_storage is not None: # no nesting allowed diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index 25f1baea1..841602b31 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -452,8 +452,8 @@ class CASTBuilder(ASTBuilderBase): if isinstance(dim_tag, VectorArrayDimTag): align_size *= axis_len - base_storage_to_align_bytes.setdefault(tv.base_storage, []).append( - align_size) + base_storage_to_align_bytes.setdefault(tv.base_storage, + []).append(align_size) for idi in decl_info: cast_decl = POD(self, idi.dtype, "") -- GitLab