Skip to content

Instantly share code, notes, and snippets.

@jrk
Created October 25, 2012 01:17
Show Gist options
  • Save jrk/3949931 to your computer and use it in GitHub Desktop.
Save jrk/3949931 to your computer and use it in GitHub Desktop.
Valid chunk choices
f(v0, v1) = v0*v1
g(v2, v3, v4) = f(v2, v3)
h(v5, v6) = g(v5, v6, 0) + g(v5, v6, 1)
h.root() // h is output, so this is implicit
// this means:
[allocate h]
for all v6:
for all v5:
h[v5,v6] = g(v5,v6,0) + g(v5,v6,1)
// this leaves the variable list: v6, v5 for choices at which g could be evaluated.
g.chunk(v6)
// this means:
for all v6:
[allocate and evaluate as much of g as needed by all calls below here]
for all v5:
h[v5,v6] = g[...] + g[...]
// the evaluation block actually expands to:
for all v6:
[allocate g for range needed by h over all values of v5 below]
for all v4 required by h(v6,*):
for all v3 required by h(v6,*):
for all v2 required by h(v6,*):
g[v2,v3,v4] = f(v2,v3)
for all v5:
h[v5,v6] = g[v5,v6,0] + v[v5,v6,1]
// So now for f...
// The variable list when g was scheduled was: v6, v5
// g was chunked under v6. This eliminated v5 from the list for where f is called.
// (if you look above, you can clearly see f *isn't called within the v5 loop*)
// f is called by g, so it can also be chunked under any of the variables of g's domain.
// Now the variable list for f is: v6, v4, v3, v2
// Notice that this is the same as the ordered set of loops above where f is "called"
f.chunk(v4)
// this means
for all v6:
[allocate g for range needed by h over all values of v5 below]
for all v4 required by h(v6,*):
[allocate f for the range needed by g over all values of v2,v3 below]
for all v1 required by g(v4,*,*):
for all v0 required by g(v4,*,*):
f[v0,v1] = v0+v1
for all v3 required by h(v6,*):
for all v2 required by h(v6,*):
g[v2,v3,v4] = f(v2,v3)
for all v5:
h[v5,v6] = g[v5,v6,0] + v[v5,v6,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment