Skip to content

Commit 321765f

Browse files
committed
Add performance counter DPI module
1 parent 64ff8ee commit 321765f

5 files changed

Lines changed: 113 additions & 32 deletions

File tree

src/main/resources/csrc/Cyclotron.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,18 @@ void cyclotron_difftest_reg(
412412
);
413413
}
414414

415+
void profile_perf_counters_rs(
416+
uint64_t inst_retired,
417+
uint64_t cycle,
418+
uint8_t finished
419+
);
420+
421+
void profile_perf_counters(
422+
uint64_t inst_retired,
423+
uint64_t cycle,
424+
uint8_t finished
425+
) {
426+
profile_perf_counters_rs(inst_retired, cycle, finished);
427+
}
428+
415429
} // extern "C"

src/main/resources/vsrc/Profiler.v

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module ProfilerBlackBox #(
2+
parameter COUNTER_WIDTH = 64
3+
) (
4+
input clock,
5+
input reset,
6+
input logic finished,
7+
input logic [COUNTER_WIDTH-1:0] perf_backend_execute_instRetired,
8+
input logic [COUNTER_WIDTH-1:0] perf_backend_execute_cycle
9+
);
10+
11+
`include "Cyclotron.vh"
12+
13+
import "DPI-C" function void profile_perf_counters(
14+
input longint inst_retired,
15+
input longint cycle,
16+
input bit finished
17+
);
18+
19+
initial cyclotron_init_task();
20+
21+
always @(posedge clock) begin
22+
if (reset) begin
23+
end else begin
24+
profile_perf_counters(
25+
perf_backend_execute_instRetired,
26+
perf_backend_execute_cycle,
27+
finished
28+
);
29+
end
30+
end
31+
32+
endmodule

src/main/scala/radiance/muon/Execute.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Execute(implicit p: Parameters) extends CoreModule()(p) {
1717
val feCSR = Flipped(feCSRIO)
1818
val barrier = barrierIO
1919
val softReset = Input(Bool())
20-
val perf = Output(new ExecutePerfIO)
20+
val perf = new ExecutePerfIO
2121
})
2222

2323
val aluPipe = Module(new ALUPipe())
@@ -81,7 +81,7 @@ class Execute(implicit p: Parameters) extends CoreModule()(p) {
8181
}
8282

8383
class ExecutePerfIO(implicit p: Parameters) extends CoreBundle()(p) {
84-
val instRetired = UInt(Perf.counterWidth.W)
85-
val cycle = UInt(Perf.counterWidth.W)
84+
val instRetired = Output(UInt(Perf.counterWidth.W))
85+
val cycle = Output(UInt(Perf.counterWidth.W))
8686
// TODO: issue valid, execute fire
8787
}

src/main/scala/radiance/unittest/Muon.scala

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ class MuonCoreTop(implicit p: Parameters) extends LazyModule with HasCoreParamet
231231
core.io.coreId := 0.U
232232
core.io.clusterId := 0.U
233233

234+
// performance counters
235+
val cperf = Module(new Profiler)
236+
cperf.io.perf <> core.io.perf
237+
cperf.io.finished := core.io.finished
238+
234239
// RTL/model diff-test
235240
if (core.test) {
236241
val cdiff = Module(new CyclotronDiffTest(tick = true))
@@ -1092,40 +1097,70 @@ class CyclotronDiffTest(tick: Boolean = true)
10921097
boxtr.address := tr.address
10931098
boxtr.data := tr.data.asUInt
10941099
}
1095-
}
10961100

1097-
class CyclotronDiffTestBlackBox(tick: Boolean)(implicit val p: Parameters)
1098-
extends BlackBox(Map(
1099-
"ARCH_LEN" -> p(MuonKey).archLen,
1100-
"INST_BITS" -> p(MuonKey).instBits,
1101-
"NUM_WARPS" -> p(MuonKey).numWarps,
1102-
"NUM_LANES" -> p(MuonKey).numLanes,
1103-
"OP_BITS" -> Isa.opcodeBits,
1104-
"REG_BITS" -> Isa.regBits,
1105-
"IMM_BITS" -> 32,
1106-
"CSR_IMM_BITS" -> Isa.csrImmBits,
1107-
"PRED_BITS" -> Isa.predBits,
1108-
"SIM_TICK" -> (if (tick) 1 else 0),
1109-
)) with HasBlackBoxResource with HasCoreParameters {
1110-
val io = IO(new Bundle {
1111-
val clock = Input(Clock())
1112-
val reset = Input(Bool())
1101+
class CyclotronDiffTestBlackBox(tick: Boolean)(implicit val p: Parameters)
1102+
extends BlackBox(Map(
1103+
"ARCH_LEN" -> p(MuonKey).archLen,
1104+
"INST_BITS" -> p(MuonKey).instBits,
1105+
"NUM_WARPS" -> p(MuonKey).numWarps,
1106+
"NUM_LANES" -> p(MuonKey).numLanes,
1107+
"OP_BITS" -> Isa.opcodeBits,
1108+
"REG_BITS" -> Isa.regBits,
1109+
"IMM_BITS" -> 32,
1110+
"CSR_IMM_BITS" -> Isa.csrImmBits,
1111+
"PRED_BITS" -> Isa.predBits,
1112+
"SIM_TICK" -> (if (tick) 1 else 0),
1113+
)) with HasBlackBoxResource with HasCoreParameters {
1114+
val io = IO(new Bundle {
1115+
val clock = Input(Clock())
1116+
val reset = Input(Bool())
11131117

1114-
val trace = Input(new Bundle {
1115-
val valid = Bool()
1116-
val pc = pcT
1117-
val warpId = widT
1118-
val regs = Vec(Isa.maxNumRegs, new Bundle {
1119-
val enable = Bool()
1120-
val address = pRegT
1121-
val data = UInt((muonParams.numLanes * muonParams.archLen).W)
1118+
val trace = Input(new Bundle {
1119+
val valid = Bool()
1120+
val pc = pcT
1121+
val warpId = widT
1122+
val regs = Vec(Isa.maxNumRegs, new Bundle {
1123+
val enable = Bool()
1124+
val address = pRegT
1125+
val data = UInt((muonParams.numLanes * muonParams.archLen).W)
1126+
})
11221127
})
11231128
})
1129+
1130+
addResource("/vsrc/CyclotronDiffTest.v")
1131+
addResource("/vsrc/Cyclotron.vh")
1132+
addResource("/csrc/Cyclotron.cc")
1133+
}
1134+
}
1135+
1136+
class Profiler(implicit p: Parameters) extends CoreModule {
1137+
val io = IO(new Bundle {
1138+
val finished = Input(Bool())
1139+
val perf = Flipped(new PerfIO)
11241140
})
11251141

1126-
addResource("/vsrc/CyclotronDiffTest.v")
1127-
addResource("/vsrc/Cyclotron.vh")
1128-
addResource("/csrc/Cyclotron.cc")
1142+
val bbox = Module(new ProfilerBlackBox()(p))
1143+
bbox.io.clock := clock
1144+
bbox.io.reset := reset.asBool
1145+
1146+
bbox.io.perf <> io.perf
1147+
bbox.io.finished := io.finished
1148+
1149+
class ProfilerBlackBox()(implicit val p: Parameters)
1150+
extends BlackBox(Map(
1151+
"COUNTER_WIDTH" -> Perf.counterWidth,
1152+
)) with HasBlackBoxResource with HasCoreParameters {
1153+
val io = IO(new Bundle {
1154+
val clock = Input(Clock())
1155+
val reset = Input(Bool())
1156+
val finished = Input(Bool())
1157+
val perf = Flipped(new PerfIO)
1158+
})
1159+
1160+
addResource("/vsrc/Profiler.v")
1161+
addResource("/vsrc/Cyclotron.vh")
1162+
addResource("/csrc/Cyclotron.cc")
1163+
}
11291164
}
11301165

11311166
class CyclotronMemBlackBox(implicit p: Parameters) extends CyclotronBlackBox

0 commit comments

Comments
 (0)