Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal...

50
Efficient Stackless Hierarchy Traversal with Backtracking in Constant Time Nikolaus Binder and Alexander Keller, June, 2016

Transcript of Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal...

Page 1: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversalwith Backtracking in Constant TimeNikolaus Binder and Alexander Keller, June, 2016

Page 2: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

1

Page 3: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

2

postponed nodes

3

Page 4: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

4

postponed nodes

3

5

Page 5: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

9

postponed nodes

3

5

Page 6: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

19

postponed nodes

3

5

Page 7: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

38

postponed nodes

3

5

Page 8: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalPruning/postponing nodes and backtracking

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

38

postponed nodes

3

55

Page 9: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalComparing previous backtracking strategies

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Stack

addr(3)

addr(5)

Page 10: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalComparing previous backtracking strategies

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit TrailStack

addr(3)

addr(5) 1

1

0

0

0

Page 11: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalComparing previous backtracking strategies

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit TrailStack

addr(3)

addr(5) 1

1

0

0

0

0

Page 12: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalComparing previous backtracking strategies

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit TrailBit TrailStack

addr(3)

addr(5) 1

1

0

0

0

0

1

1

0

0

0

0

Page 13: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Hierarchy TraversalComparing previous backtracking strategies

StackStackless,

Backtrackingfrom root

Stackless,Backtracking

with parents/siblings

state for book keeping (per ray) O(h(tree)) O(1) O(1)

backtracking effort O(1) O(h(tree)) O(h(tree))

Page 14: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 1: Using a bit trail, go to nth uncle in constant time

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit Trail Cur Key

1

1

0

0

0

1

0

0

1

1

0

Page 15: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 1: Using a bit trail, go to nth uncle in constant time

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit Trail Cur Key

1

1

0

0

0

1

0

0

1

1

0

Page 16: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 1: Using a bit trail, go to nth uncle in constant time

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit Trail Cur Key

1

1

1

0

00 1

Page 17: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 1: Using a bit trail, go to nth uncle in constant time

1

32

5

1110

4

9

19

3938

7776

18

8

1

2 3

4 5

8 9

18 19

38 39

76 77

Bit Trail Cur Key

1

0

1

0

1

Page 18: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 1: Using a bit trail, go to nth uncle in constant time

Perfect Hash Map h: node key k 7! node address addr(k )

⌅ properties– no collisions

– no need to store keys

– lookup in constant time

Page 19: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Page 20: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

E

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

39

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 21: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 22: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

9

9

9

9

9

9

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 23: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

9

9

9

9

9

9

18

18

18

18

18

18

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 24: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 25: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

8

88

E

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+0

+0

+0

+0

+0

+0

+0

+0

Page 26: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

8

88

E

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+1

+0

+0

+0

+0

+0

+0

+0

Page 27: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+0

+0

Page 28: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+0

+0

Page 29: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+0

+0

Page 30: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

3838

E

5

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+0

+0

Page 31: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+0

Page 32: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

3939

E

38

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+0

Page 33: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

3939

E

18

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+1

Page 34: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

3939

E

19

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+2

Page 35: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

3939

E

9

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+3

Page 36: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

3939

E

8

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+4

Page 37: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 2: Two level hashing using an additional displacement table D

k 7! (k mod |T |+D[k mod |D|]) mod |T | [Tarjan, Yao 1979]

Greedy resolution in decreasing number of dependencies [Fox, Heath, Chen, and Daoud 1992]

1

2

3

4

5

8

9

18

19

38

39

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4 5

5

5

5

5

5

5

8

8

8

8

8

8

9

9

9

9

9

9

18

18

18

18

18

18

19

19

19

19

19

19

38

38

38

38

38

38

39

39

39

39

39

39 39

mod 11

k mod |T|

km

od|D|

S = {1,2,3,4,5,8,9,18,19,38,39}

|S|= 11

|T |= 11 = |S|) minimal perfect hash table

|D|= 8

#

1

2

2

2

1

1

1

