A Tabling Implementation Based on Variables with Multiple Bindings - - PowerPoint PPT Presentation

a tabling implementation based on variables with multiple
SMART_READER_LITE
LIVE PREVIEW

A Tabling Implementation Based on Variables with Multiple Bindings - - PowerPoint PPT Presentation

A Tabling Implementation Based on Variables with Multiple Bindings an 1 Manuel Carro 1 Pablo Chico de Guzm Manuel V. Hermenegildo 1 , 2 1 School of Computer Science, Technical University of Madrid, Spain 2 IMDEA-Software, Spain ICLP 2009


slide-1
SLIDE 1

A Tabling Implementation Based on Variables with Multiple Bindings

Pablo Chico de Guzm´ an1 Manuel Carro1 Manuel V. Hermenegildo1,2

1School of Computer Science, Technical University of Madrid, Spain 2IMDEA-Software, Spain

ICLP 2009 — Pasadena, CA, USA – July 15, 2009

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 1 / 1

slide-2
SLIDE 2

Motivation

Motivation

Tabling: resolution strategy (alternative to SLD) aimed at improving both efficiency and declarativeness in Prolog.

◮ ≈ memoing: answers for already executed calls retrieved from table. ◮ Also, infinite recursions avoided by delaying the loop-creating call.

Many applications: deductive databases, program analysis, reasoning in the semantic Web, model checking, . . .

Example code

:- table p/1. p(A) :- q, p(B), A = 2. p(A) :- A = 1.

?− p(A). q, p(B), A = 2. A = 1. p(B), A = 2. Suspension p(1), A = 2. A = 2.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 2 / 1

slide-3
SLIDE 3

Motivation

Main Implementation Approaches

Linear tabling:

◮ Fails on looping branches, performs recomputation instead of resuming. ◮ Only one execution tree ⇒ lower memory stack usage.

Suspension-based mechanisms:

◮ Saves status of looping call to be resumed later. ◮ Several execution trees ⇒ higher memory stack usage.

Example code

:- table p/1. p(A) :- q, p(B), A = 2. p(A) :- A = 1.

?− p(A). q, p(B), A = 2. A = 1. p(B), A = 2. Suspension p(1), A = 2. A = 2.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 3 / 1

slide-4
SLIDE 4

Suspension-Based Implementations

Suspension-Based Implementations

CHAT Example

Really good memory usage:

◮ Sharing local stack and heap. ◮ Copying those bindings which are different for each consumer.

STACK LOCAL POINTS CHOICE G P C TRAIL HEAP B A 1 2

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 4 / 1

slide-5
SLIDE 5

Suspension-Based Implementations

Suspension-Based Implementations

CHAT Example

Really good memory usage:

◮ Sharing local stack and heap. ◮ Copying those bindings which are different for each consumer.

STACK LOCAL POINTS CHOICE G P C TRAIL HEAP B A 1 2

CHAT AREA @A 1 @B 2 C Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 4 / 1

slide-6
SLIDE 6

Suspension-Based Implementations

Suspension-Based Implementations

CHAT Example

Really good memory usage:

◮ Sharing local stack and heap. ◮ Copying those bindings which are different for each consumer.

STACK LOCAL POINTS CHOICE G TRAIL HEAP B A

CHAT AREA @A 1 @B 2 C Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 4 / 1

slide-7
SLIDE 7

Suspension-Based Implementations

Suspension-Based Implementations

CHAT Example

Really good memory usage:

◮ Sharing local stack and heap. ◮ Copying those bindings which are different for each consumer.

STACK LOCAL POINTS CHOICE G TRAIL HEAP B A C 2 1

CHAT AREA @A 1 @B 2 C Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 4 / 1

slide-8
SLIDE 8

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N HEAP

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-9
SLIDE 9

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N 1 2 3 N−1 N HEAP

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-10
SLIDE 10

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N 1 2 3 N−1 N HEAP _1 1 _2 2 _N N

