Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects: (stencil) Relax stencil.return for tensors #2989

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions xdsl/dialects/stencil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,18 +1276,22 @@ def verify_(self) -> None:


class TensorIgnoreSizeConstraint(VarConstraint[Attribute]):

@staticmethod
def matches(attr: TensorType[Attribute], other: Attribute) -> bool:
return (
isa(other, TensorType[Attribute])
and len(attr.get_shape()) == len(other.get_shape())
and attr.get_element_type() == other.get_element_type()
)

def verify(
self, attr: Attribute, constraint_context: ConstraintContext | None = None
) -> None:
constraint_context = constraint_context or ConstraintContext()
if self.name in constraint_context.variables:
if (
isa(attr, TensorType[Attribute])
and isinstance(
other := constraint_context.variables[self.name], TensorType
)
and len(attr.get_shape()) == len(other.get_shape())
and attr.get_element_type() == other.get_element_type()
if isa(attr, TensorType[Attribute]) and TensorIgnoreSizeConstraint.matches(
attr, constraint_context.variables[self.name]
):
return
super().verify(attr, constraint_context)
Expand Down Expand Up @@ -1454,7 +1458,10 @@ def verify_(self) -> None:
for i, res_type in enumerate(res_types):
for j in range(unroll_factor * i, unroll_factor * (i + 1)):
op_type = types[j]
if op_type != res_type:
if op_type != res_type and not (
isa(op_type, TensorType[Attribute])
and TensorIgnoreSizeConstraint.matches(op_type, res_type)
):
raise VerifyException(
"stencil.return expected operand types to match the parent "
f"stencil.apply result element types. Got {op_type} at index "
Expand Down
Loading