1

D

T

+2

+0

+0

+0

+0

+0

+1

+5

Page 38: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 3: Reducing the number of hash lookups

⌅ backtracking statistics– to sibling: 27%

– to uncle: 15%

– to grand uncle: 15%

⌅ store references to uncle and grand uncle in node– in unused padding space

– data loaded anyway

⌅ store most recently postponed node in a register– always used for transitions to siblings

– similar to a short stack, but more powerful

around 57% alltogether

sibling

uncle

grand uncle

grand

2uncle

grand

3uncle

grand

4uncle

grand

5uncle

grand

6uncle

grand

7uncle

grand

8uncle

grand

9uncle

grand

10uncle

grand

11uncle

grand

12uncle

grand

13uncle

grand

14uncle

grand

15uncle

grand

16uncle

grand

17uncle

grand

18uncle

grand

19uncle

grand

20uncle

0

27%15% 42% 57% 68% 77% 84% · · · 100%

Page 39: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 3: Reducing the number of hash lookups

⌅ backtracking statistics– to sibling: 27%

– to uncle: 15%

– to grand uncle: 15%

⌅ store references to uncle and grand uncle in node– in unused padding space

– data loaded anyway

⌅ store most recently postponed node in a register– always used for transitions to siblings

– similar to a short stack, but more powerful

around 57% alltogether

sibling

uncle

grand uncle

grand

2uncle

grand

3uncle

grand

4uncle

grand

5uncle

grand

6uncle

grand

7uncle

grand

8uncle

grand

9uncle

grand

10uncle

grand

11uncle

grand

12uncle

grand

13uncle

grand

14uncle

grand

15uncle

grand

16uncle

grand

17uncle

grand

18uncle

grand

19uncle

grand

20uncle

0

27%15% 42% 57% 68% 77% 84% · · · 100%

Page 40: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 3: Reducing the number of hash lookups

⌅ backtracking statistics– to sibling: 27%

– to uncle: 15%

– to grand uncle: 15%

⌅ store references to uncle and grand uncle in node– in unused padding space

– data loaded anyway

⌅ store most recently postponed node in a register– always used for transitions to siblings

– similar to a short stack, but more powerful

around 57% alltogether

sibling

uncle

grand uncle

grand

2uncle

grand

3uncle

grand

4uncle

grand

5uncle

grand

6uncle

grand

7uncle

grand

8uncle

grand

9uncle

grand

10uncle

grand

11uncle

grand

12uncle

grand

13uncle

grand

14uncle

grand

15uncle

grand

16uncle

grand

17uncle

grand

18uncle

grand

19uncle

grand

20uncle

0

27%15% 42% 57% 68% 77% 84% · · · 100%

Page 41: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 4: Avoid pointless backtracking

⌅ subtrees behind intersection may not always be culled– due to overlapping bounding boxes

⌅ discard levels with disjoint t-intervals

– cheap⇧ no t0 values stored

⇧ mask with one bit per level

⇧ bit set to one if overlapping, zero if disjoint

⇧ bitwise and with bit trail after intersection has been found

– compromise⇧ cannot account for intersections outside overlap

Page 42: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 4: Avoid pointless backtracking

⌅ subtrees behind intersection may not always be culled– due to overlapping bounding boxes

⌅ discard levels with disjoint t-intervals

– cheap⇧ no t0 values stored

⇧ mask with one bit per level

⇧ bit set to one if overlapping, zero if disjoint

⇧ bitwise and with bit trail after intersection has been found

– compromise⇧ cannot account for intersections outside overlap

tL0

tL1

tR0tR1

d

i

s

j

o

i

n

t

tL0

tR0

tL1

tR1

o

v

e

r

l

a

p

p

i

n

g

Page 43: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 4: Avoid pointless backtracking

⌅ subtrees behind intersection may not always be culled– due to overlapping bounding boxes

⌅ discard levels with disjoint t-intervals– cheap

⇧ no t0 values stored

⇧ mask with one bit per level

