Skip to content

Commit

Permalink
Defines lp.VectorizationFallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikcfd committed Jul 14, 2022
1 parent a09feb0 commit fc63161
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions loopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -298,7 +298,7 @@

"LoopyError", "LoopyWarning",

"TargetBase",
"TargetBase", "VectorizationFallback",
"CFamilyTarget", "CTarget", "ExecutableCTarget", "generate_header",
"CWithGNULibcTarget", "ExecutableCWithGNULibcTarget",
"CudaTarget", "OpenCLTarget",
Expand Down
24 changes: 24 additions & 0 deletions loopy/target/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.. autoclass:: OpenCLTarget
.. autoclass:: PyOpenCLTarget
.. autoclass:: ISPCTarget
.. autoclass:: VectorizationFallback
References to Canonical Names
-----------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions loopy/target/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions loopy/target/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# }}}


Expand Down
5 changes: 5 additions & 0 deletions loopy/target/ispc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions loopy/target/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# }}}


Expand Down

0 comments on commit fc63161

Please sign in to comment.