From ee89b0f0acd3e659504d97013bd609a4890787c6 Mon Sep 17 00:00:00 2001 From: tj-sun Date: Mon, 22 Jan 2018 19:29:43 +0000 Subject: [PATCH 1/5] Add alignment attribute to ArrayBase --- loopy/kernel/array.py | 4 +++- loopy/target/c/__init__.py | 4 ++++ loopy/target/pyopencl.py | 5 +++++ loopy/version.py | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 34f58e286..df50b4d33 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -624,7 +624,7 @@ class ArrayBase(ImmutableRecord): def __init__(self, name, dtype=None, shape=None, dim_tags=None, offset=0, dim_names=None, strides=None, order=None, for_atomic=False, - target=None, + target=None, alignment=None, **kwargs): """ All of the following (except *name*) are optional. @@ -662,6 +662,7 @@ class ArrayBase(ImmutableRecord): Whether the array is declared for atomic access, and, if necessary, using atomic-capable data types. :arg offset: (See :attr:`offset`) + :arg alignment: memory alignment in bytes """ @@ -816,6 +817,7 @@ class ArrayBase(ImmutableRecord): offset=offset, dim_names=dim_names, order=order, + alignment=alignment, **kwargs) def __eq__(self, other): diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index f4b124303..177daa029 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -709,6 +709,10 @@ class CASTBuilder(ASTBuilderBase): ecm(p.flattened_product(decl_info.shape), prec=PREC_NONE, type_context="i")) + if temp_var.alignment: + from cgen import AlignedAttribute + temp_var_decl = AlignedAttribute(temp_var.alignment, temp_var_decl) + return temp_var_decl def wrap_temporary_decl(self, decl, scope): diff --git a/loopy/target/pyopencl.py b/loopy/target/pyopencl.py index 9955705a2..744c03d8e 100644 --- a/loopy/target/pyopencl.py +++ b/loopy/target/pyopencl.py @@ -61,6 +61,11 @@ def adjust_local_temp_var_storage(kernel, device): temp_var.copy(storage_shape=temp_var.shape) continue + if not temp_var.shape: + # scalar, no need to mess with storage shape + new_temp_vars[temp_var.name] = temp_var + continue + other_loctemp_nbytes = [ tv.nbytes for tv in six.itervalues(kernel.temporary_variables) diff --git a/loopy/version.py b/loopy/version.py index 888fb95f9..7141a6782 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -32,4 +32,4 @@ except ImportError: else: _islpy_version = islpy.version.VERSION_TEXT -DATA_MODEL_VERSION = "v75-islpy%s" % _islpy_version +DATA_MODEL_VERSION = "v76-islpy%s" % _islpy_version -- GitLab From 861b5c14f25fbfb003c6940fe82eaebcaf71f138 Mon Sep 17 00:00:00 2001 From: tj-sun Date: Fri, 26 Jan 2018 11:25:57 +0000 Subject: [PATCH 2/5] add docstring for alignment --- loopy/kernel/array.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index df50b4d33..8dbfc24dd 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -608,6 +608,12 @@ class ArrayBase(ImmutableRecord): to generate more informative names than could be achieved by axis numbers. + .. attribute:: alignment + + Memory alignment of the array in bytes. + Default to *None*. If an integer N is given, the array would be declared + with ``__attribute__((aligned(N)))`` in code generation for :class:`loopy.CTarget`. + .. automethod:: __init__ .. automethod:: __eq__ .. automethod:: num_user_axes -- GitLab From 8488a5e3cd67043e2fbc3be4b33f120d713b9ad9 Mon Sep 17 00:00:00 2001 From: tj-sun Date: Fri, 26 Jan 2018 13:04:05 +0000 Subject: [PATCH 3/5] flake8 --- 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 8dbfc24dd..6d8349916 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -612,7 +612,8 @@ class ArrayBase(ImmutableRecord): Memory alignment of the array in bytes. Default to *None*. If an integer N is given, the array would be declared - with ``__attribute__((aligned(N)))`` in code generation for :class:`loopy.CTarget`. + with ``__attribute__((aligned(N)))`` in code generation for + :class:`loopy.CTarget`. .. automethod:: __init__ .. automethod:: __eq__ -- GitLab From 0fd8c9acf8113c1e42ddd917da7c7e4e5017392b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Fri, 26 Jan 2018 11:04:21 -0500 Subject: [PATCH 4/5] Add "versionadded" note to ArrayBase.alignment. --- loopy/kernel/array.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 6d8349916..f86c3f9a3 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -614,6 +614,8 @@ class ArrayBase(ImmutableRecord): Default to *None*. If an integer N is given, the array would be declared with ``__attribute__((aligned(N)))`` in code generation for :class:`loopy.CTarget`. + + .. versionadded:: 2018.1 .. automethod:: __init__ .. automethod:: __eq__ -- GitLab From 73ec484ac3b18b3c05f8acb612d408dcf249df4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Fri, 26 Jan 2018 15:06:51 -0500 Subject: [PATCH 5/5] Update docs for ArrayBase.alignment --- loopy/kernel/array.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index f86c3f9a3..b672f0227 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -610,11 +610,17 @@ class ArrayBase(ImmutableRecord): .. attribute:: alignment - Memory alignment of the array in bytes. - Default to *None*. If an integer N is given, the array would be declared + Memory alignment of the array in bytes. For temporary arrays, + this ensures they are allocated with this alignment. For arguments, + this entails a promise that the incoming array obeys this alignment + restriction. + + Defaults to *None*. + + If an integer N is given, the array would be declared with ``__attribute__((aligned(N)))`` in code generation for :class:`loopy.CTarget`. - + .. versionadded:: 2018.1 .. automethod:: __init__ -- GitLab