An OpenCL implementation of a forward sampling algorithm for - - PowerPoint PPT Presentation

an opencl implementation of a forward sampling algorithm
SMART_READER_LITE
LIVE PREVIEW

An OpenCL implementation of a forward sampling algorithm for - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

An OpenCL implementation of a forward sampling algorithm for CP-logic

Wiebe Van Ranst Joost Vennekens

  • KU Leuven

Campus De Nayer

slide-2
SLIDE 2

CP-logic

  • PLP language in family of distribution semantics languages
  • PRISM [Sato,Kameya], Independent Choice Logic

[Poole], CP-logic [Vennekens et al.], …

(E1 : 1) ∨ · · · ∨ (En : n) ← .

FOL formula Atom Probability
 (sum ≤ 1) Condition φ, when true, causes one of the effects Ei (or none if sum < 1). Each of the Ei is caused with probability ϵi.

slide-3
SLIDE 3

Example

  • Random walk
  • Never turn back
  • What is the probability?
  • Of getting stuck
  • Finding exit
slide-4
SLIDE 4

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).

slide-5
SLIDE 5

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 (2/4)

slide-6
SLIDE 6

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 (3/4)

slide-7
SLIDE 7

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,_).

Example (4/4)

slide-8
SLIDE 8

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
slide-9
SLIDE 9

Distribution semantics [Sato]

CP-theory Instance 1 Instance n

(a : α) ∨ (b : β) ← φ. (c : γ) ∨ (d : δ) ← ψ. (a : α) ∨ (b : β) ← φ. (c : γ) ∨ (d : δ) ← ψ. (a : α) ∨ (b : β) ← φ. (c : γ) ∨ (d : δ) ← ψ.

α · δ

β · γ

slide-10
SLIDE 10

Distribution semantics [Sato]

CP-theory Instance 1 Instance n

(a : α) ∨ (b : β) ← φ. (c : γ) ∨ (d : δ) ← ψ.

α · δ

β · γ

b ← φ. c ← ψ.

a ← φ. d ← ψ.

slide-11
SLIDE 11

Distribution semantics [Sato]

CP-theory Instance 1 Instance n

(a : α) ∨ (b : β) ← φ. (c : γ) ∨ (d : δ) ← ψ.

α · δ

β · γ

World 1 World m

Σ Σ

| = | =

Query yes no yes … … … no

b ← φ. c ← ψ.

a ← φ. d ← ψ.

slide-12
SLIDE 12

Distribution semantics

… …

slide-13
SLIDE 13

Inference

  • Problog system 


[De Raedt,Kimmig,Fierens,…]

  • PITA in XSB [Riguzzi, Swift]
  • CVE [Meert, Blockeel]
  • MCINTYRE [Riguzzi]

Exact Approximative All query-based Query
 (+ evidence) All/some 
 proofs Disjoint sum

slide-14
SLIDE 14

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
slide-15
SLIDE 15

Efficient implementation: GPGPU

http://michaelgalloy.com/2013/06/11/cpu-vs-gpu-performance.html

slide-16
SLIDE 16

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
slide-17
SLIDE 17

Approach

CPU GPU

Ground CP-theory

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

slide-18
SLIDE 18

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

Approach

CPU GPU

Ground CP-theory Results

slide-19
SLIDE 19

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

I = {} Repeat: Find applicable rule Sample atom from head Add atom to I Until no more rules

Approach

CPU GPU

Ground CP-theory Results

slide-20
SLIDE 20

Probability tree semantics

… 0.5 0.5 Equivalent [TPLP2009]
 Correctness: sample = branch … …

slide-21
SLIDE 21

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

slide-22
SLIDE 22

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)
slide-23
SLIDE 23

Optimisations

slide-24
SLIDE 24

GrowingHead

best: MCINTYRE, ok: OpenCL

slide-25
SLIDE 25

GrowingBody

best: CVE, ok: OpenCL, PITA, ProbLog

slide-26
SLIDE 26

Bloodtype (non ground)

best: PITA, ok: (C)VE, OpenCL(?)

slide-27
SLIDE 27

Bloodtype (non ground)

best: PITA, ok: (C)VE, OpenCL(?) $1000

slide-28
SLIDE 28

Experimental results

best

  • k

PITA 1 1 CVE 1 1 Problog 1 Problog MC Problog 
 k-best MCINTYRE 1 OpenCL 2 or 3

slide-29
SLIDE 29

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
slide-30
SLIDE 30

Thank you