CHAT AREA

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-11
SLIDE 11

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N HEAP _1 1 _2 2 _N N

CHAT AREA

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-12
SLIDE 12

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N 1 2 3 N−1 N HEAP _1 1 _2 2 _N N

CHAT AREA

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-13
SLIDE 13

Suspension-Based Implementations

Suspension-Based Implementations

Speculative Work

Bindings are reinstalled for the consumer execution (and later unbound):

◮ They may be not used ⇒ speculative work!

Code

:− table t/1. large execution (with huge trail), X = 1000. t(1). t(2). t(1000). t(X) :− t(X),

_1 _2 _3 _N−1 _N HEAP _1 1 _2 2 _N N

CHAT AREA

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 5 / 1

slide-14
SLIDE 14

MVB Implementation

Basic Idea of MVB

Local stack and Heap frozen as CHAT does. MVB variables keep track of several bindings. The proper binding is accessed using a consumer id. Adv.: bindings are not reinstalled/unbound when a consumer resumes/fails (there is no speculative work). Disadv.: variable access more complex, and may be non-constant time. MVB Consumer D Consumer C Consumer A Consumer B 1 2 3 4 HEAP

{

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 6 / 1

slide-15
SLIDE 15

MVB Implementation

MVB as List of Values

Structure:

CACHE 1 2 3 MVB Last Id Last Value C1 C3 C2

Behavior:

Measure sgm atr2 pg kalah gabriel disj cs o peep Avg. Accesses 150412 36247 886 562 1720 1084 508 5876 — Misses 1504 2545 147 100 155 103 33 335 — % Misses 1 7 16.6 17.8 9 9.5 6.5 5.7 8.7 Avg.Length 30.6 1 3.5 1.4 1.8 1.3 1.2 2.1 4.9 Avg.Trav. 15.8 1 11.5 1.3 3.8 2.5 1.8 5.4 5

Seems efficient enough —at least in our benchmarks-

◮ Balanced trees, arrays, hash tables. . . also possible. Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 7 / 1

slide-16
SLIDE 16

MVB Implementation

MVB Execution Example

A

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

?− t(X). suspension

ID = 1

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-17
SLIDE 17

MVB Implementation

MVB Execution Example

A 2

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

?− t(X). suspension

ID = 1

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-18
SLIDE 18

MVB Implementation

MVB Execution Example

A MVB

CACHE

1 2

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

?− t(X). suspension

ID = 1

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-19
SLIDE 19

MVB Implementation

MVB Execution Example

A MVB

CACHE

3 1 2

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

?− t(X). suspension suspension

ID = 1 ID = 2

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-20
SLIDE 20

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 3 2 1

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

?− t(X). suspension suspension

ID = 1 ID = 2

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-21
SLIDE 21

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 3 2 1

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). ?− t(X). suspension suspension

ID = 1 ID = 2

2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-22
SLIDE 22

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 3 2 1

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-23
SLIDE 23

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 2 2 1 1 3

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-24
SLIDE 24

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 2 2 1 1 3

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 9.− 3 = 1. 10.− fail. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1. 8.− t(1), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-25
SLIDE 25

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 2 2 3 3 1

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 9.− 3 = 1. 10.− fail. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1. 8.− t(1), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-26
SLIDE 26

MVB Implementation

MVB Execution Example

A MVB

CACHE

2 2 2 3 3 1

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). 12.− X = 1 11.− complete ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 9.− 3 = 1. 10.− fail. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1. 8.− t(1), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-27
SLIDE 27

MVB Implementation

MVB Execution Example

A

Code

t(X), t(1). p(2). p(3). A = 1000. p(A), t(X) :− :− table t/1.

ID = 0

4.− t(1). 12.− X = 1 11.− complete ?− t(X). suspension suspension

ID = 1 ID = 2

5.− t(1), 2 = 1. 9.− 3 = 1. 10.− fail. 6.− 2 = 1. 7.− fail. 2.− t(X), 2 = 1. 1.− p(A), t(X), A = 1. 3.− t(X), 3 = 1. 8.− t(1), 3 = 1.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 8 / 1

slide-28
SLIDE 28

MVB Implementation

Sharing MVB Values

CHAT shares trail, MVB can share MVB bindings among consumers. Each value cell is associated with an interval of consumers ⇒ better cache ratio! Consumer Ids created in sequential order ⇒ MVB list is sorted.

G C1 C2 C3 C = 4 C = 5 C = 6 B = 3 B = 2 A = 1

Value Last Ini Last Last End Id Id Value Last Ini Last Last End Id Id Value Last Ini Last Last End Id Id MVB_B MVB_C C3−C3 C1−C2 3 2 CACHE C3−C3 C2−C2 C1−C1 6 5 4 CACHE MVB_A C1−C3 1 CACHE Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 9 / 1

slide-29
SLIDE 29

MVB Implementation

State Dependencies

C1, C2 y C3 are suspended and their MVB variables created. C1 is restarted and C4 suspends. If C4 is restarted, MVB bindings of C1 have to be also accessed. Our solution: C4 remembers it depends on C1 (always smaller Id). If a binding for C4 is not found ⇒ the binding of C1 is searched for (from that point!).

G C1 C2 C3 C4 C = 4 C = 5 C = 6 B = 3 B = 2 A = 1

MVB_C C3−C3 C2−C2 C1−C1 6 5 4 CACHE Last Last Ini End Value Last Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 10 / 1

slide-30
SLIDE 30

Performance

Experimental Results

Program MVB CHAT XSB sgm 1806 1905 1649 atr2 339.2 353.4 351.0 pg 13.11 13.20 12.03 kalah 19.23 18.82 16.77 gabriel 19.83 19.39 18.42 disj 15.19 15.12 14.02 cs o 29.18 29.28 25.30 cs r 58.19 57.80 51.03 peep 60.01 59.20 52.10 Still room for improvements / optimizations (e.g., simple scheduler). We expect more advantages to appear in benchmarks which generate more memory structures.

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 11 / 1

slide-31
SLIDE 31

Tabling and OR-parallelism

Tabling and OR-Parallelism

Common problem: stack sharing.

◮ Copying approach (MUSE) ⇒ CCall, CAT. ◮ Hashing windows ⇒ Hashing by variable + consumer id. ◮ Version vector ⇒ MVB.

However, not completely similar:

◮ Number of consumers non controllable (unlike really parallel ’or’

branches): Aurora would not work.

Deeper connections interesting to investigate (e.g., tradeoff task creation / task switching / variable access speed).

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 12 / 1

slide-32
SLIDE 32

Summary

Conclusions

Trail management-based implementations (CHAT, SLG-WAM) very well engineered, but can incur speculative work. MVB: suspension-based, does not performe speculative work, but it can incur a non-constant variable access. MVB performance w.r.t. CHAT (or SLG-WAM) ultimately depends

  • n benchmark.

◮ Initial performance results on unoptimized implementations promising.

OR-parallelism ideas can be adapted to tabling.

◮ With care, due to inexact mapping or-parallel tasks / consumers. ◮ But can help to homogeinize or-parallel implementations of tabling. Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 13 / 1

slide-33
SLIDE 33

Summary

A Tabling Implementation Based on Variables with Multiple Bindings

Pablo Chico de Guzm´ an1 Manuel Carro1 Manuel V. Hermenegildo1,2

1School of Computer Science, Technical University of Madrid, Spain 2IMDEA-Software, Spain

ICLP 2009 — Pasadena, CA, USA – July 15, 2009

Pablo Chico de Guzm´ an et al (UPM) A Tabling Implementation. . . ICLP 2009, Pasadena, CA 14 / 1