Skip to content

Commit

Permalink
generalize parts of vector dtypes implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikcfd committed May 11, 2022
1 parent f172dab commit 590d262
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
7 changes: 7 additions & 0 deletions loopy/codegen/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def generate_assignment_instruction_code(codegen_state, insn):
raise UnvectorizableError(
"LHS is scalar, RHS is vector, cannot assign")

if (lhs_is_vector
and (not rhs_is_vector)
and (not
kernel.target.broadcasts_scalar_assignment_to_vec_types)):
raise UnvectorizableError(
"LHS is vector, RHS is not vector, cannot assign")

is_vector = lhs_is_vector

del lhs_is_vector
Expand Down
4 changes: 3 additions & 1 deletion loopy/kernel/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,9 @@ def eval_expr_assert_integer_constant(i, expr):
# We'll do absolutely nothing here, which will result
# in the vector being returned.
pass

elif (vectorization_info is None
and target.allows_non_constant_indexing_for_vec_types):
vector_index = eval_expr(idx)
else:
idx = eval_expr_assert_integer_constant(i, idx)

Expand Down
13 changes: 13 additions & 0 deletions loopy/target/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,11 @@ def ast_block_class(self):
from cgen import Block
return Block

@property
def ast_comment_class(self):
from cgen import Comment
return Comment

@property
def ast_block_scope_class(self):
return ScopingBlock
Expand Down Expand Up @@ -1255,6 +1260,10 @@ def emit_comment(self, s):
from cgen import Comment
return Comment(s)

def emit_pragma(self, s):
from cgen import Pragma
return Pragma(s)

@property
def can_implement_conditionals(self):
return True
Expand Down Expand Up @@ -1334,6 +1343,10 @@ def get_dtype_registry(self):
fill_registry_with_c99_complex_types(result)
return DTypeRegistryWrapper(result)

@property
def allows_non_constant_indexing_for_vec_types(self):
return False


class CASTBuilder(CFamilyASTBuilder):
def preamble_generators(self):
Expand Down
17 changes: 13 additions & 4 deletions loopy/target/c/codegen/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,24 @@ def make_var(name):
ary = self.find_array(expr)

from loopy.kernel.array import get_access_info
from pymbolic import evaluate
from pymbolic import evaluate, substitute

from loopy.symbolic import simplify_using_aff
index_tuple = tuple(
simplify_using_aff(self.kernel, idx) for idx in expr.index_tuple)

access_info = get_access_info(self.kernel.target, ary, index_tuple,
lambda expr: evaluate(expr, self.codegen_state.var_subst_map),
self.codegen_state.vectorization_info)
if self.kernel.target.allows_non_constant_indexing_for_vec_types:
access_info = get_access_info(self.kernel.target, ary, index_tuple,
lambda expr: substitute(
expr,
self.codegen_state.var_subst_map),
self.codegen_state.vectorization_info)
else:
access_info = get_access_info(self.kernel.target, ary, index_tuple,
lambda expr: evaluate(
expr,
self.codegen_state.var_subst_map),
self.codegen_state.vectorization_info)

from loopy.kernel.data import (
ImageArg, ArrayArg, TemporaryVariable, ConstantArg)
Expand Down
8 changes: 8 additions & 0 deletions loopy/target/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ def vector_dtype(self, base, count):

# }}}

@property
def allows_non_constant_indexing_for_vec_types(self):
return False

@property
def broadcasts_scalar_assignment_to_vec_types(self):
return True

# }}}


Expand Down
4 changes: 4 additions & 0 deletions loopy/target/ispc.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def get_dtype_registry(self):

# }}}

@property
def allows_non_constant_indexing_for_vec_types(self):
return False


class ISPCASTBuilder(CFamilyASTBuilder):
def _arg_names_and_decls(self, codegen_state):
Expand Down
8 changes: 8 additions & 0 deletions loopy/target/opencl.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,14 @@ def vector_dtype(self, base, count):
vec.types[base.numpy_dtype, count],
target=self)

@property
def allows_non_constant_indexing_for_vec_types(self):
return False

@property
def broadcasts_scalar_assignment_to_vec_types(self):
return True

# }}}


Expand Down
5 changes: 5 additions & 0 deletions loopy/target/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def ast_block_scope_class(self):
# and delete the implementation above.
return Collection

@property
def ast_comment_class(self):
from genpy import Comment
return Comment

def emit_sequential_loop(self, codegen_state, iname, iname_dtype,
lbound, ubound, inner):
ecm = codegen_state.expression_to_code_mapper
Expand Down

0 comments on commit 590d262

Please sign in to comment.