Skip to content

Commit 25f6434

Browse files
committed
New data type for cgra
1 parent 772e44b commit 25f6434

13 files changed

Lines changed: 526 additions & 148 deletions

File tree

api/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (d *driverImpl) doOneFeedInTask(task *feedInTask) bool {
131131
msg := cgra.MoveMsgBuilder{}.
132132
WithSrc(port.AsRemote()).
133133
WithDst(task.remotePorts[i]).
134-
WithData(task.data[task.round*task.stride+i]).
134+
WithData(cgra.NewScalar(task.data[task.round*task.stride+i])).
135135
WithColor(task.color).
136136
WithSendTime(d.Engine.CurrentTime()). // Set the current engine time here
137137
Build()
@@ -179,13 +179,14 @@ func (d *driverImpl) doOneCollectTask(task *collectTask) bool {
179179

180180
for i, port := range task.ports {
181181
msg := port.RetrieveIncoming().(*cgra.MoveMsg)
182-
task.data[task.round*task.stride+i] = msg.Data
182+
task.data[task.round*task.stride+i] = msg.Data.First()
183183
// in red
184184

185185
core.Trace("DataFlow",
186186
"Behavior", "Collect",
187187
slog.Float64("Time", float64(d.Engine.CurrentTime()*1e9)),
188188
"Data", task.data[task.round*task.stride+i],
189+
"Pred", msg.Data.Pred,
189190
"Color", task.color,
190191
"From", task.ports[i].Name(),
191192
"To", "None",

cgra/data.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cgra
2+
3+
type Data struct {
4+
Data []uint32
5+
Pred bool
6+
}
7+
8+
// NewScalar creates a Data that wraps a single uint32 value with Pred=true by default.
9+
func NewScalar(v uint32) Data {
10+
return Data{Data: []uint32{v}, Pred: true}
11+
}
12+
13+
// NewScalar creates a Data that wraps a single uint32 value with Pred=true by default.
14+
func NewScalarWithPred(v uint32, pred bool) Data {
15+
return Data{Data: []uint32{v}, Pred: pred}
16+
}
17+
18+
// First returns the first lane value. If empty, returns 0.
19+
func (d Data) First() uint32 {
20+
if len(d.Data) == 0 {
21+
return 0
22+
}
23+
return d.Data[0]
24+
}
25+
26+
// WithPred returns a copy with the given predicate flag.
27+
func (d Data) WithPred(pred bool) Data {
28+
d.Pred = pred
29+
return d
30+
}
31+
32+
// FromSlice constructs a Data from a slice and optional predicate.
33+
func FromSlice(vals []uint32, pred bool) Data {
34+
return Data{Data: vals, Pred: pred}
35+
}

cgra/msg.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package cgra
22

3-
import "github.com/sarchlab/akita/v4/sim"
3+
import (
4+
"github.com/sarchlab/akita/v4/sim"
5+
)
46

57
// MoveMsg moves data from one tile to another in a CGRA.
68
type MoveMsg struct {
79
sim.MsgMeta
810

9-
Data uint32
11+
Data Data
1012
Color int
1113
//create a new branch predicate data
1214
//Predicate int
@@ -29,7 +31,7 @@ func (m *MoveMsg) Clone() sim.Msg {
2931
type MoveMsgBuilder struct {
3032
src, dst sim.RemotePort
3133
sendTime sim.VTimeInSec
32-
data uint32
34+
data Data
3335
color int
3436
// predicate value
3537
//predicate int
@@ -54,7 +56,7 @@ func (m MoveMsgBuilder) WithSendTime(sendTime sim.VTimeInSec) MoveMsgBuilder {
5456
}
5557

5658
// WithData sets the data of the msg.
57-
func (m MoveMsgBuilder) WithData(data uint32) MoveMsgBuilder {
59+
func (m MoveMsgBuilder) WithData(data Data) MoveMsgBuilder {
5860
m.data = data
5961
return m
6062
}

core/builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func (b Builder) Build(name string) *Core {
4545
"NorthWest": true,
4646
"Router": true,
4747
},
48-
Registers: make([]uint32, 64),
48+
Registers: make([]cgra.Data, 64),
4949
Memory: make([]uint32, 1024),
50-
RecvBufHead: make([][]uint32, 4),
50+
RecvBufHead: make([][]cgra.Data, 4),
5151
RecvBufHeadReady: make([][]bool, 4),
52-
SendBufHead: make([][]uint32, 4),
52+
SendBufHead: make([][]cgra.Data, 4),
5353
SendBufHeadBusy: make([][]bool, 4),
5454
AddrBuf: 0,
5555
IsToWriteMemory: false,
@@ -63,9 +63,9 @@ func (b Builder) Build(name string) *Core {
6363
}
6464

6565
for i := 0; i < 4; i++ {
66-
c.state.RecvBufHead[i] = make([]uint32, 12)
66+
c.state.RecvBufHead[i] = make([]cgra.Data, 12)
6767
c.state.RecvBufHeadReady[i] = make([]bool, 12)
68-
c.state.SendBufHead[i] = make([]uint32, 12)
68+
c.state.SendBufHead[i] = make([]cgra.Data, 12)
6969
c.state.SendBufHeadBusy[i] = make([]bool, 12)
7070
}
7171

core/core.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func (c *Core) doSend() bool {
114114
Trace("DataFlow",
115115
"Behavior", "Send",
116116
slog.Float64("Time", float64(c.Engine.CurrentTime()*1e9)),
117-
"Data", msg.Data,
117+
"Data", msg.Data.First(),
118+
"Pred", c.state.SendBufHead[color][i].Pred,
118119
"Color", color,
119120
"Src", msg.Src,
120121
"Dst", msg.Dst,
@@ -130,7 +131,7 @@ func (c *Core) doSend() bool {
130131
if c.state.IsToWriteMemory {
131132
msg := mem.WriteReqBuilder{}.
132133
WithAddress(uint64(c.state.AddrBuf)).
133-
WithData(makeBytesFromUint32(c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router])).
134+
WithData(makeBytesFromUint32(c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].First())).
134135
WithSrc(c.ports[cgra.Side(cgra.Router)].local.AsRemote()).
135136
WithDst(c.ports[cgra.Side(cgra.Router)].remote).
136137
Build()
@@ -143,7 +144,8 @@ func (c *Core) doSend() bool {
143144
Trace("Memory",
144145
"Behavior", "Send",
145146
slog.Float64("Time", float64(c.Engine.CurrentTime()*1e9)),
146-
"Data", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router],
147+
"Data", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].First(),
148+
"Pred", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
147149
"Color", "R",
148150
"Src", msg.Src,
149151
"Dst", msg.Dst,
@@ -212,7 +214,8 @@ func (c *Core) doRecv() bool {
212214
Trace("DataFlow",
213215
"Behavior", "Recv",
214216
"Time", float64(c.Engine.CurrentTime()*1e9),
215-
"Data", msg.Data,
217+
"Data", msg.Data.First(),
218+
"Pred", c.state.RecvBufHead[color][i].Pred,
216219
"Src", msg.Src,
217220
"Dst", msg.Dst,
218221
"Color", color,
@@ -234,28 +237,30 @@ func (c *Core) doRecv() bool {
234237
// if msg is DataReadyRsp, then the data is ready
235238
if msg, ok := item.(*mem.DataReadyRsp); ok {
236239
c.state.RecvBufHeadReady[c.emu.getColorIndex("R")][cgra.Router] = true
237-
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = convert4BytesToUint32(msg.Data)
240+
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = cgra.NewScalar(convert4BytesToUint32(msg.Data))
238241

239242
Trace("Memory",
240243
"Behavior", "Recv",
241244
"Time", float64(c.Engine.CurrentTime()*1e9),
242245
"Data", msg.Data,
243246
"Src", msg.Src,
244247
"Dst", msg.Dst,
248+
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
245249
"Color", "R",
246250
)
247251

248252
c.ports[cgra.Side(cgra.Router)].local.RetrieveIncoming()
249253
madeProgress = true
250254
} else if msg, ok := item.(*mem.WriteDoneRsp); ok {
251255
c.state.RecvBufHeadReady[c.emu.getColorIndex("R")][cgra.Router] = true
252-
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = 0
256+
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = cgra.NewScalar(0)
253257

254258
Trace("Memory",
255259
"Behavior", "Recv",
256260
"Time", float64(c.Engine.CurrentTime()*1e9),
257261
"Src", msg.Src,
258262
"Dst", msg.Dst,
263+
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
259264
"Color", "R",
260265
)
261266

core/data.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package core
2+
3+
type Data struct {
4+
Data []uint32
5+
Pred bool
6+
}
7+
8+
// NewScalar creates a Data that wraps a single uint32 value with Pred=true by default.
9+
func NewScalar(v uint32) Data {
10+
return Data{Data: []uint32{v}, Pred: true}
11+
}
12+
13+
// NewScalar creates a Data that wraps a single uint32 value with Pred=true by default.
14+
func NewScalarWithPred(v uint32, pred bool) Data {
15+
return Data{Data: []uint32{v}, Pred: pred}
16+
}
17+
18+
// First returns the first lane value. If empty, returns 0.
19+
func (d Data) First() uint32 {
20+
if len(d.Data) == 0 {
21+
return 0
22+
}
23+
return d.Data[0]
24+
}
25+
26+
// WithPred returns a copy with the given predicate flag.
27+
func (d Data) WithPred(pred bool) Data {
28+
d.Pred = pred
29+
return d
30+
}
31+
32+
// FromSlice constructs a Data from a slice and optional predicate.
33+
func FromSlice(vals []uint32, pred bool) Data {
34+
return Data{Data: vals, Pred: pred}
35+
}

0 commit comments

Comments
 (0)