From 60cd3aade75b65c2f74289955bab66874a722516 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Tue, 22 Mar 2016 09:19:10 -0500 Subject: [PATCH] Introduce a notion of 'scope' for temporary variables, in preparation for global temporaries --- doc/ref_kernel.rst | 2 ++ loopy/__init__.py | 4 ++-- loopy/kernel/data.py | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/ref_kernel.rst b/doc/ref_kernel.rst index 088bedc9e..2d878dc6b 100644 --- a/doc/ref_kernel.rst +++ b/doc/ref_kernel.rst @@ -345,6 +345,8 @@ Temporary Variables Temporary variables model OpenCL's ``private`` and ``local`` address spaces. Both have the lifetime of a kernel invocation. +.. autoclass:: temp_var_scope + .. autoclass:: TemporaryVariable :members: :undoc-members: diff --git a/loopy/__init__.py b/loopy/__init__.py index 14bce615a..b65b5e75c 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -42,7 +42,7 @@ from loopy.kernel.data import ( ValueArg, GlobalArg, ConstantArg, ImageArg, memory_ordering, memory_scope, VarAtomicity, AtomicInit, AtomicUpdate, InstructionBase, Assignment, ExpressionInstruction, CInstruction, - TemporaryVariable, + temp_var_scope, TemporaryVariable, SubstitutionRule) from loopy.kernel import LoopKernel, kernel_state @@ -129,7 +129,7 @@ __all__ = [ "memory_ordering", "memory_scope", "VarAtomicity", "AtomicInit", "AtomicUpdate", "ValueArg", "ScalarArg", "GlobalArg", "ArrayArg", "ConstantArg", "ImageArg", - "TemporaryVariable", + "temp_var_scope", "TemporaryVariable", "SubstitutionRule", "InstructionBase", "Assignment", "ExpressionInstruction", "CInstruction", diff --git a/loopy/kernel/data.py b/loopy/kernel/data.py index f89c2b631..a2ef8fd83 100644 --- a/loopy/kernel/data.py +++ b/loopy/kernel/data.py @@ -267,6 +267,19 @@ class ValueArg(KernelArgument): # {{{ temporary variable +class temp_var_scope: + """Storage location of a temporary + + .. attribute:: PRIVATE + .. attribute:: LOCAL + .. attribute:: GLOBAL + """ + + PRIVATE = 0 + LOCAL = 1 + GLOBAL = 2 + + class TemporaryVariable(ArrayBase): __doc__ = ArrayBase.__doc__ + """ .. attribute:: storage_shape @@ -281,6 +294,8 @@ class TemporaryVariable(ArrayBase): The name of a storage array that is to be used to actually hold the data in this temporary. + + .. autoattribute:: scope """ min_target_axes = 0 @@ -318,6 +333,15 @@ class TemporaryVariable(ArrayBase): storage_shape=storage_shape, base_storage=base_storage) + @property + def scope(self): + """One of :class:`loopy.temp_var_scope`.""" + + if self.is_local: + return temp_var_scope.LOCAL + else: + return temp_var_scope.PRIVATE + @property def nbytes(self): shape = self.shape -- GitLab