From fc63161985f74b6dda631044295fcfde0789acc2 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 5 Jul 2022 19:09:14 -0500 Subject: [PATCH] Defines lp.VectorizationFallback --- loopy/__init__.py | 4 ++-- loopy/target/__init__.py | 24 ++++++++++++++++++++++++ loopy/target/c/__init__.py | 5 +++++ loopy/target/cuda.py | 5 +++++ loopy/target/ispc.py | 5 +++++ loopy/target/opencl.py | 5 +++++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/loopy/__init__.py b/loopy/__init__.py index ce3ba1439..62529016e 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -150,7 +150,7 @@ from loopy.frontend.fortran import (c_preprocess, parse_transformed_fortran, parse_fortran) -from loopy.target import TargetBase, ASTBuilderBase +from loopy.target import TargetBase, ASTBuilderBase, VectorizationFallback from loopy.target.c import (CFamilyTarget, CTarget, ExecutableCTarget, generate_header, CWithGNULibcTarget, ExecutableCWithGNULibcTarget) @@ -298,7 +298,7 @@ "LoopyError", "LoopyWarning", - "TargetBase", + "TargetBase", "VectorizationFallback", "CFamilyTarget", "CTarget", "ExecutableCTarget", "generate_header", "CWithGNULibcTarget", "ExecutableCWithGNULibcTarget", "CudaTarget", "OpenCLTarget", diff --git a/loopy/target/__init__.py b/loopy/target/__init__.py index ea7eec072..aedb0bd50 100644 --- a/loopy/target/__init__.py +++ b/loopy/target/__init__.py @@ -10,6 +10,7 @@ .. autoclass:: OpenCLTarget .. autoclass:: PyOpenCLTarget .. autoclass:: ISPCTarget +.. autoclass:: VectorizationFallback References to Canonical Names ----------------------------- @@ -50,6 +51,7 @@ from typing import (Any, Tuple, Generic, TypeVar, Sequence, ClassVar, Optional, TYPE_CHECKING, Type) import abc +from enum import Enum, unique if TYPE_CHECKING: from loopy.typing import ExpressionT @@ -60,12 +62,30 @@ ASTType = TypeVar("ASTType") +@unique +class VectorizationFallback(Enum): + """ + Directs :mod:`loopy`\'s code-generation pipeline how the code should be + generated if an instruction cannot be vectorized. + + :attr UNROLL: Unrolls the instances the unvectorizable statement. + :attr UNROLL: Wraps the statement around a loop with an ``omp simd`` + pragma-directive. + """ + UNROLL = 0 + OMP_SIMD = 1 + + class TargetBase(abc.ABC): """Base class for all targets, i.e. different combinations of code that loopy can generate. Objects of this type must be picklable. + .. attribute:: vectorization_fallback + + An instance of :class:`VectorizationFallback`. + .. attribute:: allows_non_constant_indexing_for_vec_types An instance of :class:`bool` that is *True* only if the target @@ -178,6 +198,10 @@ def is_executable(self) -> bool: translation units through :attr:`loopy.TranslationUnit.__call__`. """ + @abc.abstractproperty + def vectorization_fallback(self): + pass + @abc.abstractproperty def allows_non_constant_indexing_for_vec_types(self): pass diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index e266ab073..beba25239 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -1375,6 +1375,11 @@ def allows_non_constant_indexing_for_vec_types(self): def broadcasts_scalar_assignment_to_vec_types(self): return False + @property + def vectorization_fallback(self): + from loopy.target import VectorizationFallback + return VectorizationFallback.UNROLL + class CASTBuilder(CFamilyASTBuilder): def preamble_generators(self): diff --git a/loopy/target/cuda.py b/loopy/target/cuda.py index 2c6f97f53..f8850ff96 100644 --- a/loopy/target/cuda.py +++ b/loopy/target/cuda.py @@ -276,6 +276,11 @@ def allows_non_constant_indexing_for_vec_types(self): def broadcasts_scalar_assignment_to_vec_types(self): return True + @property + def vectorization_fallback(self): + from loopy.target import VectorizationFallback + return VectorizationFallback.UNROLL + # }}} diff --git a/loopy/target/ispc.py b/loopy/target/ispc.py index a54ece4f7..b02a93a0a 100644 --- a/loopy/target/ispc.py +++ b/loopy/target/ispc.py @@ -210,6 +210,11 @@ def allows_non_constant_indexing_for_vec_types(self): def broadcasts_scalar_assignment_to_vec_types(self): return True + @property + def vectorization_fallback(self): + from loopy.target import VectorizationFallback + return VectorizationFallback.UNROLL + class ISPCASTBuilder(CFamilyASTBuilder): # {{{ top-level codegen diff --git a/loopy/target/opencl.py b/loopy/target/opencl.py index fe971d4d2..7690eae63 100644 --- a/loopy/target/opencl.py +++ b/loopy/target/opencl.py @@ -606,6 +606,11 @@ def allows_non_constant_indexing_for_vec_types(self): def broadcasts_scalar_assignment_to_vec_types(self): return True + @property + def vectorization_fallback(self): + from loopy.target import VectorizationFallback + return VectorizationFallback.UNROLL + # }}}