103
1 Aspects of Embedded System Design Mahmut Taylan Kandemir Pennsylvania State University University Park, PA 16802, USA [email protected] Acknowledgements Marilyn Wolfe Mary Jane Irwin Yuanrui Zhang Wei Zhang Vijay Narayanan Seda Ogrenci Memik Hakan Aydin Jack Davidson

Aspects of Embedded System Design

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Aspects of Embedded System Design

1

Aspects of Embedded

System Design

Mahmut Taylan KandemirPennsylvania State University

University Park, PA 16802, [email protected]

Acknowledgements

• Marilyn Wolfe

• Mary Jane Irwin

• Yuanrui Zhang

• Wei Zhang

• Vijay Narayanan

• Seda Ogrenci Memik

• Hakan Aydin

• Jack Davidson

Page 2: Aspects of Embedded System Design

2

Me• My own research

– Compiling for advanced microprocessor systems with deep memory hierarchies

– Optimization for embedded systems (space, power, speed, reliability), with an emphasis on chip multiprocessors

– Energy-conscious hardware and software design

– Runtime system support for data-intensive applications

• Thus, my interests lie in

– Quality of generated code

– Interplay between compiler and architecture

– Static analysis to understand program behavior

– Runtime performance analysis and architecture design

• Visit: http://www.cse.psu.edu/~kandemir/

Outline

• Lecture #1: aspects of embedded system

design

• Lecture #2: compiler directed optimizations

• Lecture #3: power and related issues

• Lecture #4: embedded OS and reliability

Page 3: Aspects of Embedded System Design

3

Aspects of embedded system design

Architectures

and Platforms

Design

Methodologies

Applications

and Environments

Design,

Modeling,

Analysis

Characteristics,

Specifications,

Interactions,

QoS

Software:

threads, mapping,

scheduling

Hardware:

cores, multicores, NoC

Embedded system constraints

Energy

Time Constraints

Processing Speed

Memory

Frequent Disconnectivity

Form Factor

Page 4: Aspects of Embedded System Design

4

Embedded system design

challenges• Strict, quantifiable goals (in most cases)

• Design space is typically very large and highly

irregular (e.g., lots of metrics, lots of alternatives)

• Lack of automated tools for many steps

• Can‟t simulate everything

– We need quick, hierarchical and reasonably

accurate evaluation tools

• In most cases, software and hardware should be

developed concurrently

Applications

• Application characteristics and execution environment should be well studied

• What are embedded applications?• Consumer electronics (cell phones, PDAs,

digital cameras, DVD players)

• Household appliances (dishwashers, microwave ovens)

• Transportation systems

• Medical equipments (pacemakers, glucose monitors)

• National infrastructures (power transmission networks)

8

Page 5: Aspects of Embedded System Design

5

Example: cell phones

• Increasing use worldwide

• Many different applications on-board

• Contain a large amount of circuitry, each of which is carefully designed to optimize performance

• Radio frequency -receiver and transmitter

• Digital signal processor

• A/D conversion

• Control processor

• Power control unit and battery

9

Example: automobiles as

distributed embedded systems

Page 6: Aspects of Embedded System Design

6

Automotive and aviation

electronics

• Functions embedded in vehicles include braking

assistance, active suspension, steering control, etc.

• Subject to stringent timing constraints

• Some functions are safety-critical

• Must operate in real-time

• Must fit within power budget (limited by generator)

• Must be resilient to errors

• In both hardware and software

Other applications

ADSL modem/router ABS brakes

Artificial pacemaker Dishwasher

Page 7: Aspects of Embedded System Design

7

Modeling an Embedded Systems

• Modeling input and output

• Modeling interaction with physical world– Performance (timing) specification

– Power specification

– Others

• Common computation models– Finite state machines

– Turing machines

– Petri nets

– Data flow based models

– Control flow based models

Models of computation

• No one model of computation is good for all

algorithms

• Models effect programming style

• Large systems may require different models of

computation for different parts

– Models must communicate compatibly

Page 8: Aspects of Embedded System Design

8

Data flow versus control flow

• In principle, they are equivalent

– An execution reaching a program point can be labeled as such

• Control flow based models

– Flow of control during execution

– Response to events and interrupts

– Control dependencies

• Data flow based models

– How data is generated and consumed

– Memory performance

– Data dependencies

Metrics• Performance can be measured in multiple ways

– Latency vs. throughput

– Average vs. worst-case vs. best-case

– Peak vs. sustained

• Power/energy

– Power consumption is important for heat generation

– Energy consumption is important for battery life

– Integrated metrics such as Energy-Delay Product (EDP)

• Cost

– Design time vs. lifetime

• Reliability

– Availability, dependability, performability

Page 9: Aspects of Embedded System Design

9

Hardware/software codesign

• Goals

– Optimizing design process

– Optimizing design

• Tasks

– Cospecification and comodeling

– Codesign

– Cosynthesis, optimization, interfacing

– Verification

HW SW HW SW

codesign classic design

Codesign flow

Specification

Partitioning

SW DesignInterface

Design HW Design

Integration

and Test

Evaluation

Page 10: Aspects of Embedded System Design

10

Cosynthesis• Software synthesis

– Code optimization and code generation

• Hardware synthesis

– Works at different layers

• Interface and communication synthesis

• Scheduling

– Instruction scheduling in compilers

– Operation scheduling in architecture

– Process/thread scheduling in OS

Software synthesis and

code generation

• Multilayer software design– Operating systems

• Embedded, real time

• Resource allocation, scheduling

• Compilers

– Code generation and optimization

– Retargetability

• Interfacing

– Between different software components

– Between software components and hardware components

Page 11: Aspects of Embedded System Design

11

Hardware synthesis

• Automated design process that interprets the

description of a desired behavior and creates

hardware that implements that behavior

• Improves designer productivity

• Many commercial tools available

• Can be addressed at different of levels of

abstraction

– Gate level

– Register transfer level

– Algorithmic level

Interface synthesis

• Automated generation of software drivers and

hardware components to ease information flow

between two components

• Different interfacing strategies are possible

– Synchronous (Blocking)

– Asynchronous

– Self timed

– etc

Page 12: Aspects of Embedded System Design

12

Platform-based design

• Design the platform

• Use the platform

requirements past designs

platform

userneeds

product

Work partitioning

• Platform design

– choose, characterize hardware units

– create the system architecture

– optimize for performance, power

• Platform-based product design

– modify hardware architecture

– optimize programs

Page 13: Aspects of Embedded System Design

13

Platform design challenges

• Does it satisfy basic requirements?

• Is it sufficiently customizable? And in the right

ways?

• Is it cost-effective?

• How long does it take to turn a platform into a

product?

Platform design methodology

• Develop an initial architecture

• Evaluate for performance, power, etc

• Evaluate customizability

• Improve platform after each use

Page 14: Aspects of Embedded System Design

14

Platform use challenges

• How do I understand the platform‟s design?

• How do I modify it to suit my needs?

• How do I optimize for performance, power, etc.?

Platform use methodology

• Start with reference design, evaluate differences

required for your features

• Evaluate hardware changes

• Implement hardware and software changes in

parallel

• Integrate and test

Page 15: Aspects of Embedded System Design

15

Embedded architectures

• Application-specific circuits (ASICs)

• Processors

– RISC CPUs

– VLIWs/DSPs

– SoCs

– Multicores (MPSoC)

• Reconfigurable architectures

– Fine grain (FPGAs)

– Coarse grain

– ASIPs, extensible processors (e.g., Tensilica‟s Xtensa)

Tradeoffs

Performance

Fle

xib

ility

Domain-Specific

Accelerators

Reconfigurable

Fabrics

General-Purpose

Processors

DSPs

ASICs

Page 16: Aspects of Embedded System Design

16

Hardware vs. software• Hardware: functionality implemented via a custom

architecture

• Software: functionality implemented in software on a programmable component

• Key differences:– Concurrency

• Processors usually have one “thread of control”– This is changing with multicores

• Dedicated hardware often has concurrent datapaths

– Multiplexing• Software modules multiplexed with others on a

processor (e.g., using an OS)

• Hardware modules are typically mapped individually on dedicated hardware

Embedded vs. general-purpose

processors• Embedded processors may be optimized for a

category of applications

– Customization may be narrow or broad

