A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU...

24
Predicting cache contents by abstract interpretation A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial College London

Transcript of A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU...

Page 1: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

Predicting cache contents by abstract interpretation

A hierarchy independent approach (ongoing work)

Michael Monerau Chris HankinCourant Institute, NYU

Ecole Normale Supérieure de Paris, France

Imperial College London

Page 2: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

2

Overview

Problem description Abstract Interpretation Cache prediction Related & Future work Conclusion

Page 3: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

3

Cache mechanicsQuick introduction: How do cache work?

Page 4: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

4

Cache mechanics: Cache hit

CPUs

Cache hierarchy

Read / Write

L1

L2

L2

L3

L3

Virtual Memory

Off-chip

On-chip

Page 5: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

5

Virtual Memory

Cache mechanics: Cache miss

CPUs

Cache hierarchy

Read / Write

L1

L2

L2

L3

L3Ask for data

Sends data

Off-chip

On-chip

Page 6: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

6

Cache Level

Cache mechanisms: Low-Level

Cache line...........

An example: 4-Way Associative Cache0.1.2.3.4.5.6.7.

8.9.10.11.

A cache line contains a copy of a Virtual Memory

Block

VM Address % 3 == 0

VM Address % 3 == 1

VM Address % 3 == 2

Page 7: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

7

Cache hierarchies

Cache hierarchies may vary a lot Number of levels Internals of each level Replacement strategies (each level) Write strategies Inter-level strategies Several CPUs, shared/unshared level

Combinatorial explosion !

Page 8: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

8

Predict it!

Knowing cache contents can help WCET (Worst Case Execution Time) Clever allocation on scratchpads

(software-managed small caches in embedded systems)

GoalsModular and hierarchy independent

prediction framework

Page 9: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

9

Abstract InterpretationA quick overview of Abstract Interpretation

Page 10: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

10

Abstract Interpretation: Principle

CONCRETE WORLD ABSTRACT WORLD

Page 11: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

11

Abstract Interpretation: Principle

CONCRETE WORLD ABSTRACT WORLD

T

T

T

T

Page 12: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

12

Abstract Interpretation: Galois

Given two posets and

Best abstraction (ie. most precise) iff Galois Connection :

,C ,A ô

, , ( ) ( )P C Q A P Q P Q ô –

Soundness

is optimal

Page 13: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

13

Abstract Interpretation: Analysis

GoalFind an overapproximation of the abstract state at each control point

Equations (fixpoint)

x = Rand(1, 10)

y = 1y = 0

Print y

x > 5 x <= 5

1.

2. 3.

4.

2 15x

4 2 3 ò3 15x

Page 14: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

14

Abstract Interpretation: Analysis

e.g. with intervals:

x = Rand(1, 10)

y = 1y = 0

Print y

x > 5 x <= 5

1.

2. 3.

4.

1 1[1,10], ] , [x y

2 2[6,10], [0,0]x y

3 3[1,5], [1,1]x y

4 [1,5] [6,10] [1,10]x ò

4 [0,0] [1,1] [0,1]y ò

Page 15: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

15

Cache predictionDescription of the abstract domain for cache prediction

Page 16: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

16

Cache Prediction: Dispatch

Cache Level

Relation Strategy

Stock Strategy

Stock Management

(low-level data organization)

Other levelOther level

Receive / Forward

Receive / Forward

Requests

Report updates

Make Address Available

Candidate locations

L3 L1

L2

Page 17: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

17

Cache Prediction: Priority Goal: Modeling the replacement dynamic

Instead of abstracting locations contentsabstract addresses priorities

Priority for each Virtual Memory Address Or : « the address is not in the cache »

Meaning: Victim is the lowest priority

[0, 1]p n

0p

Page 18: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

18

Cache Prediction: ChangePriority

Main ingredient to implement strategies:

Change Priority(VMAddress, p)

LRU: Just call ChangePriority(.., Highest+1)

FIFO: Call ChangePriority(.., Highest+1) only if the address is not in the cache level

Pseudo-LRU: More complicated, but same idea

Page 19: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

19

Cache Prediction: AbstractionABSTRACTION FOR A LINES CACHEn

({ : [0, 1] { }

/ is injective})

p nVM

p

C=P ™}){ { }:p VM n A P™ ([0, - 1]

P : ( )p P

p ad p ad

p[0, 1] { }

/ is injective

an

{ :

}d , ( ) ( )

n

p

ad VM p ad p ad

p VM

Galois Connection

Page 20: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

20

a4

Cache Prediction: ChangePriority#

ChangePriority#(Ad, pr)

.a1a2a3

a5a6

.

.

Priority

pr.

a1a2a3

a5a6

.

.

Priority

pr

1( )p pr 1( )p pr

Ad a4

Ad a7Ad a7

Ad a4

Moved 0 or 1 down

Moved 1 down

Soundness : #CP CP ô

Page 21: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

21

Cache Prediction: Hits & Misses

CONCRETE WORLD

Miss p(Address)

Hit p(Address)

ABSTRACT WORLD

Let

Miss

Hit/Miss?

Hit

{ } P

{ } P Ö

P

(Address)P p

Page 22: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

22

Cache Prediction: Scratchpad

Virtual Memory

CPU

Cache hierarchy

L1L2L3

Scratchpad

Hardware managed

Analysis gives information:

Possible contents of the cache

Simulate Scratchpad as a « L0 » cache

Heuristic

Software manage

d

Scratchpad allocationstrategy

If (unlikely) y=0

don’t put y on the

scratchpad

Page 23: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

23

Related & Future Work

Related Work [Wilhelm et al. VMCAI’10] and [Reineke et al. SAS’09]:

clever abstract domains, no generic proof, no hierarchy

[Marvadel et al.]: profiling (for scratchpad allocation)

Future work Safe initial states for some replacement strategies

(domino effect, … cf. [SAS’09], [Berg ’06]) Improvements proposed in [SAS’09] Implementation & benchmarks Clever strategies for scratchpads

Page 24: A hierarchy independent approach (ongoing work) Michael Monerau Chris Hankin Courant Institute, NYU Ecole Normale Supérieure de Paris, France Imperial.

24

Conclusion

Modular analysis: Hierarchy-independent Replacement strategy-independent Easy-to-build transfer functions

Formal and modular proofs of soundness

Thank you!