An OpenCL implementation of a forward sampling algorithm for CP-logic Wiebe Van Ranst Joost Vennekens � KU Leuven Campus De Nayer
CP-logic • PLP language in family of distribution semantics languages • PRISM [Sato,Kameya], Independent Choice Logic [Poole], CP-logic [Vennekens et al.], … Atom Probability FOL formula (sum ≤ 1) ( E 1 : � 1 ) ∨ · · · ∨ ( E n : � n ) ← � . Condition φ , when true, causes one of the effects E i (or none if sum < 1). Each of the E i is caused with probability ϵ i.
Example • Random walk • Never turn back • What is the probability? • Of getting stuck • Finding exit
Example (1/4) (Go(Right,t) : ⅓ ) ∨ (Go(Straight,t) : ⅓ ) ∨ (Go(Left,t): ⅓ ) ← At(p,t) ∧ FourWay(p). � � (Go(Left,t) : ½ ) ∨ (Go(Right, t) : ½ ) ← At(p,t) ∧ Facing(d,t) ∧ TJunction(p,d). (Go(Left,t) : ½ ) ∨ (Go(Straight, t) : ½ ) ← At(p,t) ∧ Facing(d,t) ∧ LeftTurn(p). (Go(Right,t) : ½ ) ∨ (Go(Straight, t) : ½ ) ← At(p,t) ∧ Facing(d,t) ∧ RightTurn(p). � � Go(Left,t) ← At(p,t) ∧ LeftBend(p). Go(Right,t) ← At(p,t) ∧ RightBend(p). Go(Straight,t) ← At(p,t) ∧ Straight(p).
Example (2/4) At(to, t +1) ← At(from, t) ∧ Go(dir,t) ∧ Road(from,dir,to). � Facing(d2,t +1) ← Facing(d1,t) ∧ Go(Left,t) ∧ Next(d2,d1). Facing(d2,t +1) ← Facing(d1,t) ∧ Go(Right,t) ∧ Next(d1,d2). Facing(d, t +1) ← Facing(d,t) ∧ Go(Straight,t). � Next(N,E). Next(E,S). Next(S,W). Next(W,N). � At(Start,0). Heading(East,0).
Example (3/4) Road(1,N,2). Road(1,E,3). Road(2,N,4). Road(2,E,5). … � Road(x,S,y) ← Road(y,N,x). Road(x,W,y) ← Road(y,W,x).
Example (4/4) FourWay(p) ← Road(p,N,_) ∧ Road(p,E,_) ∧ Road(p,S,_) ∧ Road(p,W,_). � TJunction(p,d) ← ¬FourWay(p) ∧ Next(left,d) ∧ Next(d,right) ∧ Road(p,left,_) ∧ Road(p,right,_). LeftTurn(p,d) ← ¬FourWay(p) ∧ Next(left,d) ∧ Road(p,left,_) ∧ Road(p,d,_). RightTurn(p,d) ← ¬FourWay(p) ∧ Next(d,right) ∧ Road(p,right,_) ∧ Road(p,d,_). � ThreeJunction(p,d) ← TJunction(p,d) ∨ LeftTurn(p,d) ∨ RightTurn(p,d). � LeftBend(p,d) ← ¬FourWay(p) ∧ ¬ThreeJunction(p) ∧ Next(left,d) ∧ Road(p,left,_). RightBend(p,d) ← ¬FourWay(p) ∧ ¬ThreeJunction(p) ∧ Next(d,right) ∧ Road(p,right,_). Straight(p,d) ← ¬FourWay(p) ∧ ¬ThreeJunction(p) ∧ Road(p,d,_).
Simplifying assumptions • All theories have been grounded • No negation in bodies • Two-valued well-founded model semantics • Makes both implementation and semantics bit more difficult • Probabilities in the head sum to 1
Distribution semantics [Sato] Instance 1 α · δ ( a : α ) ∨ ( b : β ) ← φ . CP-theory ( c : γ ) ∨ ( d : δ ) ← ψ . … β · γ ( a : α ) ∨ ( b : β ) ← φ . ( c : γ ) ∨ ( d : δ ) ← ψ . Instance n ( a : α ) ∨ ( b : β ) ← φ . ( c : γ ) ∨ ( d : δ ) ← ψ .
Distribution semantics [Sato] Instance 1 α · δ a ← φ . d ← ψ . CP-theory … β · γ ( a : α ) ∨ ( b : β ) ← φ . ( c : γ ) ∨ ( d : δ ) ← ψ . Instance n b ← φ . c ← ψ .
Distribution semantics [Sato] Query yes | = Instance 1 α · δ no World 1 Σ a ← φ . yes d ← ψ . CP-theory … … … β · γ … ( a : α ) ∨ ( b : β ) ← φ . Σ World m ( c : γ ) ∨ ( d : δ ) ← ψ . … Instance n | = no b ← φ . c ← ψ .
Distribution semantics … …
Inference Exact • Problog system [De Raedt,Kimmig,Fierens, … ] Approximative • PITA in XSB [Riguzzi, Swift] • CVE [Meert, Blockeel] • MCINTYRE [Riguzzi] All query-based Query Disjoint All/some (+ evidence) proofs sum
This talk: Sampling with forward chaining • Sometimes no query • Debugging: prob = 0 • Diagnosis: MPE � • Different search strategy • Maybe more appropriate for certain theories • See experiments
Efficient implementation: GPGPU http://michaelgalloy.com/2013/06/11/cpu-vs-gpu-performance.html
Writing efficient GPGPU code • Massive number of simple cores in SIMD • Each core executes dumb code • Be smart about • Memory transfer • Memory access • Good fit
Approach Ground CP-theory CPU GPU 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample Results
Approach Ground CP-theory CPU GPU 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample 1 sample Results
Approach Ground CP-theory CPU GPU 1 sample 1 sample 1 sample 1 sample I = {} Repeat: 1 sample 1 sample 1 sample 1 sample Find applicable rule 1 sample 1 sample 1 sample 1 sample Sample atom from head 1 sample Add atom to I 1 sample 1 sample 1 sample Until no more rules 1 sample 1 sample 1 sample 1 sample Results
Probability tree semantics … 0.5 … 0.5 … Equivalent [TPLP2009] Correctness: sample = branch
Optimisations • [ MEM ] Ensure coalesced memory access • [ INI ] Initialise data structures on GPU • [ PRI ] Use private instead of local memory • [ RAN ] Generate random numbers on GPU • [ RED ] Compute results on GPU • [ CHU ] Start m ≪ n samples on GPU, copy back, repeat + stopping criterion
Benchmarks • Taken from: W. Meert, J. Struyf, and H. Blockeel. CP-logic theory inference with contextual variable elimination and comparison to BDD based inference methods. In Proc. ILP, 2009. • Bloodtype, GrowingBody, GrowingHead • Linux machine with similarly priced GPU,CPU: • Intel Core i7 965 CPU (3.20GHz) • NVIDIA GeForce GTX 295 (GT200)
Optimisations
GrowingHead best: MCINTYRE, ok: OpenCL
GrowingBody best: CVE, ok: OpenCL, PITA, ProbLog
Bloodtype (non ground) best: PITA, ok: (C)VE, OpenCL(?)
Bloodtype (non ground) $1000 best: PITA, ok: (C)VE, OpenCL(?)
Experimental results best ok PITA 1 1 CVE 1 1 Problog 1 Problog MC Problog k-best MCINTYRE 1 OpenCL 2 or 3
Conclusion • Naive forward chaining sampling algorithm • Implemented in a smart way in OpenCL • Complements existing approaches • Not query-based • Different computation strategy • Experimental results • Optimisations really help • Performance is always ok, though never best • Close to formal semantics, maybe easier for extensions
Thank you
Recommend
More recommend