• We may judge embedded processors using different metrics

– Form factor

– Memory capacity

– Memory system performance

– Predictability

– Reliability

Page 17: Aspects of Embedded System Design

17

RISC processor families

• ARM: ARM7 is relatively simple, no memory management; ARM11 has memory management, other features

• MIPS: MIPS32 4K has 5-stage pipeline; 4KE family has DSP extension; 4KS is designed for security

• PowerPC: 400 series includes several embedded processors; MPD7410 is two-issue machine; 970FX has 16-stage pipeline

• Intel and AMD also have embedded product lines

ARM architecture• As of 2007, about 98

percent of the more than

one billion mobile phones

sold each year use at least

one ARM processor

• As of 2009, ARM processors

account for approximately

90% of all embedded 32-bit

RISC processors

• Used extensively in

consumer electronics,

including PDAs, mobile

phones, digital media and

music players, hand-held

game consoles, and

calculators

ARM9

[Wikipedia]

Page 18: Aspects of Embedded System Design

18

ARM Thumb

• Goal: reduce memory requirements

– Except in the most speed-critical of embedded devices, the cost of memory is much more critical than the execution speed of the processor

• Thumb ISA consists of 16-bit instructions that act as a compact shorthand for a subset of the 32-bit instructions

• Some functions that can be accomplished in a single ARM instruction can only be simulated with a sequence of Thumb instructions

• Expansion happens at runtime (using a dedicated unit)

• Thumb code is typically slower than standard ARM code

• Tradeoff: code size vs. speed vs. power

SPMs vs caches

• Software managed on-chip memory with fast access latency and low power consumption

• Frequently used in embedded computing

– Allows accurate latency prediction

– Can be more power efficient than conventional caches

• Can be used along with caches

• Downside: requires software management

– Not good for certain applications

– Code modifications can be tricky

Page 19: Aspects of Embedded System Design

19

Very long instruction word

(VLIW) processors • The power consumption, hardware cost and

complexity of the superscalar dependence analyzer and scheduler is a major problem

• VLIW processors rely on compile time analysis to identify and bundle together instructions that can be executed concurrently

• Contemporary VLIWs typically have four to sixteen functional units

• Variants of this concept are employed in many embedded processors

– NXP‟s TriMedia, Analog Devices SHARC DSP, TI‟s C6000 family, STMicroelectronics‟s ST200 family

– Tensilica's Xtensa LX2 processor (FLIX)

VLIWs• Compiler has a bigger context from which to

select co-scheduled instructions

• Compilers, however, do not have much runtime information such as cache misses

– Scheduling is, therefore, inherently conservative

• Branch and memory prediction are more difficult

• VLIW performance is highly dependent on the compiler. A number of techniques such as loop unrolling, speculative execution, branch prediction are proven to be critical

Page 20: Aspects of Embedded System Design

20

Traditional VLIW architecture

• Large register file feeds multiple function units

Register file

Add r1,r2,r3; Sub r4,r5,r6; Ld r7,foo; St r8,baz; NOP

ALU ALUL/S

Unit

L/S

UnitFPU

Clustered VLIW architecture

• Register file, function units divided into clusters

Execution

Register file

Execution

Register file

Cluster bus

Page 21: Aspects of Embedded System Design

21

TriMedia (Mediaprocessor)• A VLIW

mediaprocessor family from NXP Semiconductors (formerly Philips Semiconductors)

• Features many DSP and SIMD operations to efficiently process audio and video data streams

• 8 issue slots filling 45 functional units

• High level programma-bility (C and C++)

Exploiting slacks to reduce

energy consumption (1/2)• VLIW functional units (FUs) often are not

completely utilized due to

– lack of available instructions using all units

– data dependences

• Consequently, there are execution slacks

– Some operations can be executed slower without impacting the overall execution time

– Some functional units can be completely shutdown if idle time is long enough

• Compiler can exploit these slacks to reduce energy consumption

Page 22: Aspects of Embedded System Design

22

Exploiting slacks to reduce

energy consumption (2/2)

• Compiler can reschedule instructions for energy

• Goal is to have larger slacks so that

– More opportunities to switch to low power operating modes

– Stay longer in low power modes

• Constraint: performance impact

System-on-Chip (SoC)

• Ability to place multiple functions on a single silicon chip,

cutting development cycle while increasing product

performance and quality

• A typical SoC consists of:

– One microcontroller, microprocessor or DSP core

– Memory blocks including a selection of ROM, RAM,

EEPROM and flash

– Timing sources including oscillators and phase-locked loops

– Peripherals including counter-timers, real-time timers and

power-on reset generators

– External interfaces such as USB and Ethernet

– Analog-to-digital and digital-to-analog converters

– Voltage regulators and power management circuits

Page 23: Aspects of Embedded System Design

23

Multiprocessor SoC (MPSoC)

• An SoC that employs multiple (possibly heterogeneous) processors

• MPSoC components are linked to each other by an on-chip interconnect (e.g., buses, NoC)

• Application parallelization is a big issue

– Hand parallelization vs. compiler guided parallelization

– Other important issues include thread-to-processing unit mapping, data access scheduling, synchronization optimizations

FPGAs

• Integrated circuit designed to be configured after manufacturing

• Contains programmable logic components called logic blocks, and a hierarchy of reconfigurable interconnects that wire blocks together

• Recent trend: combining the logic blocks and interconnects of traditional FPGAs with embedded hard and soft cores and related circuitry to have System-on-Chip

Page 24: Aspects of Embedded System Design

24

Bar() {

int a, b, c, d, e;a = b + c;b = e * d;d = a / b;for(…..) {

a = b + c;b = e * d;for(…..) {

for(…..) {………….………….

foo_a();………….………….

}}………….………….

}foo_b();

}

loop1

loop2

loop3

loop4

loop5

loop6

loop9

loop0

loop1

loop0

loop2

loop3 loop4 loop9

loop5

loop6

loop7

loop7

loop8

loop8

loop10

loop10

0

1

2

10

3

4

9

5

6

7

8

a) Representation 1

b) Representation 2

Codesign space exploration

for a single function• One can employ branch-and-bound search to

find a solution with least latency under the given

area constraint

• To facilitate the search, an auxiliary data

structure can be used to systematically

enumerate all possible combinational mappings

for nodes in an LHT

Page 25: Aspects of Embedded System Design

25

0

1

2

4

S3

5

H0S S

H

H

Loop Hierarchy Tree

Mapping Tree

S0

H1 S1

H2 S2 H2 S2

H3 H3S3 S3

H4 H4 H4 H4 S4S4S4S4

H5 H5 H5 H5 S5S5S5S5

S5H5

R

H

Codesign space exploration

for an entire program

• Handle function calls by traversing the call graph in a post order, so that the codesign exploration is performed and a solution has been found for each callee during the exploration of the caller

– The best solution is recorded for each callee along with the area and latency costs

– Function calls implemented outside the program are assumed to be characterized with pre-estimated costs, e.g., software libraries

Page 26: Aspects of Embedded System Design

26

Cost estimation models for

LHT• Leaf nodes

– Software estimation – compiler based techniques

• Area: 0

• Latency: profiling or WCET analysis

– Hardware estimation – modeling tools

• an FPGA-based modeling tool

• Non-leaf nodes – based on leaf node estimations– Software estimation

– Hardware estimation

Leaf node hardware

estimations

Data Flow Graph0

1

2 5

3

Co-design exploration

Modeling Tool(Hardware Estimation)

4

Compiler

LHT Representation

[Junsub Kim et al in IEEE Transactions on Computers, 2009]

Page 27: Aspects of Embedded System Design

27

Non-leaf node software cost

estimations• Area: 0

• Latency: loop iteration count * (its children‟s total latency) / degree of parallelism

– Two types of dependencies

• Dependencies across child loops

• Dependencies across loop iterations

– Communication cost between hardware and software

• Parent-child communication

• Child-child communication

1

2

3

4

5

Loop

Dependence

Graph

1 2 3 4 5 6 7 8 9 10 11 12 13 ..

Parallel iterations = 4

Iteration

Dependences for

loop0

Degree of parallelism = min

(parallel iterations, number of

CPUs)

loop0

1 2 3 4 5

Children‟s latency

= node1 + max (node2, (node3

+ node4)) + node5)

Page 28: Aspects of Embedded System Design

28

Non-leaf node hardware

estimations• If a non-leaf node is implemented in

hardware, its entire sub-LHT is assigned to

hardware

• Pipelined design is considered

Cost evaluation for the entire

LHT• Before branch-and-bound search starts, the

area costs of all nodes in the mapping tree are

estimated based on node types

• The search tries to calculate the total area of a

mapping by accumulating the area values when

traveling down along each path

• If the area constraint is met, performance cost is

estimated in a bottom-up fashion on the LHT for

the root, using non-leaf node cost models

Page 29: Aspects of Embedded System Design

29

Possible extensions

• Codesign for more complex hybrid embedded architectures

– Can still use branch-and-bound search

– Can build cost estimation models based on the characteristics of the underlying platforms

GPUsIBM CellFPGAsMulticores

Root

Potential research topics

• Characterization of multithreaded embedded applications

• Design and implementation of multi-FPGA systems

• Multicore DSP design and optimization

• Application

optimization for

heterogeneous

systems

• Novel codesign

strategies targeting

hybrid systems

Page 30: Aspects of Embedded System Design

30

Compiler Directed

Optimizations

Mahmut Taylan KandemirPennsylvania State University

University Park, PA 16802, [email protected]

Motivation• Increasing “software content” in embedded

systems

– Past: 10% SW, 90% HW

– Current: 70% SW, 30% HW

– Future: 90% SW, 10% HW

• Traditionally, software optimizations consider performance

• Additional constraints in embedded computing domain:

– Memory space (data and instructions), energy/power behavior, error resilience

Page 31: Aspects of Embedded System Design

31

Challenges

• Retargetability

• Extensibility and adaptability

• High-quality code

• Portability

• Robustness

• Complete package

Software optimizations

• Algorithm and Application Design

• Compiler Optimizations

– High Level (source level)

– Low Level (code generation)

• Operating System Control

– Includes runtime optimizations as well

Page 32: Aspects of Embedded System Design

32

Compiler optimizations

• Classical optimizations

– Target high end machines

– Typically do not have power constrains or

memory space limitations

• Embedded system specific optimizations

– Performance

– Memory space

– Power (will be covered later) –Lecture #3

– Reliability (will be covered later) –Lecture #4

Classical optimizations

• Back-end optimizations

– Instruction selection, resource allocation, scheduling,

etc.

• High level optimizations

– Loop optimizations

• Linear transformations, tiling, loop merging/distribution

– Data layout optimizations

• Changing memory layout of data, dimension re-

indexing

• Parallelism related optimizations

Page 33: Aspects of Embedded System Design

33

Exercise #1

for (i=0;i<N;i++)

for (j=0;j<N;j++)

a[j][i] = b[j][i]+1;

for (j=0;j<N;j++)

for (i=0;i<N;i++)

a[j][i] = b[j][i]+1;

Exercise #2

for (i=1;i<N;i++)

for (j=0;j<N-1;j++)

a[j][i] = a[j+1][i-1]+1;

for (i=1;i<N;i++)

for (j=0;j<N-1;i++)

t[i][j] = t[i-1][j+1]+1;

Page 34: Aspects of Embedded System Design

34

Exercise #3

for (i=0;i<N;i++)

for (j=0;j<N;j++)

… = a[i] + b[j];

for (jj=0;jj<N;jj=jj+q)

for (i=0;i<N;i++)

for (jjj=jj;jjj<min(N,jj+q);jjj++)

… = a[i] + b[jjj];

Loop transformations

• Data dependencies

may be within or

between loop

iterations

– The latter is more

problematic to handle

• Any code

transformation should

preserve data

dependencies [High-PerformanceEmbedded Computing,M. Wolf]

Page 35: Aspects of Embedded System Design

35

Types of loop transformations

• Loop permutation changes order of loops– Loop interchange is a specific instance

• Loop tiling helps to exploit temporal reuse in outer loop iterations

• Loop unrolling copies the loop body

• Loop fission creates separate loops for statements in the loop body

• Loop fusion combines bodies of neighboring loops

• These optimizations can be used for maximizing cache performance and/or improving parallelism

Example: loop permutation and

fusion

for (i=0; i<N; i++)

x[i] = a[i] * b[i];

for (i=0;i<N;i++)

y[i] = c[i] * a[i];

Original loop nest

for (i=0; i<N; i++)

{ x[i] = a[i] * b[i];

y[i] = c[i] * a[i]; }

After loop fusion

Page 36: Aspects of Embedded System Design

36

Embedded system specific

optimizations• Instruction space optimizations

– Offset assignment

– Code positioning

• Data space minimization

– Memory space reuse

– Compiler directed data compression

• Compiler directed memory hierarchy design

• WCET estimation

• Power optimization (more on this later)

• Reliability optimizations (more on this later)

Minimizing code space• Smart storage assignment

– Address assignment to variables

– Effective use auto-increment/decrement addressing modes in DPSs

• Code compression– Software Approach

• Common sequences are extracted and placed in a directory

• Instances of these sequences are replaced by mini-subroutine calls (automatic subroutine creation)

– Hardware Approach

• New instructions are defined

• Flexible dictionary structures with architectural support

Page 37: Aspects of Embedded System Design

37

Storage assignment

• Many DSPs have limited addressing modes (e.g., TMS320C55x)

• They use address registers to access memory

• No complex indexing modes; instead they have auto-increment/decrement modes

• Compiler support is needed to minimize the number of explicit assignments to address registers

• Address instructions can constitute up to 55% of total program bits

Use of address registers

…..x….y….add r4, M(AR)

AR=AR+q

sub r8, M(AR)

…..xy….add r4, M(AR+)

sub r8, M(AR)

Page 38: Aspects of Embedded System Design

38

Offset assignment problem

• Simple offset assignment

– One address register

– Works with +1/-1 offset

– Operates on a single basic block at a time

• General offset assignment

– Multiple registers, larger offset values, inter-

basic block analysis, etc

Simple offset assignment

Based on order of declaration:

a,b,c,d,e,f,g,h

Based on order of first use:

c,d,f,h,a,b,e,g

Based on compiler analysis:

a,c,h,g,b,e,f,d

c = c + d + f

a = h – c

b = b + e

c = g – b

a = a - c

Page 39: Aspects of Embedded System Design

39

Simple offset assignment

• Access sequence for “z=x op y” is “xyz”

• Access sequence for an ordered set of operations is the concatenated access sequences for each operation in the appropriate order

• Cost of assignment: the number of adjacent accesses of variables that are not assigned to consecutive places

• Can be formulated as Graph Covering [S. Liao, MIT]

Access graph

e

c

hd

b

ga

f2

4

1

1

1

22

1

1

c,d,f,c,h,c,a,b,e,b,g,b,c,a,c,a

Page 40: Aspects of Embedded System Design

40

Access graph

e

c

hd

b

ga

f2

4

1

1

1

22

1

1

(selected paths are in pink)

General offset assignment

• General offset assignment (GOA) is the problem

of optimizing the memory layout when there are

multiple address registers

• Solutions break access sequence into multiple

sequences and then solve the SOA problem

Page 41: Aspects of Embedded System Design

41

General offset assignment

• Straightforward approach

– Fix the access sequence

– Form subsequences

– Solve a separate SOA for each subsequence

General offset assignment

• Three approaches for assigning variables to

address registers

– Greedy algorithm [Luepers & David 1998]

– Heuristic approach that iteratively partitions

variables [Sugino et. al 1996]

– Coalescing nodes in the access graph [Zuang et.

al 2003]

Page 42: Aspects of Embedded System Design

42

General offset assignment

• Access sequence:a d b e c f b e c f a d

• Sequence 1: a b c b c aSequence 2: d e f e f d

• Memory layout

f

ba

d

c

e

c

b

a

e

e

f

a b c d e f

An alternate approach

• Modify code sequence instead of memory layout

• Problems:

– Data dependences

– Performance issues (i.e., conflict with the code

scheduler)

• Extension to array computations

Page 43: Aspects of Embedded System Design

43

Memory placement of

program code• Goal is to place code

carefully in memory to

improve cache

performance

• Possible cache conflicts

may be determined

using addresses;

interesting conflicts are

determined through

analysis

• May require program

padding

