Skip to content

Commit a46ec48

Browse files
committed
test: Hook up MuonCoreTop with Cyclotron inst mem
1 parent 998c97d commit a46ec48

6 files changed

Lines changed: 108 additions & 35 deletions

File tree

src/main/resources/csrc/Cyclotron.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ void cyclotron_init(const char* elfname) {
3636
cyclotron_init_rs(elfname);
3737
}
3838

39+
void cyclotron_fetch_rs(
40+
uint8_t req_valid,
41+
uint64_t req_bits_tag,
42+
uint32_t req_bits_pc,
43+
uint8_t* resp_valid_ptr,
44+
uint64_t* resp_bits_tag_ptr,
45+
uint64_t* resp_bits_inst_ptr
46+
);
47+
48+
void cyclotron_fetch(
49+
uint8_t req_valid,
50+
uint64_t req_bits_tag,
51+
uint32_t req_bits_pc,
52+
uint8_t* resp_valid_ptr,
53+
uint64_t* resp_bits_tag_ptr,
54+
uint64_t* resp_bits_inst_ptr
55+
) {
56+
cyclotron_fetch_rs(
57+
req_valid,
58+
req_bits_tag,
59+
req_bits_pc,
60+
resp_valid_ptr,
61+
resp_bits_tag_ptr,
62+
resp_bits_inst_ptr
63+
);
64+
}
65+
3966
void cyclotron_frontend_rs(
4067
const uint8_t* ibuf_ready_vec,
4168
uint8_t* ibuf_valid_vec,

src/main/resources/vsrc/Cyclotron.vh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ import "DPI-C" function void cyclotron_init(input string elffile);
88

99
import "DPI-C" function string vpi_get_binary();
1010

11-
import "DPI-C" function cyclotron_difftest_reg(
12-
input bit trace_sim_tick,
13-
input bit trace_valid,
14-
input int trace_pc,
15-
input int trace_warpId,
16-
input bit trace_regs_0_enable,
17-
input byte trace_regs_0_address,
18-
input int trace_regs_0_data[NUM_LANES],
19-
input bit trace_regs_1_enable,
20-
input byte trace_regs_1_address,
21-
input int trace_regs_1_data[NUM_LANES],
22-
input bit trace_regs_2_enable,
23-
input byte trace_regs_2_address,
24-
input int trace_regs_2_data[NUM_LANES]
25-
);
26-
2711
task automatic cyclotron_init_task();
2812
string elffile;
2913
elffile = vpi_get_binary();

src/main/resources/vsrc/CyclotronDiffTest.v

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ module CyclotronDiffTestBlackBox #(
3636
);
3737
`include "Cyclotron.vh"
3838

39+
import "DPI-C" function cyclotron_difftest_reg(
40+
input bit trace_sim_tick,
41+
input bit trace_valid,
42+
input int trace_pc,
43+
input int trace_warpId,
44+
input bit trace_regs_0_enable,
45+
input byte trace_regs_0_address,
46+
input int trace_regs_0_data[NUM_LANES],
47+
input bit trace_regs_1_enable,
48+
input byte trace_regs_1_address,
49+
input int trace_regs_1_data[NUM_LANES],
50+
input bit trace_regs_2_enable,
51+
input byte trace_regs_2_address,
52+
input int trace_regs_2_data[NUM_LANES]
53+
);
54+
3955
// "in": C->verilog, "out": verilog->C
4056
// need to be in ascending order to match with C array memory layout
4157
bit __out_trace_valid;

src/main/scala/radiance/muon/MuonTile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class MuonTile(
159159
emits = TLMasterToSlaveTransferSizes(
160160
get = TransferSizes(1, muonParams.core.instBytes)
161161
),
162-
sourceId = IdRange(0, muonParams.core.numWarps * muonParams.core.ibufDepth)
162+
sourceId = IdRange(0, muonParams.core.l0iReqTagBits)
163163
)),
164164
channelBytes = TLChannelBeatBytes(muonParams.core.instBytes),
165165
)))

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

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import chisel3.experimental.BundleLiterals._
99
import chisel3.experimental.VecLiterals._
1010
import org.chipsalliance.cde.config.Parameters
1111
import org.chipsalliance.diplomacy.lazymodule.{LazyModule, LazyModuleImp}
12+
import freechips.rocketchip.diplomacy.{IdRange, TransferSizes}
1213
import freechips.rocketchip.tile.TileKey
1314
import freechips.rocketchip.tilelink._
1415
import freechips.rocketchip.diplomacy.{IdRange, AddressSet}
@@ -20,13 +21,15 @@ import scala.collection.mutable.ArrayBuffer
2021
/** Testbench for Muon with the test signals */
2122
class MuonCoreTestbench(implicit p: Parameters) extends LazyModule {
2223
val coreTop = LazyModule(new MuonCoreTop()(p.alterMap(Map(
23-
// FIXME: this should be unnecessary with WithMuonCores(headless = true)
24+
// @cleanup: this should be unnecessary with WithMuonCores(headless = true)
2425
TileKey -> DummyTileParams
2526
))))
2627
val xbar = TLXbar()
2728
val fakeGmem = TLRAM(
28-
address = AddressSet(0x0, 1024*1024*16-1), // TODO: don't hardcode; 1MB region for each warp
29-
beatBytes = p(MuonKey).archLen / 8
29+
// address = AddressSet(0x0, (BigInt(1) << p(MuonKey).archLen) - 1),
30+
address = AddressSet(0x0, 0x1000 - 1),
31+
beatBytes = p(MuonKey).archLen / 8,
32+
devName = Some("gmem")
3033
)
3134

3235
// see doc in MuonLSUTestbench for TLBuffer
@@ -40,6 +43,7 @@ class MuonCoreTestbench(implicit p: Parameters) extends LazyModule {
4043
val io = IO(new Bundle {
4144
val finished = Bool()
4245
})
46+
4347
io.finished := coreTop.module.io.finished
4448
}
4549
}
@@ -178,23 +182,21 @@ class MuonLSUTestbench(implicit p: Parameters) extends LazyModule {
178182
}
179183
}
180184

181-
/** DUT module for core-standalone testbench */
185+
/** DUT module for core-standalone testbench.
186+
* Hooks up a MuonCore with a Rust instruction memory model, and exposes a TL
187+
* node for its global memory interface. */
182188
class MuonCoreTop(implicit p: Parameters) extends LazyModule with HasCoreParameters {
183189
val sourceIdsPerLane = 1 << lsuDerived.sourceIdBits
184190

185191
// every core lane is a separate TL client
186-
def masterParams = (lane: Int) => {
187-
val sourceId = IdRange(0, sourceIdsPerLane)
188-
TLMasterParameters.v1(
189-
name = f"lsu-gmem-lane$lane",
190-
sourceId = sourceId,
191-
requestFifo = false
192-
)
193-
}
194192
val lsuNodes = Seq.tabulate(muonParams.lsu.numLsuLanes) { lane =>
195193
TLClientNode(Seq(
196194
TLMasterPortParameters.v1(
197-
Seq(masterParams(lane))
195+
Seq(TLMasterParameters.v1(
196+
name = f"lsu-gmem-lane$lane",
197+
sourceId = IdRange(0, sourceIdsPerLane),
198+
requestFifo = false
199+
))
198200
)
199201
))
200202
}
@@ -206,16 +208,16 @@ class MuonCoreTop(implicit p: Parameters) extends LazyModule with HasCoreParamet
206208
})
207209

208210
val core = Module(new MuonCore()(p))
209-
core.io.imem.resp.valid := false.B
210-
core.io.imem.resp.bits := DontCare
211-
core.io.imem.req.ready := false.B
212211

213-
// mem <> lsuAdapter
212+
val imem = Module(new CyclotronInstMem)
213+
core.io.imem <> imem.io.imem
214+
214215
MuonMemTL.multiConnectTL(
215216
core.io.dmem.req,
216217
core.io.dmem.resp,
217218
lsuNodes
218219
)
220+
219221
// tie off shared mem
220222
core.io.smem.req.foreach(_.ready := false.B)
221223
core.io.smem.resp.foreach(_.valid := false.B)
@@ -1019,6 +1021,50 @@ with HasBlackBoxResource with HasCoreParameters {
10191021
addResource("/csrc/Cyclotron.cc")
10201022
}
10211023

1024+
class CyclotronInstMem(implicit p: Parameters) extends CoreModule {
1025+
val io = IO(new Bundle {
1026+
val imem = Flipped(new InstMemIO)
1027+
})
1028+
1029+
val bbox = Module(new CyclotronInstMemBlackBox)
1030+
bbox.io.clock := clock
1031+
bbox.io.reset := reset.asBool
1032+
1033+
io.imem.req.ready := true.B
1034+
bbox.io.req.valid := io.imem.req.valid
1035+
bbox.io.req.bits.tag := io.imem.req.bits.tag
1036+
bbox.io.req.bits.pc := io.imem.req.bits.address
1037+
1038+
io.imem.resp.valid := bbox.io.resp.valid
1039+
io.imem.resp.bits.tag := bbox.io.resp.bits.tag
1040+
io.imem.resp.bits.data := bbox.io.resp.bits.inst
1041+
io.imem.resp.bits.metadata := DontCare
1042+
1043+
class CyclotronInstMemBlackBox(implicit val p: Parameters)
1044+
extends BlackBox(Map(
1045+
"ARCH_LEN" -> p(MuonKey).archLen,
1046+
"INST_BITS" -> p(MuonKey).instBits,
1047+
"IMEM_TAG_BITS" -> p(MuonKey).l0iReqTagBits
1048+
)) with HasBlackBoxResource with HasCoreParameters {
1049+
val io = IO(new Bundle {
1050+
val clock = Input(Clock())
1051+
val reset = Input(Bool())
1052+
val req = Flipped(Valid(new Bundle {
1053+
val tag = UInt(imemTagBits.W)
1054+
val pc = pcT
1055+
}))
1056+
val resp = Valid(new Bundle {
1057+
val tag = UInt(imemTagBits.W)
1058+
val inst = instT
1059+
})
1060+
})
1061+
1062+
addResource("/vsrc/CyclotronInstMem.v")
1063+
addResource("/vsrc/Cyclotron.vh")
1064+
addResource("/csrc/Cyclotron.cc")
1065+
}
1066+
}
1067+
10221068
/** If `tick` is true, advance cyclotron sim by one tick inside the difftest
10231069
* logic. Set to false when some other module does the tick, e.g.
10241070
* separate cyclotron frontend */

0 commit comments

Comments
 (0)