diff --git a/doc/ref_kernel.rst b/doc/ref_kernel.rst index 088bedc9eeb77723483149dcc445d8aa84ddbbb7..2d878dc6baae36d3ae146337580c711c41c09212 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 14bce615a29ef20ef3b5d18b2083cf0cdd98e2f4..b65b5e75c887a90df1f56e6f507ba9df738167ec 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 f89c2b631b5928f6c6fc2ace61b8c3684d1e3b8b..a2ef8fd830057e8ae21ce5bb31e3c66929944d32 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