McFarling

• Analyzed program structure, trace information

• Annotated program with loop execution count,

basic block size, procedure call frequency

• Walked through program to propagate labels,

group code based on labels, place code groups

to minimize interference

Page 44: Aspects of Embedded System Design

44

Pettis and Hansen

• Profiled programs using gprof

• Put caller and callee close together in the program, increasing the chance they would be on the same page

• Ordered procedures using call graph, weighted by number of invocations, merging highly-weighted edges

• Optimized if-then-else code to take advantage of the processor‟s branch prediction mechanism

• Identified basic blocks that were not executed by given input data; moved to separate processes to improve cache behavior

Reducing data memory area

(1/4)

Reusing the same memory space

– Can reduce capacity misses

– Can lead to smaller memory in embedded design

for(i=0;i<N;i++)

… = c[i]

for(i=0;i<N;i++)

b[i] = a[i]

for(i=0;i<N;i++)

… = c[i]

for(i=0;i<N;i++)

c[i] = a[i]last use

Page 45: Aspects of Embedded System Design

45

for(i=1;i<N;i++)

for(i=0;j<N-1;j++)

a[i][j] = ….

…. = a[i-1][j+1]

Reducing data memory area

(2/4)

iteration (i j)T write into a[i][j]

iteration (i+1 j-1)T read from a[i][j]

After (i+1 j-1)T, memory location of a[i][j] can be

used for storing another element

Reducing data memory area

(3/4)Strategies:

– Inter-variable

• Use a[] instead of b[]

– Intra-variable

• Use a[3] instead of a[44]

Re-writing the code is a big issue!

Page 46: Aspects of Embedded System Design

46

Reducing data memory area

(4/4)

• One method:

– Divide data arrays into (disjoint) chunks

– Create a node for each chunk

– If two chunks have overlapping lifetimes,

put an edge between them

– The result is an Interference Graph (IG)

– Color the graph (remember this?)

92

Example: NUFFTcone L l

rl

rl’

alpha

rll

temp5

Rll temp3

temp4

Angll

p

Nphi la lb

temp1

temp2

temp

Lrl

rll

Angll

cone

rl’

Rll

p

Nphi la lb

temp1

temp2

temp

temp3

temp4

temp5

alphalcone L l

rl

rl’

alpha

rll

temp5

Rll temp3

temp4

Angll

p

Nphi la lb

temp1

temp2

temp

Lrl

rll

Angll

cone

rl’

Rll

p

Nphi la lb

temp1

temp2

temp

temp3

temp4

temp5

alphal

Interference Graph

Coloring Interference

Graph

• Variables with the same

color have non-overlapping

lifetimes

•Variables cone, rl‟, rll, Angll

and l can share the same

storage.

Function Name Original Storage

Optimized Storage

Reduction

test.m 28751 26541 2210

fmm.m 1180 816 364

cluster_fmm.m 15953 12297 3646

trans_fmm.m 22125 16885 5240

~17% memory

reduction!

Page 47: Aspects of Embedded System Design

47

Memory occupancy• MMO: Maximum

memory occupancy– captures the

amount of memory that needs to be allocated for the application

• AMO: Average memory occupancy– important in a

multiprogramming based environment where multiple appls compete for the same space

• Drops in the curve indicate recycling

Compiler-guided data compression

for reducing memory consumption • Goal

– Keep the data block in the on-chip memory even if the reuse distance is large

• Compress data blocks with large inter-access times

• When next request comes, decompress the data block and forward it to the requester

• Advantages

– Data is kept on-chip

– Less memory occupation

• Drawback

Decompression

• We should not compress the data block if its reuse distance is short

• Reduced on-chip space utilization

Page 48: Aspects of Embedded System Design

48

Challenges

• Which data blocks should be compressed and decompressed

• Order of compressions and decompressions?

• Data sharing across the processors must be accounted for

– Decisions should be made based on global data access patterns

• Original execution cycle count should not increase excessively

– Need to be careful about the critical path of execution

– Complex compression/decompression algorithms should be avoided

Additional compiler tasks• Divide data arrays into tiles

• Compiler produces two (helper) threads– Compressor and decompressor

• Compressor implements data tile compressions

• Decompressor implements data tile decompressions

• Scheduling these threads is the key– In particular, decompressions can come in the critical

path of execution

– Decompressions can be overlapped with compressions (pre-decompression)

• Tradeoffs between memory space consumption and performance

Page 49: Aspects of Embedded System Design

49

Experimental evaluation • Memory space occupancy for a stencil code

• 20 epochs with the same number of execution cycles

Memory

occupancy of

BASE

continuously

increases

The best space

savings are

achieved with the

CD+LF version

Combines data

compression

and dead block

recycling

Compiler-directed memory

hierarchy design

• Software-managed hierarchies can be preferable against hardware counterparts in embedded computing

– Usually the best choice for embedded systems that execute a single application

• Customized memory hierarchy that suits the needs of the application

– Data movements are handled by software

• Energy efficient (no dynamic lookups)

• Can be applied to single core as well as multicore design

Page 50: Aspects of Embedded System Design

50

Data reuse and data locality

• Reuse

– Multiple use of the same data

– A characteristic of application; determined by

access pattern

– Independent of memory architecture

• Locality

– Catching the reused data in fast memory

– Depends on fast memory capacity, management

policy, and application access pattern

Objective of locality optimization

• Converting reuse into locality

– Loop optimizations

– Data layout transformations

– or both…

• Requires program analysis, checking data

dependences, capturing data reuse, and

transforming code

Page 51: Aspects of Embedded System Design

51

Representation

• Each array reference represented by

HI + c (an affine function)

• I: iteration vector (loop indices)

• H: access (reference) matrix

• c: offset vector

• Example:

for i = 1, N

for j = 1, N

… U[i+1][j+2]

1 0 1

0 1H=

2c=,

Data reuse vectors

• Data reuse analysis

– HI+c = HJ+c H(I-J)=0, r=I-J

– r: temporal reuse vector

– H‟I+c = H‟J+c H‟(I-J)=0, r‟=I-J

– r‟: spatial reuse vector

• Example

– In a nest with loops i, j, k

– V[i][k] has temporal reuse in j loop

– Successive iterations of j loop access the same array element

Page 52: Aspects of Embedded System Design

52

What does reuse vector say?

• If we have two levels of memory

– Fast memory (small, energy-efficient)

– Slow memory (large, power-hungry)

• We can reuse vectors to guide data transfers

– V[i][k] has temporal reuse in j loop

– Bring V[i][1..N] into fast memory before j loop

– Write it back to slow memory after j loop

– Very good (expected) energy/performance

behavior during execution of j loop

Playing with reuse vectors

• If r is a reuse vector and T is a loop

transformation, Tr is the new reuse vector

• Optimization problem

– Use loop transformations for modifying reuse

vector(s)

– Select a T such that Tr is in a desired form

– This can be used for locality optimization, or

customized memory hierarchy exploration

Page 53: Aspects of Embedded System Design

53

Types of reuse vectors

• r = [0,0,0,1,0,0]T

– Reuse in a single loop: single fast memory

• r = [0,0,1,0,1,0]T

– Reuse in multiple levels: multi-level memory

• Loop transformations can convert one type of

reuse vector into another

Types of transformations

• [0,0,0,1,0,0]T [0,0,0,0,1,0]T

– Changes reuse level

– Affects capacity of fast memory

• [0,0,0,0,1,0]T [0,0,0,1,0,1]T

– Changes the number of reuse levels

– Affects the number of memories in the hierarchy

Page 54: Aspects of Embedded System Design

54

Exploiting temporal locality in

memory design

Array

Index

Values

Time

Reuse

Region

Can be kept in faster

memory

Exploiting temporal locality in

memory design (multiple levels)Array

Index

Values

Time

in the fastest

memory

in the next

fastest memory

Page 55: Aspects of Embedded System Design

55

Memory trees

Individual memory trees

Combined memory tree

[Catthoor et al 98]

Multi-level on-chip memory

hierarchy design • Alternatives

(a) pure shared memory

(b) pure private memory

(c) memory space across a single level

(not a hierarchy)

(d) hierarchy based design

• In the most general case

– A “hybrid” architecture

– Each processor can see a different memory hierarchy image

P

IN

P P P P P

