From 45e9c3e7fcfb942bea6e23b88d30af21d56d9357 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 25 May 2017 07:16:57 -0700 Subject: [PATCH 1/3] Allow names, exprs, and lp.auto for array offsets --- loopy/kernel/array.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index a02fc58d9..40612dc83 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -1036,7 +1036,9 @@ class ArrayBase(ImmutableRecord): is_written=is_written) - if self.offset: + import loopy as lp + + if self.offset is lp.auto: offset_name = full_name+"_offset" yield ImplementedDataInfo( target=target, @@ -1202,12 +1204,17 @@ def get_access_info(target, ary, index, eval_expr, vectorization_info): return result def apply_offset(sub): + import loopy as lp + if ary.offset: - offset_name = ary.offset - if offset_name is lp.auto: + if ary.offset is lp.auto: offset_name = array_name+"_offset" - - return var(offset_name) + sub + elif isinstance(ary.offset, str): + offset_name = ary.offset + return var(offset_name) + sub + else: + # assume it's an expression + return ary.offset + sub else: return sub -- GitLab From 703b31d128e9aed582fb0c3f2402f82745e48352 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 25 May 2017 09:34:20 -0700 Subject: [PATCH 2/3] Fix array offset treatment if offset is None --- loopy/kernel/array.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 40612dc83..d9f2faf7c 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -1208,10 +1208,9 @@ def get_access_info(target, ary, index, eval_expr, vectorization_info): if ary.offset: if ary.offset is lp.auto: - offset_name = array_name+"_offset" + return var(array_name+"_offset") + sub elif isinstance(ary.offset, str): - offset_name = ary.offset - return var(offset_name) + sub + return var(ary.offset) + sub else: # assume it's an expression return ary.offset + sub -- GitLab From ee94e36da911047a171f06b352f82ea74a6cf46c Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Wed, 6 Sep 2017 13:30:50 +0200 Subject: [PATCH 3/3] [doc][skip ci] Add new offset possibilities --- loopy/kernel/array.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index d9f2faf7c..f3f4e9d73 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -643,8 +643,9 @@ class ArrayBase(ImmutableRecord): :arg offset: Offset from the beginning of the buffer to the point from which the strides are counted. May be one of - * 0 + * 0 or None * a string (that is interpreted as an argument name). + * a pymbolic expression * :class:`loopy.auto`, in which case an offset argument is added automatically, immediately following this argument. :class:`loopy.CompiledKernel` is even smarter in its treatment of -- GitLab