chisel @ cs250 ready/valid lecture 11bcs250/fa13/lectures/lec11b.pdf · chisel @ cs250 –...

23
Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013

Upload: others

Post on 22-Oct-2019

34 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Chisel @ CS250 – Ready/Valid Lecture 11b

Jonathan Bachrach

EECS UC Berkeley

October 3, 2013

Page 2: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

From Last Time 1

Page 3: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Ready / Valid 2

ConsumerProducerBool

Bool

T

ready

valid

bits

Bool

Bool

T

ready

valid

bits

Decoupled(T) Decoupled(T).flip

Page 4: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Ready / Valid + Queue 3

QueueProducerBool

Bool

T

ready

valid

bits

Bool

Bool

T

ready

valid

bits

ConsumerBool

Bool

T

ready

valid

bits

Bool

Bool

T

ready

valid

bits

Page 5: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Ready / Valid Transfer 4

Clock

Valid

Ready

transfer

Page 6: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Two Ready / Valid Transfers 5

Clock

Valid

Ready

transfer transfer

Page 7: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

No Ready / Valid Transfer Both Low 6

Clock

Valid

Ready

Page 8: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

No Ready / Valid Transfer Valid Low 7

Clock

Valid

Ready

Page 9: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

No Ready / Valid Transfer Ready Low 8

Clock

Valid

Ready

Page 10: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

No Ready / Valid Transfer Out of Phase 9

Clock

Valid

Ready

Page 11: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

No Ready / Valid Combinational Loops 10

Bool

Bool

T

ready

valid

bits

Bool

Bool

T

ready

valid

bits

CombinationalLogic

CombinationalLogic

Producer Consumer

Page 12: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

How do We Avoid Combinational Loops 11

producer is valid regardless of whether consumer is readyconsumer is ready regardless of whether producer is valid

but how do you know when to move on?

Page 13: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

How to Update Valid from Ready 12

Bool

Bool

T

ready

valid

bits

Bool

Bool

T

ready

valid

bits

f

Producer Consumer

g f g

Page 14: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Simplest Ready / Valid Example 13

cmd.ready = cmd.x & !xcmd.readyxcmd.valid = cmd.valid & cmd.xxcmd.bits = cmd.bits

cmd

xcmd

xcmd =

Page 15: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Simple Ready / Valid Example 14

cmd.ready =(!cmd.x | xcmd.ready) &(!cmd.y | ycmd.ready)

xcmd.valid = cmd.valid & cmd.x &(!cmd.y | ycmd.ready)

ycmd.valid = cmd.valid & cmd.y &(!cmd.x | xcmd.ready)

xcmd.bits = ycmd.bits = cmd.bits

cmd

xcmd

ycmd

x ycmd =

Page 16: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Rewritten Simple Ready / Valid Example 15

x_blocked = cmd.x & !xcmd.readyy_blocked = cmd.y & !ycmd.readycmd.ready = !x_blocked & !y_blockedxcmd.valid = cmd.valid & cmd.x & !y_blockedycmd.valid = cmd.valid & cmd.y & !x_blockedxcmd.bits = ycmd.bits = cmd.bits

cmd

xcmd

ycmd

x ycmd =

Page 17: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Harder Ready / Valid Example 16

cmd.ready =(!cmd.x | xcmd.ready) &(!cmd.y | ycmd.ready) &(!cmd.op | (op.valid &

(!cmd.x | xop.ready) &(!cmd.y | yop.ready)))

xcmd.valid =cmd.valid & cmd.x &(!cmd.op | (op.valid & xop.ready)) &(!cmd.y | (ycmd.ready &

(!cmd.op | (op.valid & yop.ready))))ycmd.valid = ...

cmd op

ycmd

yop

xcmd xop

x y opcmd =

Page 18: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Even Harder Ready / Valid Example 17

cmd.ready =(!cmd.x | xcmd.ready) &(!cmd.y | ycmd.ready) &(!cmd.op1 | (op1.valid &

(!cmd.x | xop1.ready) &(!cmd.y | yop1.ready))) &

(!cmd.op2 | (op2.valid &(!cmd.x | xop2.ready) &(!cmd.y | yop2.ready)))

xcmd.valid =cmd.valid & cmd.x &(!cmd.op1 | (op1.valid & xop1.ready)) &(!cmd.op2 | (op2.valid & xop2.ready)) &(!cmd.y | (ycmd.ready &

(!cmd.op1 | (op1.valid & yop1.ready)) &(!cmd.op2 | (op2.valid & yop2.ready))))

ycmd.valid = ...

cmd op1

ycmd

yop1

xcmd xop1

op2

yop2

xop2

x y op1 op2cmd =

Page 19: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Transactional View 18

transaction() {

c = cmd.deq

if (c.x)

xcmd.enq(c)

if (c.y)

ycmd.enq(c)

if (c.op1) {

o1 = op1.deq

if (c.x)

xop1.enq(o1)

if (c.y)

yop1.enq(o1)

}

if (c.op2) {

o2 = op2.deq

if (c.x)

xop2.enq(o2)

if (c.y)

yop2.enq(o2)

}

}

cmd op1

ycmd

yop1

xcmd xop1

op2

yop2

xop2

x y op1 op2cmd =

Page 20: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Rules 19

no ready in terms of its ownvalidno valid in terms of its ownreadyready/valid must make surethat all data that shouldmove can move

cmd op1

ycmd

yop1

xcmd xop1

op2

yop2

xop2

x y op1 op2cmd =

Page 21: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Using Decoupled in Chisel ( Old ) 20

producer

val results =

Decoupled(UInt(width = 64))

val result =

Reg(UInt(width = 64))

results.valid := Bool(false)

results.bits := UInt(0)

...

when (isResult && results.ready) {

// enq

results.valid := Bool(true)

results.bits := result

}

consumer

val cmds =

Decoupled(UInt(width = 32)).flip

val cmd =

Reg(UInt(width = 32))

cmds.ready := Bool(false)

...

...

when (cmds.valid) {

// deq

cmds.ready := Bool(true)

cmd := result

}

IntuitiveIn general will create combinational loopIf though queue between producer and consumer ok

Page 22: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Using Decoupled in Chisel ( New ) 21

producer

val results =

Decoupled(UInt(width = 64))

val result =

Reg(UInt(width = 64))

results.valid := isResult

results.bits := result

isResult :=

Reg(results.ready) &

haveNewResult

consumer

val cmds =

Decoupled(UInt(width = 32)).flip

val cmd =

Reg(UInt(width = 32))

cmds.ready := amReady

cmd := result

amReady :=

Reg(cmds.valid) & isConsumedCmd

Ready and valid never function of each otherHard to designNever will create combinational loop

Page 23: Chisel @ CS250 Ready/Valid Lecture 11bcs250/fa13/lectures/lec11b.pdf · Chisel @ CS250 – Ready/Valid Lecture 11b Jonathan Bachrach EECS UC Berkeley October 3, 2013. From Last Time

Acknowledgements 22

“Ready / Valid” based on Chris Fletcher’s CS150 Writeup which isbased on Greg Gibeling’s WriteupChris Patten’s mother of all decoupled examples told to me byYunsup Lee