Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions api/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,19 @@ func (d *driverImpl) doOneFeedInTask(task *feedInTask) bool {
panic("CGRA cannot handle the data rate")
}

core.Trace("DataFlow",
"Behavior", "FeedIn",
slog.Float64("Time", float64(d.Engine.CurrentTime()*1e9)),
"Data", task.data[dataIndex],
"Color", task.color,
"From", port.Name(),
"To", task.remotePorts[i],
)
timeValue := float64(d.Engine.CurrentTime() * 1e9)
if core.TraceEnabled() {
core.Trace("DataFlow",
"Behavior", "FeedIn",
slog.Float64("Time", timeValue),
"Data", task.data[dataIndex],
"Color", task.color,
"From", port.Name(),
"To", task.remotePorts[i],
)
} else {
core.ObserveDataFlow("FeedIn", timeValue, port.Name(), string(task.remotePorts[i]), "", "")
}
task.portRounds[i]++
madeProgress = true
}
Expand Down Expand Up @@ -202,15 +207,20 @@ func (d *driverImpl) doOneCollectTask(task *collectTask) bool {
}
task.data[dataIndex] = msg.Data.First()

core.Trace("DataFlow",
"Behavior", "Collect",
slog.Float64("Time", float64(d.Engine.CurrentTime()*1e9)),
"Data", msg.Data.First(),
"Pred", msg.Data.Pred,
"Color", task.color,
"From", task.ports[i].Name(),
"To", "None",
)
timeValue := float64(d.Engine.CurrentTime() * 1e9)
if core.TraceEnabled() {
core.Trace("DataFlow",
"Behavior", "Collect",
slog.Float64("Time", timeValue),
"Data", msg.Data.First(),
"Pred", msg.Data.Pred,
"Color", task.color,
"From", task.ports[i].Name(),
"To", "None",
)
} else {
core.ObserveDataFlow("Collect", timeValue, task.ports[i].Name(), "None", "", "")
}

task.portRounds[i]++
madeProgress = true
Expand Down
14 changes: 11 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ type DeviceBuilder struct {
freq sim.Freq
monitor *monitoring.Monitor
//portFactory portFactory
width, height int
memoryMode string // simple or shared or local
memoryShare map[[2]int]int //map[[x, y]]GroupID
width, height int
memoryMode string // simple or shared or local
memoryShare map[[2]int]int //map[[x, y]]GroupID
executionPolicy string
}

// type portFactory interface {
Expand Down Expand Up @@ -74,6 +75,12 @@ func (d DeviceBuilder) WithMemoryShare(share map[[2]int]int) DeviceBuilder {
return d
}

// WithExecutionPolicy sets core execution policy.
func (d DeviceBuilder) WithExecutionPolicy(policy string) DeviceBuilder {
d.executionPolicy = policy
return d
}
Comment on lines +78 to +82
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithExecutionPolicy accepts any string and stores it without validation/normalization. Combined with core-side silent fallback on unknown policies, this can make misconfigurations hard to detect. Consider validating/normalizing here (or changing the API to a typed enum/consts) so invalid values are rejected early and behavior matches runtimecfg.Resolve validation.

Copilot uses AI. Check for mistakes.