SM

(a)

P

IN

P P P P P

PM

SM

SMPM PM

SM

SM

P

IN

P P P P P

PM PM PM PM PM PM

(b)

P

IN

P P P P P

PM PMSM SM

(c)

(d)

Page 56: Aspects of Embedded System Design

56

Overview of a profiler/compiler

directed approach Input program is divided into phases

and profiled/statically analyzed

The profile/analysis data data gives

Data blocks accessed by each proc

An estimation of the number of

accesses to each data block by

each processor

This information is then passed to a

solver, which

Determines the locations of data

blocks for each phase

Preferred on-chip memory hierarchy

This information is passed to the

compiler

Modifies the application code

accordingly to insert explicit data

transfer calls

Input

Output

Compiler

AnalysisProfiling

Solver

Code

Modifier

Varieties of performance

metrics• Worst-case execution time (WCET):

– Factor in meeting deadlines

• Average-case execution time:

– Factor in identifying problematic spots

• Best-case execution time (BCET)

– Factor in coming up with more realistic bounds

(when used along with WCET)

Page 57: Aspects of Embedded System Design

57

Performance analysis

techniques• Simulation

– Not exhaustive

– Cycle-accurate CPU models are often available

• WCET analysis

– Formal method; may make use of some

simulation techniques

– Bounds execution time but hides some details

Sources of variations• Inputs

• Runtime program paths

• Execution-specific timing

– Caches

– Pipelines

– Branch Prediction

– Speculation

– OOO Execution

if

thenelse

L2 or

MemoryCacheTo Processor

From Processor

Blk X

Blk Y

Page 58: Aspects of Embedded System Design

58

How to Estimate WCET

Safely and Accurately

• Estimated WCET must be:

– Safe

– Tight

• Industry practice: measurement + safety margin

• Measurement based approaches are not safe

• Another promising approach: static WCET analysis

Potential research topics

• Compiler directed memory hierarchy design

• Scratch-pad optimizations for multicore

architectures

• WCET analysis for cache based multicores

• Global code analysis for tighter WCET and

BCET

• Code optimizations for multicore embedded

systems

Page 59: Aspects of Embedded System Design

59

Last class

• Instruction space optimizations

• Data space optimizations

• Reuse vectors and their importance

Representation

• Each array reference represented by

HI + c (an affine function)

• I: iteration vector (loop indices)

• H: access (reference) matrix

• c: offset vector

• Example:

for i1 = 1, N

for i2 = 1, N

… U[i1+1][i2+2]…

1 0 1

0 1H=

2c=,

i1

i2I= ,

i1+1

i2+2HI+c=

Page 60: Aspects of Embedded System Design

60

Data reuse vectors

• Data reuse analysis

– HI+c = HJ+c H(I-J)=0, r=I-J

– r: temporal reuse vector

– H‟I+c = H‟J+c H‟(I-J)=0, r‟=I-J

– r‟: spatial reuse vector

• Example

– In a nest with loops i, j, k

– V[i][k] has temporal reuse in j loop

– Successive iterations of j loop access the same array element

for(i=1;i<N;i++)

for(i=0;j<N-1;j++)

a[i][j] = ….

…. = a[i-1][j+1]

Example calculation

iteration (i j)T write into a[i][j]

iteration (i+1 j-1)T read from a[i][j]

r = (i+1 j-1)T – (i j)T = (1 -1)T

Page 61: Aspects of Embedded System Design

61

Ranking reuse vectors

• Which one is good?

– (1 0 0)T or (0 1 0)T or (0 0 1)T

• Can we change a reuse vector?

– E.g., how can we go from (1 0)T to (0 1)T ?

• Answer: using loop transformations

– If I = (i1 i2)T is the original iteration vector and we

apply a linear transformation represented by T, it is transformed to I’ = TI

– And, HI+o is transformed to HT-1I’+o (Why?)

– And, r is transformed to r’=Tr (Why?)

– Our goal is to find T such that r’ is in a desired form

Potential uses of r

• Data locality optimization

• Memory space minimization

• Memory hierarchy design

– r = (0 0 0 1 0 0)T

• Reuse in a single loop: single fast memory

– r = (0 0 1 0 1 0)T

• Reuse in multiple levels: multi-level memory

Page 62: Aspects of Embedded System Design

62

Power and Related Issues

Mahmut Taylan KandemirPennsylvania State University

University Park, PA 16802, [email protected]

Motivation

• Power and energy are first-class parameters in many embedded designs and execution environments

• Memory energy is particularly problematic

• Support for low-power operating modes motivates for energy-aware optimizations

• Code-level optimizations and data layout changes may increase savings

• The goal is to save energy/power without significantly impacting performance

Page 63: Aspects of Embedded System Design

63

Heat becoming an

unmanageable problem!10,000

1,000

100

10

1

„70 „80 „90 „00 „10

Pow

er

Density (

W/c

m2)

4004

8008

8080

8085

8086

286 386

486

Pentium®Hot Plate

Nuclear Reactor

Rocket Nozzle

Sun‟s Surface

Intel Developer Forum, Spring 2004 - Pat Gelsinger

(Pentium at 90 W)

Cubic relationship between the cycle time and power

Power and energy design space:

a hardware perspectiveConstant

Throughput/LatencyVariable

Throughput/Latency

Energy Design Time Non-active Modules Run Time

Active

Logic Design

Reduced Vdd

Sizing

Multi-Vdd

Clock Gating

DFS, DVS

(Dynamic

Freq, Voltage

Scaling)

Leakage + Multi-VT

Sleep Transistors

Multi-Vdd

Variable VT

+ Variable VT

Page 64: Aspects of Embedded System Design

64

Low-power operating modes• Each mode is characterized by

– Per access (or per cycle) energy consumption

– Resynchronization cost

• Selecting the best mode involves a tradeoff between performance and energy consumption

• Compiler/OS/user must decide what to shut down (or switch to a low power mode) and when to do so. Two cases to consider:

– If we shut down a component and that component is needed again quickly, an annoying delay might occur when it is restarted

– On the other hand, if we wait too long to shut down a component, energy may be wasted unnecessarily

• The objective then is to carefully develop a strategy that decides about what to shut down and when

Proactive approach

• A Proactive Strategy is about predicting the future

• A compiler can analyze data access patterns and map this information to component use

• An OS can look at past access pattern information and predict what would happen in the future

• A combination can work by letting the compiler pass application-wide information to the OS; the latter then can make global (workload wide) decisions considering inputs from all co-runners

Page 65: Aspects of Embedded System Design

65

Activity clustering

• A generic technique

• Goal

– Perform accesses in a short period of time

– Increase lengths of idle periods

• Result

– Can switch to a more aggressive low power mode

– Can stay in a low power mode longer

– Can minimize state transitions (reliability angle)

Sample energy consumptions

and resynchronization costs

(memory)Operating

Mode

Energy

Consumption

Resynch

Cost

ACTIVE 3.570 nJ 0

STANDBY 0.830 nJ 20

NAP 0.320 nJ 300

POWERDOWN 0.005 nJ 9000

Page 66: Aspects of Embedded System Design

66

Compiler-directed operating

mode selection• Estimating idle periods

– Easy for array-based applications

• Can be conservative in others

– Requires mapping from cycles to loop iterations

• Preactivating memory banks– Not to incur re-synch costs

– Implementation similar to compiler-directed prefetching

Iterations and access patterns

• Each loop nest can be represented using a set of iterations (iteration space):

{I} = {(1,1,1),(1,1,2)…,(1,1,n),

(1,2,1),(1,2,2),…,(n,n,n)}

. An access pattern is a function from iteration space to data space

{I} {D}

. Data space (array space) consists of all array indices

{D} = {(1,1),(1,2),…(1,n),(2,1),…,(m,m)}

Page 67: Aspects of Embedded System Design

67

Classification and optimization:

a data centric strategy

• {I}all : all iterations in a given nest

• Assuming two memory banks, {I}all can be written as – {I}all = {I}01 U {I}10 U {I}11

• Instead of executing iterations in {I}all in their original order, we can execute– {I}01 {I}11 {I}10

• Not easy and not always possible

Pattern classification

• A two-bank memory system

• Three different access patterns

• {I}01 = {I2,I3}

• {I}10 = {I1,I4}

• {I}11 = {I0,I5}

• Each of them is a class

B0

B1

I0

I1

I2

I3

I4

I5

Page 68: Aspects of Embedded System Design

68

Pattern optimization

• Going from

{I}all to {I}01 {I}11 {I}10

• Converting

I0 I1 I2 I3 I4 I5

to

I2 I3 I0 I5 I1 I4

B0

B1

I2

I3

I0

I5

I1

I4

Original access pattern

B0 B1

I0

I1

I2

I3

I4

I5

Page 69: Aspects of Embedded System Design

69

Optimized access pattern

B0 B1

I2

I3

I0

I5

I1

I4

Problems and solutions

• How to enumerate iterations in a given class?

– A polyhedral tool can be used

– Example question to a polyhedral tool:

• Give us all iterations that access only the first bank

• How to handle data dependences?

– Capture them in a graph and traverse the

graph using directed edges

Page 70: Aspects of Embedded System Design

70

Class-level dependence graph

(CLDG)

• Each node is a class

• An edge from node {I}i to node {I}j indicates that there is a data dependence from an iteration in {I}i to an iteration in {I}j

• Traversing this graph using edges gives a legal execution order

• There might be more than one legal order

• Select the one that maximizes duration of idleness

Optimization strategy

• Associate a bit vector with each class– e.g., 10001 indicates that only the first and the last

banks (of a five-bank system) are accessed

– All iterations in a class are executed successively

• In going from one node to another, we need to minimize the bit transitions– Intra-class vs inter-class

• A classical scheduling problem (energy-aware scheduling)

• Lots of algorithms in literature – e.g., list scheduling

Page 71: Aspects of Embedded System Design

71

Transformations

• Node Merging:

– Too many nodes in CLDG

– Reduces the number of nodes and the effectiveness of

our strategy

– Sometimes it is a Must-Do optimization (cyclic CLDGs)

• Node Splitting:

– To break a large cyclic dependence chain

Percentage energy savings

01020304050

w/out cache with cache with cache + locality

Page 72: Aspects of Embedded System Design

72

Heap and garbage collector• Heap

– All Java objects created by the application are

allocated from the heap

• Garbage Collector

– Reclaims heap memory occupied by objects no

longer needed by the application

• How Does M&S Garbage Collector works?

– Mark – find out garbage

– Sweep – free the memory occupied by garbage

– Compact – combine fragments (optional)

Mark / sweep / compaction

rootA

B

C

D

E

F

G

rootA

B

C

D

E

F

G

root

B

E

G

rootB

E

G

Before GC

Live Garbage Unknown Free

After Mark After Sweep After Compact

Page 73: Aspects of Embedded System Design

73

Banked memory

Bank1

VDD

Bank2

VDD

Bank3

VDD

Bank4

VDD

Bank5

VDD

Bank6

VDD

1. Each bank can be turned on/off independently

2. When a bank is turned off, it consumes very little

energy and data in it is lost

3. After GC, turn off banks not containing live objects

Heap

GC controlled bank turnoff

BANK1 BANK2 BANK3 BANK4

OFF OFF OFF OFFT=0

OFF OFF OFFT=1 A

T=50 A B C D E F G

T=100 A B C D E F G

OFFT=200 A C D G GC

Live

Garbage

Energy

wasted

Page 74: Aspects of Embedded System Design

74

Impact of GC-controlled bank

turnoff

0102030405060708090

100C

alc

ula

tor

Cry

pto

Dra

go

n

Elite

Ks

ha

pe

Kv

ide

o

Kw

ml

Ma

ny

ba

lls

Ma

thF

P

Min

i

Mis

sile

s

Sc

he

du

ler

Sta

rcru

ise

r

% E

ne

rgy

On average, 30% heap energy is saved

Impact of GC frequency

0

20

40

60

80

100

Calculator Dragon Kvideo Kwml Missiles

%

Heap

En

erg

y

10 40 75 100 250 Out of Memory

More frequent GC

Earlier detection of banks containing only garbage

-More memory accesses-More CPU operations-Longer execution time

Page 75: Aspects of Embedded System Design

75

Adapting GC frequency

automatically• Different applications may have different optimal

frequencies

• Even different phases of a single application can

have different optimal frequencies

• Adaptive

– Invoke GC whenever there is an opportunity to turn

off a bank

– Should not invoke GC unless a certain number of

objects have become garbage

Time

LiveSize

t1 t2GC is invoked at t1, t2

Garbage + Live

Live

Objects created during [t1,t2]k1 = (h2-a1)/(t2-t1)

h1

a1

a2

h2

Garbage created during [t1,t2]k2 = (h2-a2)/(t2-t1)

Page 76: Aspects of Embedded System Design

76

GC invocation: case 1

If, after GC, at least 2 banks can be

turned off, the garbage collector

should be invoked

b(hi+si)-b(hi+si-k2(ti-t2)) 2

b(x): the number of banks for size x

hi: the total object size in the heap

si: the size of the object to be allocated

t2: time of previous collection

GC invocation: case 2

If only 1 bank can be turned off,

then the space GC creates must allow

the application to run an interval no

shorter than L

b(hi+si)-b(hi+si-k2(ti-t2)) = 1

and

b(hi+si-k2(ti-t2))B-(hi+si-k2(ti-t2)) k1L

B: the size of a bank

Purpose: to avoid thrashing

Page 77: Aspects of Embedded System Design

77

GC invocation: case 2 (thrashing)

Turn offBank2

Turn onBank2

Time

Live Size

Bank1

Bank2

T1 T2 T3

GC is invoked at T1, T2 and T3

Impact of adaptive GC invocation

0

20

40

60

80

100

120

140

160

180

200

Crypto Kvideo Kwml Scheduler

He

ap

En

erg

y

10 40

75 100

250 500

base adpt

Page 78: Aspects of Embedded System Design

78

Object lifetime stages• Alive

– Will be used in the future

• Last used

– Will never be used in the future, but still reachable from

the roots

• Dead

– Unreachable from the roots, but not reclaimed

• Free (Collected)

– Reclaimed by Garbage Collector

– Returned to the pool of free memory

Object lifetime stages

Alive Last Used Dead

Allocate Last use Died GCed

FreeFree

Page 79: Aspects of Embedded System Design

79

Cache line stages

Cache-

line

Stage

Contains bytes from objects in lifetime

stage:Note

Alive Last used Dead Free

Alive Yes Possible Possible Possible

Last

UsedNo Yes Possible Possible

Turn

off

cache-

line to

save

energy

Dead No No Yes Possible

Free No No No Yes

Cacheline Stages Distribution Over Runtime (1)

0%

20%

40%

60%

80%

100%

1 5 9

13

17

21

25

29

33

37

41

45

49

Time

Heap

Cach

e FREE

DEAD

LASTUSED

ALIVE

INVALID

Benchmark:

Webviewer

Page 80: Aspects of Embedded System Design

80

Cacheline Stages Distribution Over Runtime (2)

0%

20%

40%

60%

80%

100%

1 5 9

13

17

21

25

29

33

37

41

45

49

Time

Heap

Cach

e FREE

DEAD

LASTUSED

ALIVE

INVALID

Benchmark:

Calculator

• Last class

– Reuse vectors and their importance

– Activity clustering

• Today

– Compiler directed power optimizations

– OS based approaches

– Software based approaches to reliability

problems

Page 81: Aspects of Embedded System Design

81

Power Mode Control

• Transition to a low power mode after a period of time

• Reactive vsproactive

Time

Active

Power-Down

Standby

Napping

Multicore sensors and controls

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

PEMemory

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

NIC

R

• Apply DVFS

– Global DVFS

• Power/perf/

fault “sensors”– current & temp

– hw counters• Turn off idle and

faulty PEs

– Local DVFS• Static (set V&F

per core)

• Dynamic (adjust V&F in response to core idleness)

Page 82: Aspects of Embedded System Design

82

Exploiting load imbalance

Compiler does both loop iteration assignment andvoltage assignment

for i: 1..1024

for j: i..1024

..X[i][j]..

Block Assignment

PE0

PE1

PE2

PE3

V0

V1

V2

V3

Voltage Assignment

(V0 > V1 > V2 > V3)

Goal: Save as much energy as possible without incurring an excessive performance penalty

Necessary compiler support