⇧ bit set to one if overlapping, zero if disjoint

⇧ bitwise and with bit trail after intersection has been found

– compromise⇧ cannot account for intersections outside overlap

tL0

tL1

tR0tR1

d

i

s

j

o

i

n

t

tL0

tR0

tL1

tR1

o

v

e

r

l

a

p

p

i

n

g

Page 44: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 4: Avoid pointless backtracking

⌅ subtrees behind intersection may not always be culled– due to overlapping bounding boxes

⌅ discard levels with disjoint t-intervals– cheap

⇧ no t0 values stored

⇧ mask with one bit per level

⇧ bit set to one if overlapping, zero if disjoint

⇧ bitwise and with bit trail after intersection has been found

– compromise⇧ cannot account for intersections outside overlap

tL0

tL1

tR0tR1

d

i

s

j

o

i

n

t

tL0

tR0

tL1

tR1

o

v

e

r

l

a

p

p

i

n

g

Page 45: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeBuilding block 5: Resuming traversal in last node node instead of starting at the root

⌅ pause: state (key and bit trail) must be stored

⌅ resume: start in last node, set bit trail to– previous bit trail if same ray origin and direction

⇧ transparent/translucent object, cut outs

– 1 for all levels above current level if ray origin or direction has changed⇧ tracing paths

⇧ refraction

Page 46: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeSummary

⌅ optimized stackless traversal– backtracking in constant time by perfect hashing– reduced number of hash lookups

⇧ store references to uncles and grand uncles in nodes

⇧ store most recently postponed node in a register

⌅ additional building blocks currently not used in software (e.g. due to register pressure)– discard unreachable postponed nodes

– pause and resume traversal in current node

⌅ exhaustive tests– many different and freely available scenes

– various practical camera positions

– different ray types

Page 47: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeSummary

⌅ optimized stackless traversal– backtracking in constant time by perfect hashing– reduced number of hash lookups

⇧ store references to uncles and grand uncles in nodes

⇧ store most recently postponed node in a register

⌅ additional building blocks currently not used in software (e.g. due to register pressure)– discard unreachable postponed nodes

– pause and resume traversal in current node

⌅ exhaustive tests– many different and freely available scenes

– various practical camera positions

– different ray types

Page 48: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeSummary

⌅ optimized stackless traversal– backtracking in constant time by perfect hashing– reduced number of hash lookups

⇧ store references to uncles and grand uncles in nodes

⇧ store most recently postponed node in a register

⌅ additional building blocks currently not used in software (e.g. due to register pressure)– discard unreachable postponed nodes

– pause and resume traversal in current node

⌅ exhaustive tests– many different and freely available scenes

– various practical camera positions

– different ray types

Page 49: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

Efficient Stackless Hierarchy Traversal with Backtracking in Constant TimeResults: Performance in M rays/s, NVIDIA Titan X, for Primary/Shadow/Diffuse Rays

Stack [Aila 2009] Stackless [Afra 2014] ours

Primary Shadow Diffuse P S D P S D

Armadillo 837 236 214 -13% -10% -11% +17% +32% +35%

Conference 786 399 253 -16% -2% -13% +4% +25% +20%

Dragon 743 212 194 -16% -13% -15% +17% +32% +31%

Emily 676 254 234 -20% -12% -14% +9% +26% +25%

Buddha 1237 210 185 -12% -11% -12% +15% +34% +32%

Hairball 190 77 65 -23% -6% -12% +1% +25% +22%

Enchanted Forest 237 81 64 -14% -5% -12% +5% +22% +19%

San-Miguel 246 149 81 -20% -7% -20% +4% +23% +10%

Average -17% -12% -19% +8% +20% +17%

Page 50: Efficient Stackless Hierarchy Traversal with Backtracking ... · Efficient Hierarchy Traversal Pruning/postponing nodes and backtracking 1 2 3 5 10 11 4 9 19 38 39 76 77 18 8 postponed

We are hiring.

[email protected]