separation logic-assisted code transformations for efficient...
TRANSCRIPT
![Page 1: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/1.jpg)
Separation Logic-Assisted Code Transformations for Efficient High-Level Synthesis
Felix Winterstein, Samuel Bayliss, George Constantinides
12 May 2014
1
![Page 2: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/2.jpg)
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2
Background
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
SW memory model
Distributed Block RAM
FPGA
int main() { x = A[i]; p = new int; *p = 3; ... }
low address
high address
![Page 3: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/3.jpg)
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2
Background
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
SW memory model
Distributed Block RAM
FPGA
int main() { x = A[i]; p = new int; *p = 3; ... }
low address
HLS
high address
![Page 4: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/4.jpg)
2
Background
Lack of automated optimizations … • … for programs using pointers • ... because pointers are difficult
to analyze • ... and memory is allocated,
disposed, and reused at run-time • Yet widely used in SW
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
SW memory model
int main() { x = A[i]; p = new int; *p = 3; ... }
low address
high address
![Page 5: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/5.jpg)
2
Background
Lack of automated optimizations … • … for programs using pointers • ... because pointers are difficult
to analyze • ... and memory is allocated,
disposed, and reused at run-time • Yet widely used in SW
This work takes a step towards closing this gap
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
SW memory model
int main() { x = A[i]; p = new int; *p = 3; ... }
low address
high address
![Page 6: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/6.jpg)
4
Our contribution
Our goal • Partition heap-allocated data
structures (‘heaplets’) • Synthesize parallel memory
accesses
• Ensure that heap partitions are ‘private’
heap[N] heapa[N/2] heapb[N/2]
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
SW memory model
low address
high address
![Page 7: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/7.jpg)
5
Outline
Original source code (heap-directed pointers,
dynamic memory allocation)
Static analysis and code
transformation
Modified source code
Standard HLS tool (e.g. Vivado HLS)
Executive summary • Static program analysis
– Analyse pointer-based memory accesses
– Identify independent, disjoint regions in memory
• Source-to-source transformations – Partition heap across on-chip memory
banks – Automatic parallelization
![Page 8: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/8.jpg)
Motivating example
8
Can we parallelize this loop?
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
![Page 9: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/9.jpg)
Motivating example
6
root
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
![Page 10: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/10.jpg)
Motivating example
6
n u
s
root
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
![Page 11: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/11.jpg)
Motivating example
6
n u
s
root
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
![Page 12: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/12.jpg)
Motivating example
6
s=0
u, root
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
![Page 13: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/13.jpg)
Motivating example
6
s=0
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
u, root
![Page 14: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/14.jpg)
Motivating example
6
s=0
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
u, root
![Page 15: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/15.jpg)
Motivating example
6
n u
s
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
u, root
![Page 16: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/16.jpg)
Motivating example
6
n u
n u
s
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
u, root
![Page 17: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/17.jpg)
Motivating example
6
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
n u
n u
s
![Page 18: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/18.jpg)
Motivating example
6
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
… … … … … …
n u
n u
s
![Page 19: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/19.jpg)
Motivating example
6
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
After two iterations…
n u
n u
n u
s
![Page 20: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/20.jpg)
Motivating example
7
sb
… … … … … …
s = PUSH(root, s); while s!=0 do s = POP(&u, s); … do something if (u->left!= 0) && (u->right!=0) then s = PUSH(u->right, s); s = PUSH(u->left, s); end if delete u; end while
n u
n u
n u
sa
• Partition linked list and tree
![Page 21: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/21.jpg)
… preamble (accessing root node) while sa!=0 do … loop body (access left sub-tree) end while while sb!=0 do … loop body (access right sub-tree) end while
Motivating example
7
sb
… … … … … …
n u
n u
n u
sa
• Partition linked list and tree
![Page 22: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/22.jpg)
Motivating example
7
sb
… … … … … …
n u
n u
n u
sa
• Partition linked list and tree • Will the red loop ever access data in the green partition?
… preamble (accessing root node) while sa!=0 do … loop body (access left sub-tree) end while while sb!=0 do … loop body (access right sub-tree) end while
![Page 23: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/23.jpg)
Motivating example
7
sb
… … … … … …
n u
n u
n u
sa
• Partition linked list and tree • Will the red loop ever access data in the green partition? No!
… preamble (accessing root node) while sa!=0 do … loop body (access left sub-tree) end while while sb!=0 do … loop body (access right sub-tree) end while
![Page 24: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/24.jpg)
Motivating example
7
sb
… … … … … …
n u
n u
n u
sa
• Partition linked list and tree • Will the red loop ever access data in the green partition? • Parallelization is legal (does not violate data dependencies)
No!
… preamble (accessing root node) while sa!=0 do … loop body (access left sub-tree) end while while sb!=0 do … loop body (access right sub-tree) end while
![Page 25: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/25.jpg)
Motivating example
7
sb
… … … … … …
n u
n u
n u
sa
• Partition linked list and tree • Will the red loop ever access data in the green partition? • Parallelization is legal (does not violate data dependencies) • Why is it hard for a tool to figure this out?
No!
… preamble (accessing root node) while sa!=0 do … loop body (access left sub-tree) end while while sb!=0 do … loop body (access right sub-tree) end while
![Page 26: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/26.jpg)
The problem
8
… … … … …
n u
n u
n u
s …
![Page 27: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/27.jpg)
The problem
8
… … … … …
n u
n u
n u
s …
Heap accessed in the next iteration
![Page 28: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/28.jpg)
The problem
8
… … … … …
n u
n u
n u
s …
Heap accessed in the next iteration
Heap accessed in some iteration in the future
![Page 29: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/29.jpg)
The problem
8
… … … … …
n u
n u
n u
s …
Heap accessed in the next iteration
Heap accessed in some iteration in the future
• Do these iterations access the same memory cell?
![Page 30: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/30.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
heap[s]
…
![Page 31: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/31.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u]
![Page 32: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/32.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[s]
![Page 33: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/33.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[s].n]
![Page 34: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/34.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[heap[s].n].n]
![Page 35: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/35.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[heap[heap[s].n].n].u]
![Page 36: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/36.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[heap[heap[s].n].n].u]
= ?
![Page 37: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/37.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[heap[heap[s].n].n].u]
= ?
Traverse a linked list
![Page 38: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/38.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
…
heap[heap[s].u] heap[heap[heap[heap[s].n].n].u]
= ?
… which has links to sub-trees
![Page 39: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/39.jpg)
The problem
8
… … … … …
n u
n u
n u
s • Do these iterations access the same memory cell?
• Need to reason about structure, heap layout and disjointness • None of this is explicit in the above representation
…
heap[heap[s].u] heap[heap[heap[heap[s].n].n].u]
= ?
… which has links to sub-trees
![Page 40: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/40.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 41: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/41.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
“s points to a record with fields u and n”
![Page 42: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/42.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 43: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/43.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 44: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/44.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 45: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/45.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 46: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/46.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 47: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/47.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 48: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/48.jpg)
Classical first order logic
9
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 49: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/49.jpg)
Classical first order logic
10
Describe heap layout with formulae
n u
n u
n u
s
Formula below can also mean this
![Page 50: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/50.jpg)
Classical first order logic
10
Describe heap layout with formulae
n u
n u
n u
s
Formula below can also mean this
![Page 51: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/51.jpg)
Classical first order logic
10
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
![Page 52: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/52.jpg)
Classical first order logic
10
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
…
Could add loads of constraints
![Page 53: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/53.jpg)
Separation logic
11
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
…
Separating conjunction ‘ ’ rules out aliasing!
O’Hearn, Reynolds, Ishtiaq, Yang:
![Page 54: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/54.jpg)
Separation logic
11
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
…
Separating conjunction ‘ ’ rules out aliasing!
O’Hearn, Reynolds, Ishtiaq, Yang:
![Page 55: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/55.jpg)
Separation logic
11
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
Separating conjunction ‘ ’ rules out aliasing!
O’Hearn, Reynolds, Ishtiaq, Yang:
* * * * *
…
![Page 56: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/56.jpg)
Separation logic
11
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
Separating conjunction ‘ ’ rules out aliasing!
O’Hearn, Reynolds, Ishtiaq, Yang:
* * * * *
…
![Page 57: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/57.jpg)
Separation logic
11
Describe heap layout with formulae
… … … … …
n u
n u
n u
s …
Separating conjunction ‘ ’ rules out aliasing!
O’Hearn, Reynolds, Ishtiaq, Yang:
* * * * *
• Tractable heap analysis – very popular in SW verification • We use it to prove disjointness of heap regions
![Page 58: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/58.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
![Page 59: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/59.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
![Page 60: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/60.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
sb
![Page 61: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/61.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
sb
![Page 62: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/62.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
sb
a b
![Page 63: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/63.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
sb
a b
![Page 64: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/64.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b
a a
![Page 65: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/65.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b
a a
a
a
![Page 66: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/66.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b
a a
a
a
![Page 67: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/67.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b
b a a
a
a b
![Page 68: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/68.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b
b a a
a
a b
![Page 69: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/69.jpg)
Back to our partitioning task
12
… … … … … …
n u
n u
n u
s
• Partitioning the heap = partitioning the formula describing it
• Add a second ‘hook’ into the data structure
• ‘Symbolically’ step through loop iterations
• Attach labels to heaplets
sb
a b Communication-free parallelism: Never …
a b
b a a
a
a b
![Page 70: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/70.jpg)
Implementation
13
Analysis interface
C/C++ code
Substitute dynamic memory
allocation
Heap splitting /
Loop splitting
Heap analysis / Theorem proving
C/C++ code
Vivado HLS
RTL impl.
Automated source-to-source compiler LLNL ROSE Compiler Infrastructure (C++)
Automated proof engine (OCaml)
Parse into AST
Unparse AST
![Page 71: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/71.jpg)
Case Studies (I)
14
0 2000 4000 6000 8000 100000
2
4
6
8
10
12
x 105
slices
late
ncy
[clo
ck c
ycle
s]
Slices
Latency [clock cycles]
parallelization p=2
parallelization p=4
no parallelization, only ensuring synthesizability
Tree-based K-means clustering
parallelization p=2
parallelization p=4
![Page 72: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/72.jpg)
Case Studies (II)
15
x2
P Slices Clock Cycles
Merger (linked lists) Baseline (no par.) 1 574 9.0 ns 21167k Autom. Parallelization 4 965 8.7 ns 5483k
Tree deletion (tree, linked list) Baseline (no par.) 1 1521 5.2 ns 901k Autom. Parallelization 2 4069 6.0 ns 487k
K-means (tree, linked list, single heap records) Baseline (no par.) 1 2694 6.1 ns 1120k Autom. Parallelization 2 5618 7.0 ns 606k
Hand-optimized HLS 2 5492 5.5 ns 165k
x4
x2
1
2
3
Manual loop flattening, pipelining, custom bit widths, data streaming directives, data packing, …
![Page 73: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/73.jpg)
Case Studies (II)
15
x2
P Slices Clock Cycles
Merger (linked lists) Baseline (no par.) 1 574 9.0 ns 21167k Autom. Parallelization 4 965 8.7 ns 5483k
Tree deletion (tree, linked list) Baseline (no par.) 1 1521 5.2 ns 901k Autom. Parallelization 2 4069 6.0 ns 487k
K-means (tree, linked list, single heap records) Baseline (no par.) 1 2694 6.1 ns 1120k Autom. Parallelization 2 5618 7.0 ns 606k
Hand-optimized HLS 2 5492 5.5 ns 165k
x4
x2
1
2
3
Manual loop flattening, pipelining, custom bit widths, data streaming directives, data packing, …
![Page 74: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/74.jpg)
Case Studies (II)
15
x2
P Slices Clock Cycles
Merger (linked lists) Baseline (no par.) 1 574 9.0 ns 21167k Autom. Parallelization 4 965 8.7 ns 5483k
Tree deletion (tree, linked list) Baseline (no par.) 1 1521 5.2 ns 901k Autom. Parallelization 2 4069 6.0 ns 487k
K-means (tree, linked list, single heap records) Baseline (no par.) 1 2694 6.1 ns 1120k Autom. Parallelization 2 5618 7.0 ns 606k
Hand-optimized HLS 2 5492 5.5 ns 165k
x4
x2
1
2
3
Manual loop flattening, pipelining, custom bit widths, data streaming directives, data packing, … x3.6
![Page 75: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/75.jpg)
Conclusion
• Static analysis of heap-manipulating programs – Leveraging recent advances in separation logic – Distribute heap across on-chip memory banks – Loop parallelization
• Tool implementation – Automated heap analyzer – Automated source-to-source transformations (synthesizability and
parallelization) – Successful parallelization using standard HLS tools
• Future work – Use this analysis for efficient loop pipelining – … and automatic on-chip buffer insertion in interface to external
memory – Compute worst-case/average-case bounds on heap usage
16
![Page 76: Separation Logic-Assisted Code Transformations for Efficient …cas.ee.ic.ac.uk/people/fw1811/talks/Winterstein_FCCM14... · 2014-07-12 · Separation Logic-Assisted Code Transformations](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed11ea7836f882b4b041279/html5/thumbnails/76.jpg)
Thank you for listening.
http://cas.ee.ic.ac.uk/people/fw1811/