Feature: Rewriting for Open Hypergraphs
Consider the following program using a (currently nonexistent) kernel language.
F32(M,N)
●----\ F32(M,N) F32(M,N)
[Map(add)]----●------[Map(negate)]------●
●----/
F32(M,N)
Interpret Map(f) as applying the kernel f to every element of each input array.
So add : f32 × f32 → f32 is the kernel, the Map(add) goes between arrays of f32.
We should be able to fuse the two "Map" kernels into one:
F32(M,N)
●----\ F32(M,N)
[Map(add ; negate)]----●
●----/
F32(M,N)
Where add : negate : f32 × f32 → f32 is the kernel x y → -(x+y)
Proposal: we do this by rewriting.
There are three parts to implement:
- Identify a "match" (aka "LHS"): the region of the graph to rewrite (in example above, the two hyperedges
Map(add), Map(negate), and their interfaces
- Compute the result (aka "RHS"): in this case, the single op
Map(add; negate)
- Implement rewriting: replace LHS with RHS in the graph
Simple example
Here's a simpler example usable for testing. It corresponds to rewriting x + (-y) → x - y
----------------●----\ ---●----\
[add]----●----- ~> [sub]----●-----
----●---[neg]---●----/ ---●----/
This feature: a PR for open-hypergraphs
Assume both the match and RHS are known, so we only need to implement step (3) from above.
A rough sketch:
- Append the RHS into the graph
- Quotient the RHS interfaces with the match's interface
- Delete all non-interface data of the match
Acceptance criteria
- Propose API addition for rewriting in the
lax module
- Datastructures for a
Match in an open hypergraph
- Unit tests in the open hypergraphs library demonstrating successful rewrites;
- Use evaluation to check rules like
x + (-y) = x - y.
References/Glossary
Feature: Rewriting for Open Hypergraphs
Consider the following program using a (currently nonexistent) kernel language.
Interpret
Map(f)as applying the kernelfto every element of each input array.So
add : f32 × f32 → f32is the kernel, theMap(add)goes between arrays off32.We should be able to fuse the two "Map" kernels into one:
Where
add : negate : f32 × f32 → f32is the kernelx y → -(x+y)Proposal: we do this by rewriting.
There are three parts to implement:
Map(add),Map(negate), and their interfacesMap(add; negate)Simple example
Here's a simpler example usable for testing. It corresponds to rewriting
x + (-y) → x - yThis feature: a PR for open-hypergraphs
Assume both the match and RHS are known, so we only need to implement step (3) from above.
A rough sketch:
Acceptance criteria
laxmoduleMatchin an open hypergraphx + (-y) = x - y.References/Glossary