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

Improve simpilfy to normalize polynomial before constant evaluation #186

Merged
merged 7 commits into from
Apr 27, 2022

Conversation

yamaguchi1024
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Apr 13, 2022

Codecov Report

Merging #186 (e9ca6cd) into master (9245b5a) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #186      +/-   ##
==========================================
+ Coverage   79.94%   79.98%   +0.04%     
==========================================
  Files          32       32              
  Lines        2857     2863       +6     
==========================================
+ Hits         2284     2290       +6     
  Misses        573      573              
Impacted Files Coverage Δ
tests/gemmini/conv/test_gemmini_conv_stride1.py 47.02% <100.00%> (ø)
tests/test_schedules.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9245b5a...e9ca6cd. Read the comment docs.

@yamaguchi1024 yamaguchi1024 enabled auto-merge (squash) April 19, 2022 19:30
new_typ = T.Tensor(new_hi, False, s.type.basetype())
return [LoopIR.Alloc(s.name, new_typ, s.mem, s.eff, s.srcinfo)]

return super().map_s(s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you eliminate all of these different map_* cases by simply checking at the top of map_e whether or not an expression is of index or size type (i.e. is indexable) and then returning the result of index_start if it is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

return self.concat_map(e.op, lhs_map, rhs_map)
else:
assert False, ("index_start should only be called by"+
f" an indexing expression. e was {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadConfig can have indexable type, and is unhandled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching!


def normalize_e(self, e):
if isinstance(e, LoopIR.Read):
assert e.type.is_indexable()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this assertion be lifted up to the top scope of this method, applicable to all cases?

src/exo/LoopIR_scheduling.py Show resolved Hide resolved
if op == '+':
# if has same key: add value
common = { key: (lhs[key]+rhs[key]) for key in lhs if key in rhs }
return lhs | rhs | common
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the semantics of union such that the right-hand side of the union is guaranteed to overwrite the left in the event of a key clash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

if len(rhs) == 1 and self.C in rhs:
return { key: lhs[key]*rhs[self.C] for key in lhs }
else:
assert self.C in lhs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(lhs) == 1 and self.C in lhs

new_e = LoopIR.BinOp('+', new_e, get_loopir(key, val), e.type, e.srcinfo)
else:
# sub
new_e = LoopIR.BinOp('-', new_e, get_loopir(key, val), e.type, e.srcinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be -val?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this

return LoopIR.BinOp('*', vconst, readkey, e.type, e.srcinfo)

delete_zero = { key: n_map[key] for key in n_map if n_map[key] != 0 }
new_e = LoopIR.Const(0, T.int, e.srcinfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this just generate gratuitous leading zeros everywhere, or does simplification take care of that for you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplification's constant folding path takes care of eliminating the leading zeros

@yamaguchi1024
Copy link
Member Author

codecov is being silly

@yamaguchi1024 yamaguchi1024 merged commit 6a7cee1 into master Apr 27, 2022
@yamaguchi1024 yamaguchi1024 deleted the improve-simplify branch April 27, 2022 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants