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: Add tests for store, index and access #1016

Merged
merged 3 commits into from
May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 80 additions & 0 deletions tests/dialects/test_stencil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
i64,
IntegerType,
ArrayAttr,
IndexType,
)
from xdsl.dialects.experimental.stencil import (
ReturnOp,
ResultType,
ApplyOp,
StoreOp,
TempType,
LoadOp,
FieldType,
IndexAttr,
IndexOp,
AccessOp,
)
from xdsl.dialects.stencil import CastOp
from xdsl.ir import Block
Expand Down Expand Up @@ -498,3 +502,79 @@ def test_stencil_resulttype(float_type: AnyFloat):

assert isinstance(stencil_resulttype, ResultType)
assert stencil_resulttype.elem == float_type


def test_stencil_store():
temp_type = TempType([5, 5], f32)
temp_type_ssa_val = TestSSAValue(temp_type)

field_type = FieldType([2, 2], f32)
field_type_ssa_val = TestSSAValue(field_type)

lb = IndexAttr.get(1, 1)
ub = IndexAttr.get(64, 64)

store = StoreOp.get(temp_type_ssa_val, field_type_ssa_val, lb, ub)

assert isinstance(store, StoreOp)
assert isinstance(store.field.typ, FieldType)
assert store.field.typ == field_type
assert isinstance(store.temp.typ, TempType)
assert store.temp.typ == temp_type
assert len(store.field.typ.shape) == 2
assert len(store.temp.typ.shape) == 2
assert store.lb is lb
assert store.ub is ub


def test_stencil_store_load_overlap():
temp_type = TempType([5, 5], f32)
temp_type_ssa_val = TestSSAValue(temp_type)

field_type = FieldType([2, 2], f32)
field_type_ssa_val = TestSSAValue(field_type)

lb = IndexAttr.get(1, 1)
ub = IndexAttr.get(64, 64)

load = LoadOp.get(field_type_ssa_val, lb, ub)
store = StoreOp.get(temp_type_ssa_val, field_type_ssa_val, lb, ub)

with pytest.raises(VerifyException) as exc_info:
load.verify()
assert exc_info.value.args[0] == "Cannot Load and Store the same field!"

with pytest.raises(VerifyException) as exc_info:
store.verify()
assert exc_info.value.args[0] == "Cannot Load and Store the same field!"


def test_stencil_index():
dim = IntAttr(10)
offset = IndexAttr.get(1)

index = IndexOp.build(
attributes={
"dim": dim,
"offset": offset,
},
result_types=[IndexType()],
)

assert isinstance(index, IndexOp)
assert index.dim is dim
assert index.offset is offset


def test_stencil_access():
temp_type = TempType([5, 5], f32)
temp_type_ssa_val = TestSSAValue(temp_type)

offset = [1, 1]
offset_index_attr = IndexAttr.get(*offset)

access = AccessOp.get(temp_type_ssa_val, offset)

assert isinstance(access, AccessOp)
assert access.offset == offset_index_attr
assert access.temp.typ == temp_type