• Loop nest parallelization– Parallelize the outermost loop that carries no data

dependence

– This helps to minimize synchronization cost

For loop body cost of LP0: 256*1024*L

P1: 256*(1024-257+1)*L

P2: 256*(1024-513+1)*L

P3: 256*(1024-769+1)*L

Load estimation Iteration count estimation

Per-iteration cost estimation

Voltage and frequency assignment Processor with largest workload gets highest V &

fastest F

For the remaining processors, choose the lowest V & slowest F that do not cause the execution time to exceed that of the processor with the largest workload

Page 83: Aspects of Embedded System Design

83

Sept 2007, Kandemir

Potential energy savings

40

50

60

70

80

90

100

2 4 8 16 32

Number of Processors

No

rma

lize

d E

ne

rgy

3D DFE LU SPLAT MGRID WAVE5

40

50

60

70

80

90

100

2 4 8 16

Number of Voltage Levels

No

rma

lize

d E

ne

rgy

3D DFE LU SPLAT MGRID WAVE5

Large difference

between 4 and 8

voltage levels!

Better savings with

more PEs

(more load imbalance)!

Overview of compiler-directed

link allocation

Input

Code

BuildingConnectionInterference

Graph

DeterminingRoutes for

Connections

DeterminingContents of

Routing Tables

Output

Code

Goal: Determine a

route for each message

Page 84: Aspects of Embedded System Design

84

Example: X-Y routing

a e e

b

b

a

d

c

c

d

]],[[ bb]],[[ aa ]],[[ cc

]],[[ dd

]],[[ ee

22 links, 2 conflicts

Example: compiler-directed,

power-aware routing

]],[[ bb]],[[ aa ]],[[ cc

]],[[ dd

]],[[ ee

19 links, 0 conflicts

a e e

b

b

a

d

c

c

d Reused

Links

Page 85: Aspects of Embedded System Design

85

Example: power-aware routing

vs. X-Y routing

19 links, 0 conflicts

a e e

b

b

a

d

c

c

d

a e e

b

b

a

d

c

c

d

22 links, 2 conflicts

OS-based energy management

• OS has global view of the system

• Information about actual physical frame

allocation

• OS can determine points, during the execution of

an application, where banks would remain idle,

so they can be transitioned to low power modes

Page 86: Aspects of Embedded System Design

86

Scheduler-based approach

• Transitions the banks at context switch time

• We expect the same banks will be used in the

next quantum

• We need to keep track of the banks that are

used by the application per time quantum

• Bank Usage Table (BUT)

Bank usage table (BUT)

• One row per application/task

• An x means a bank was used in the previous

quantum

Process

Bank Number

B1 B2 B3 … Bn

P1 X X …

P2 X X … X

… … … … …

Pm X X

Page 87: Aspects of Embedded System Design

87

Integrated approach

Hardware based (reactive) + OS based (proactive)

Access Access

Hardware Approach

OS Approach

Integrated Approach

Additional energy savings

Process 1 Process 2 Process 1

Time

Potential research topics

• Interfacing hardware based, compiler based,

and OS based power saving strategies

• Power optimizations for multicore DSPs

• Compiling for power in the context of multicores

– Instead of maximizing performance, explore

power-performance tradeoffs

• Thermal aware computation

– Application mapping, scheduling

– Sensor placement

Page 88: Aspects of Embedded System Design

88

Embedded OS and

Reliability

Mahmut Taylan KandemirPennsylvania State University

University Park, PA 16802, [email protected]

Core5

NIC

R

Core6

NIC

R

Core7

NIC

R

Core9

NIC

R

Core10

NIC

R

Core11

NIC

R

Core13

NIC

R

Core14

NIC

R

Core15

NIC

R

Core16

NIC

R

Core12

NIC

R

Core8

NIC

R

Core4

NIC

R

Core3

NIC

R

Core2

NIC

R

Core1

NIC

R

Resiliency/reliability issues in

multicores

• Run away leakage on idle cores

• Thermal emergencies

• Transient errors

• Wearouts

Page 89: Aspects of Embedded System Design

89

Reliability, power, performance

CC

CC

CC

CC

CC

CC

CC

CC

How to allocate cores and

map threads to handle run-

time availability changes?

HighAvailability

Program Execution

16 PEs16 threads

?

2 cores go downLowerAvailability

Number of Threads

Nu

mb

er o

f C

ore

s

1614118

8

9

11

14

16

(16,14)

Best EDP Choices for FFT

(16,16) Two coresgo down

Scenario 1

(16,9)

20% reduction

Scenario 2

(11,11)

52% reduction

How to automatically

decide the ideal

configuration?

# threads # cores

Scenario 356% reduction (14,14)

Page 90: Aspects of Embedded System Design

90

FFT

• FFT uses a 3D FFT

and then the inverse

3D FFT

• Computations inside

each iteration are

similar

CALL SETUP

CALL FFT(1)

DO ITER=1, NITER

CALL EVOLVE

CALL FFT(-1)

CALL CHECKSUM

END DO

Helper thread based adaptation

• Helper thread‟s recipe

– Collect performance/energy statistics as the

execution progresses

– Calculate EDP values

– Use curve fitting to determine the best

configuration to minimize EDP

Page 91: Aspects of Embedded System Design

91

Adapting the number of cores

• Number of available cores drops from 16 to 14

14

13

12

11

10

9

8

7

Nu

mb

er o

f C

ore

s

Execution Progress

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 16-6

-4

-2

0

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

2 4 6 8 10 12 14 160

2

4

6

8

10

12

Number of Cores

ED

P

183Number of Threads

Nu

mb

er o

f C

ore

s

16142 8

8

2

14

16

Adapting both threads and cores

510

15 510

150

5

10

15

20

25

Number of ThreadsNumber of Cores

ED

P (

Js)

actual EDP values

shifted fitting results

Page 92: Aspects of Embedded System Design

92

Number of Threads

Nu

mb

er o

f C

ore

s

1611108

8

9

11

13

16

(16,10)

Adapting to multiple changes

(16,16)

(10,13)

(11,11)

(10,10)

(11,9)

(8,8)

(8,14)

13

(13,13)

30% reduction

in EDP

# threads # cores

Availability ChangeAction Taken

OSPartitioner

RuntimeModule

CMPHardware

Application 1

Application 2

Application n

performancecounter values

corerequests/releases

new core partitions and rethreading

executionstepsnumber of

availablecores

OS-guided core partitioning

Page 93: Aspects of Embedded System Design

93

Core partitioning example

0

4

8

12

16

1 5 9 13 17 21 25 29 33 37 41

Execution Progress

Nu

mb

er

of

Allo

ca

ted

Co

res

LU MG

EDPG:LU 19.1% and MG 10.1%

i.e.,W-EDGP 15%

Results with two application

workloads

-5%

0%

5%

10%

15%

20%

25%

FC FL

FB

FT

MC

ML

MB

MT

CB

CT

LB

LT

BT

FM CL

a-m

ean

h-m

ean

g-m

ean

W-E

DP

G

Page 94: Aspects of Embedded System Design

94

Results with three application

workloads

-5%

0%

5%

10%

15%

20%

25%

30%

FM

B

FM

T

FC

B

FC

T

FL

B

FL

T

FB

T

MC

B

MC

T

MLB

MLT

MB

T

CLB

CLT

CB

T

LB

T

FM

L

MC

L

FC

L

FM

C

a-m

ean

h-m

ean

g-m

ean

W-E

DP

G

Multicore architecture with

variations

C0 C1 C2 C3

C4 C5 C6 C7

C8 C9 C10 C11

C12 C13 C14 C15

• From Bin 4 to Bin 1– Clock frequency

degrades by 5%, 10% and 15%

• From Bin 1 to Bin 4– Subthreadhold

leakage power (IleakVdd) increases by 20%, 40% and 60%

[Humenay, Tarjan, Skadron; DATE’07]

Bin 4

Bin 3

Bin 2

Bin 1

leakier

slow

er

Page 95: Aspects of Embedded System Design

95

Different mappings for a single-

threaded application

0.8

0.9

1

1.1

1.2

BT

CG E

P FT IS LU

LU-H

PMG S

PUA

bzip

gcc

gobm

k

h264

ref

hmmer

mcf

perlb

ench

sjen

g

libqu

antum

omne

tpp

xalanc

bmk

No

rma

lize

d E

DP

Bin 1 Bin 2 Bin 3 Bin 4

• Results normalized to Bin 1 (the slowest, but least leaky Bin)

Which bin to run in is application dependent

Different mappings for a multi-

threaded application (4 threads)

0.9

1

1.1

1.2

1.3

BT

CG E

P FT IS LU

LU-H

PMG S

PUA

ammp

applu

art

apsi

equa

ke

fma3

d

gafort

galgel

mgr

id

swim

Norm

alized

ED

P

Bin 1 Bin 2 Bin 3 Bin 4

• One thread per core and all threads of an application run in the same Bin

For most applications, Bin 1 (the slowest, least leaky) gives the best EDP

Page 96: Aspects of Embedded System Design

96

Allowing bin frequencies to

change• Allow Bins to run at different frequencies

(i.e., downgrade a Bin from a higher frequency to a lower frequency)

C0 C1 C2 C3

C4 C5 C6 C7

C8 C9 C10 C11

C12 C13 C14 C15

192

C0 C1 C2 C3

C4 C5 C6 C7

C8 C9 C10 C11

C12 C13 C14 C15

downgrade

Bin 3

f1

f2

f3

f4

f1

f2

f2

f4

Mapping at runtime

• Non-preemptive– Only use idle cores

– Alternative schemes• MOST: 2 cores at f2• FAST: 1 core at f4• SLOW: 1 core at f1

• Preemptive– Interrupt running

applications and optimize globally

193

C0

Busy

C1

Busy

C2

Busy

C3

C4

Busy

C5

Busy

C6 C7

C8

Busy

C9

Busy

C10

Busy

C11

Busy

C12

Busy

C13

Busy

C14

Busy

C15

f4

f2

f2

f1

Page 97: Aspects of Embedded System Design

97

Compiler directed network-on-chip

reliability enhancement

• Idea: Improve on-chip communication reliability by duplicating messages traveling over the network

• Performance Constraint: A duplicate message should use a different set of links as much as possible

• Power Concern: Reuse communication links across the different phases of the program to maximize link shutdown opportunities

Automatic code replication for

reliability• Not all processors are

used to execute a loop

• Exploit idle processors– Switch off to save power

– Execute replicated computation to increase reliability

A loop nest

P1 Pm Pm+1 Pm+r Pm+r+1 Pn

I1 Im

A loop nest

P1 Pm Pm+1 Pm+r Pm+r+1 Pn

I1 Im I1’ Ir’

Pi Pm+i

Ii Ii’

Checksum

=?

Page 98: Aspects of Embedded System Design

98

Energy-delay-fallibility product

• Power, performance, and reliability tradeoffs

• Reliability: Percentage of replicated iterations

• Fallibility: Inverse of Reliability

• EDF = Energy*Time*Fallibility

– Measures the tradeoffs between power, performance, and

reliability

Energy

efficiency

Performance Reliability

Low-power mode

Loop replication

Energy-delay-fallibility product

0

0.2

0.4

0.6

0.8

1

1.2

20% 30% 40% 50% 60% 70% 80% 90% 100%

No

rmali

zed

ED

F

3step-log adi efluxfull-search n-real-updates tsf

Amount of Duplication

Page 99: Aspects of Embedded System Design

99

Memory Conscious Loop

Duplication• Memory are doubled in

full array duplication

• Utilize inactive (dead)

array elements to store

duplicates

Data

Primary Array

ArrayDuplicate

PrimaryLoop

LoopDuplicate

Primary Output

OutputDuplicate

Compare

a

b

c

Memory

Time

write

read

active

inactive

t1 t2 t3 t4 t5 t6 t7 t8

Memory conscious loop

duplication

Time

))((0,

JXkk

F

))((0,

IXkk

F

J

J

write

read

active

inactive

I

Memory

kP

kV

kL

maxlkd

,

))((in is

))(( of duplicate The

1000

max

,

,

0,

,

,,1

klkk

lkk

kkk

Tlkk

lklk

PIX

IX

LFP

dL

dd

max

maxkMl

F

F

int A(N);

for i=0,N-2

A(i+1)=A(i)+a;

int A(N+2);

for i=0,N-2 {

A(i+1)=A(i)+a;

A(i+3)=A(i+2)+a;

if A(i+1)!=A(i+3)

error();

}

int A(N),A’(N);

for i=0,N-2 {

A(i+1)=A(i)+a;

A’(i+1)=A’(i)+a;

if A(i+1)!=A’(i+1)

error();

}

Original program Full duplication Memory-conscious duplication

Page 100: Aspects of Embedded System Design

100

0%10%20%30%40%50%60%70%80%90%

171.

swim

172.

mgrid

177.

mes

a

179.

art

183.

equak

e

188.

amm

p atr

bssen

cr

img-s

eg-6

usonic

wood04

in-place global

Memory conscious loop

duplicationN

orm

aliz

ed In

crea

se in

Mem

ory

Sp

ace

Checksum reuse

A B C+ =

CS(A) CS(A) CS(C)

CS(A)+CS(B)Compare

OriginalLoop

OriginalLoop

ChecksumGeneration

ChecksumCalculation

ChecksumComparison

for i=1,1000A[i] = 2*B[i];

CS_B = 0;for i=1,1000CS_B += B[i];

CS_A = 2*CS_B;

for i=1,1000A[i] = 2*B[i];

checksum = 0;for i=1,1000

checksum += A[i];if (checksum ≠CS_A)

error;

The overhead brought by checksum generation could be removed by checksum reuse

Page 101: Aspects of Embedded System Design

101

Loop

Nest 1

Region

Original

Transformed

Loop

Nest 2

Loop

Nest 3

Checksum

Intra-procedural checksum reuse

procedure ProcA

real P(100,100)

call ProcC(P);

procedure ProcC(J)

input J(100,100)

{J}

?

procedure ProcB

real Q(100,100)

call ProcC(Q);

Inter-procedural checksum reuse

Three Options:•Do nothing•Choose one region shape•Procedure cloning

Runtime integrity checking for

inter-object connections

C1

C2

C2

C3C3

C3

C4

C5

C5C3 C5

C1 C2 C2 C5[] C2

C6

C6

Each C1 object points to at least two C2 object

All C3 objects are connected together

Each C4 is pointed by at least three C5 objects

Each C1 object points to a C2 object that also points back to this C1 object

Each C2 object is pointed by at least one C5 array object or two C6 object

Page 102: Aspects of Embedded System Design

102

Grammar Explanation

For each object of type C, the rule body B must be satisfied.

Each rule body consists of the disjunction of subrules.

All objects of the checking class are weakly connected.

There exist at least N objects of type C that have relation R

with the checking object.

Points-to relation.

Pointed-from relation.

Bidirectional-points-to relation.

Instance class.

Reference array class.

Primary array class.

N represents positive integer number.

BCL ::BorSSB |::

CNR

S

*|

::

|

|

::R

[]|

[]|

::

primary

C

ClassC

PosIntN ::

Runtime integrity checking for

inter-object connections

C1

C2

C2

C3C3

C3

C4

C5

C5C3 C5

C1 C2 C2 C5[] C2

C6

C6

2*21 CC 3C 5*34 CC

6*11 CC6*2[]5*12 CorCC

Page 103: Aspects of Embedded System Design

103

App Number of Errors Injected Number of Errors Caught

Total Disappeared Wrong

Object

Total Disappeared Wrong

Object

JLex 65 61 (94%) 4 (6%) 35 (58%) 31 (51%) 4 (100%)

compress 733 703 (96%) 30 (4%) 395 (54%) 375 (53%) 20 (67%)

jess 336 325 (97%) 11 (3%) 172 (51%) 164 (50%) 8 (73%)

db 101 96 (95%) 5 (5%) 56 (55%) 52 (54%) 4 (80%)

raytrace 410 388 (95%) 22 (5%) 219 (53%) 201 (52%) 18 (82%)

The original edge before error occurs

The edge affected by the error

Disappeared edge Wrong object

Potential research topics

• Quantifying vulnerability of embedded

applications

• Compiler support for reliability

• Application/domain specific resiliency maesures

• Reliability-power-performance tradeoffs

• Reactive versus proactive strategies