// Build creates a CGRA device.
func (d DeviceBuilder) Build(name string) cgra.Device {
dev := &device{
Expand Down Expand Up @@ -188,6 +195,7 @@ func (d DeviceBuilder) createTiles(
WithExitAddr(&exit).
WithRetValAddr(&retVal).
WithExitReqAddr(&exitReqTimestamp).
WithExecutionPolicy(d.executionPolicy).
Build(coreName)

if d.monitor != nil {
Expand Down
21 changes: 15 additions & 6 deletions core/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

// Builder can create new cores.
type Builder struct {
engine sim.Engine
freq sim.Freq
exitAddr *bool
retValAddr *uint32
exitReqAddr *float64
engine sim.Engine
freq sim.Freq
exitAddr *bool
retValAddr *uint32
exitReqAddr *float64
executionPolicy string
}

// WithEngine sets the engine.
Expand Down Expand Up @@ -43,6 +44,12 @@ func (b Builder) WithExitReqAddr(exitReqAddr *float64) Builder {
return b
}

// WithExecutionPolicy sets the execution policy for issue-time gating.
func (b Builder) WithExecutionPolicy(policy string) Builder {
b.executionPolicy = policy
return b
}

// Build creates a core.
//
//nolint:funlen
Expand All @@ -51,7 +58,8 @@ func (b Builder) Build(name string) *Core {

c.TickingComponent = sim.NewTickingComponent(name, b.engine, b.freq, c)
c.emu = instEmulator{
CareFlags: true,
CareFlags: true,
ExecutionPolicy: normalizeExecutionPolicyString(b.executionPolicy),
}
c.state = coreState{
exit: b.exitAddr,
Expand Down Expand Up @@ -80,6 +88,7 @@ func (b Builder) Build(name string) *Core {
IsToWriteMemory: false,
States: make(map[string]interface{}),
Mode: SyncOp,
CurrentCycle: 0,
CurrReservationState: ReservationState{
ReservationMap: make(map[int]bool),
OpToExec: 0,
Expand Down
159 changes: 99 additions & 60 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ func (c *Core) WriteMemory(x int, y int, data uint32, baseAddr uint32) {
if x == int(c.state.TileX) && y == int(c.state.TileY) {
c.state.Memory[baseAddr] = data
//fmt.Printf("Core [%d][%d] write memory[%d] = %d\n", c.state.TileX, c.state.TileY, baseAddr, c.state.Memory[baseAddr])
Trace("Memory",
"Behavior", "WriteMemory",
"Time", float64(c.Engine.CurrentTime()*1e9),
"Data", data,
"X", x,
"Y", y,
"Addr", baseAddr,
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("Memory",
"Behavior", "WriteMemory",
"Time", timeValue,
"Data", data,
"X", x,
"Y", y,
"Addr", baseAddr,
)
} else {
ObserveMemory("WriteMemory", timeValue, x, y, "", "")
}
} else {
panic(fmt.Sprintf("Invalid Tile: Expect (%d, %d),but get (%d, %d)", c.state.TileX, c.state.TileY, x, y))
}
Expand All @@ -85,6 +90,7 @@ func (c *Core) MapProgram(program interface{}, x int, y int) {
panic("MapProgram expects core.Program type")
}
c.state.PCInBlock = -1
c.state.CurrentCycle = 0
c.state.TileX = uint32(x)
c.state.TileY = uint32(y)
}
Expand All @@ -96,13 +102,15 @@ func (c *Core) Tick() (madeProgress bool) {
// madeProgress = c.emu.runRoutingRules(&c.state) || madeProgress
madeProgress = c.runProgram() || madeProgress
madeProgress = c.doSend() || madeProgress
c.state.CurrentCycle++
return madeProgress
}

func makeBytesFromUint32(data uint32) []byte {
return []byte{byte(data >> 24), byte(data >> 16), byte(data >> 8), byte(data)}
}

//nolint:gocyclo
func (c *Core) doSend() bool {
madeProgress := false
for i := 0; i < 8; i++ { // only 8 directions
Expand All @@ -127,15 +135,20 @@ func (c *Core) doSend() bool {
continue
}

Trace("DataFlow",
"Behavior", "Send",
slog.Float64("Time", float64(c.Engine.CurrentTime()*1e9)),
"Data", msg.Data.First(),
"Pred", c.state.SendBufHead[color][i].Pred,
"Color", color,
"Src", msg.Src,
"Dst", msg.Dst,
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("DataFlow",
"Behavior", "Send",
slog.Float64("Time", timeValue),
"Data", msg.Data.First(),
"Pred", c.state.SendBufHead[color][i].Pred,
"Color", color,
"Src", msg.Src,
"Dst", msg.Dst,
)
} else {
ObserveDataFlow("Send", timeValue, "", "", string(msg.Src), string(msg.Dst))
}
c.state.SendBufHeadBusy[color][i] = false
}
}
Expand All @@ -156,15 +169,20 @@ func (c *Core) doSend() bool {
return madeProgress
}

Trace("Memory",
"Behavior", "Send",
slog.Float64("Time", float64(c.Engine.CurrentTime()*1e9)),
"Data", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].First(),
"Pred", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
"Src", msg.Src,
"Dst", msg.Dst,
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("Memory",
"Behavior", "Send",
slog.Float64("Time", timeValue),
"Data", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].First(),
"Pred", c.state.SendBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
"Src", msg.Src,
"Dst", msg.Dst,
)
} else {
ObserveMemory("Send", timeValue, int(c.state.TileX), int(c.state.TileY), string(msg.Src), string(msg.Dst))
}
c.state.SendBufHeadBusy[c.emu.getColorIndex("R")][cgra.Router] = false
} else {
msg := mem.ReadReqBuilder{}.
Expand All @@ -179,14 +197,19 @@ func (c *Core) doSend() bool {
return madeProgress
}

Trace("Memory",
"Behavior", "Send",
slog.Float64("Time", float64(c.Engine.CurrentTime()*1e9)),
"Data", c.state.AddrBuf,
"Color", "R",
"Src", msg.Src,
"Dst", msg.Dst,
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("Memory",
"Behavior", "Send",
slog.Float64("Time", timeValue),
"Data", c.state.AddrBuf,
"Color", "R",
"Src", msg.Src,
"Dst", msg.Dst,
)
} else {
ObserveMemory("Send", timeValue, int(c.state.TileX), int(c.state.TileY), string(msg.Src), string(msg.Dst))
}
c.state.SendBufHeadBusy[c.emu.getColorIndex("R")][cgra.Router] = false
}
}
Expand All @@ -198,6 +221,7 @@ func convert4BytesToUint32(data []byte) uint32 {
return uint32(data[0])<<24 | uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])
}

//nolint:gocyclo
func (c *Core) doRecv() bool {
madeProgress := false
for i := 0; i < 8; i++ { //direction
Expand Down Expand Up @@ -226,15 +250,20 @@ func (c *Core) doRecv() bool {
c.state.RecvBufHeadReady[color][i] = true
c.state.RecvBufHead[color][i] = msg.Data

Trace("DataFlow",
"Behavior", "Recv",
"Time", float64(c.Engine.CurrentTime()*1e9),
"Data", msg.Data.First(),
"Pred", c.state.RecvBufHead[color][i].Pred,
"Src", msg.Src,
"Dst", msg.Dst,
"Color", color,
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("DataFlow",
"Behavior", "Recv",
"Time", timeValue,
"Data", msg.Data.First(),
"Pred", c.state.RecvBufHead[color][i].Pred,
"Src", msg.Src,
"Dst", msg.Dst,
"Color", color,
)
} else {
ObserveDataFlow("Recv", timeValue, "", "", string(msg.Src), string(msg.Dst))
}

c.ports[cgra.Side(i)].local.RetrieveIncoming()
madeProgress = true
Expand All @@ -254,30 +283,40 @@ func (c *Core) doRecv() bool {
c.state.RecvBufHeadReady[c.emu.getColorIndex("R")][cgra.Router] = true
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = cgra.NewScalar(convert4BytesToUint32(msg.Data))

Trace("Memory",
"Behavior", "Recv",
"Time", float64(c.Engine.CurrentTime()*1e9),
"Data", msg.Data,
"Src", msg.Src,
"Dst", msg.Dst,
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("Memory",
"Behavior", "Recv",
"Time", timeValue,
"Data", msg.Data,
"Src", msg.Src,
"Dst", msg.Dst,
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
)
} else {
ObserveMemory("Recv", timeValue, int(c.state.TileX), int(c.state.TileY), string(msg.Src), string(msg.Dst))
}

c.ports[cgra.Router].local.RetrieveIncoming()
madeProgress = true
} else if msg, ok := item.(*mem.WriteDoneRsp); ok {
c.state.RecvBufHeadReady[c.emu.getColorIndex("R")][cgra.Router] = true
c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router] = cgra.NewScalar(0)

Trace("Memory",
"Behavior", "Recv",
"Time", float64(c.Engine.CurrentTime()*1e9),
"Src", msg.Src,
"Dst", msg.Dst,
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
)
timeValue := float64(c.Engine.CurrentTime() * 1e9)
if TraceEnabled() {
Trace("Memory",
"Behavior", "Recv",
"Time", timeValue,
"Src", msg.Src,
"Dst", msg.Dst,
"Pred", c.state.RecvBufHead[c.emu.getColorIndex("R")][cgra.Router].Pred,
"Color", "R",
)
} else {
ObserveMemory("Recv", timeValue, int(c.state.TileX), int(c.state.TileY), string(msg.Src), string(msg.Dst))
}

c.ports[cgra.Router].local.RetrieveIncoming()
madeProgress = true
Expand Down
Loading
Loading