Chisel PeekPokeTester 中的 Printf 在同一 RTL 上的行为与验证器不同
Printf in Chisel PeekPokeTester behaves differently from verilator on the same RTL
在 Chisel 的 iotester 中打印似乎输出了寄存器值的更新版本,这使得相同的 Chisel 打印代码在 Chisel 后端和 verilator 后端表现不同。
当使用Chisel后端时,打印似乎只是记录硬件对象的引用,但是在当前步骤的逻辑模拟之后执行打印,然后引用以更新的值回复。
我搜索了 Chisel repo 的问题和 chisel 用户组,但发现很少有关于此主题的讨论。
这是 chisel-template 存储库顶部的独立代码示例。
package myrtl
import chisel3._
import chisel3.iotesters._
class Foo extends Module {
val io = IO(new Bundle {
val in = Input(UInt(32.W))
val out = Output(UInt(32.W))
})
val v = Wire(UInt(32.W))
when (v === 0.U) {
printf(p"v $v\n")
}
val reg = RegInit(0.U(32.W))
reg := io.in
io.out := reg
v := reg
}
class FooTester(dut: Foo) extends PeekPokeTester(dut) {
poke(dut.io.in, 32)
step(1)
}
object TestMain extends App {
iotesters.Driver.execute(args, () => new Foo)(dut => new FooTester(dut))
}
注意printf
的情况。可笑的是 v === 0.U
启用了打印,但将此 v
作为 32
.
的值输出
我相信这是一个报告的错误,其中 printf
语句没有正确计算它们的依赖关系(并且已修复)。
过去一年中进行了多次重构,可能是解决此问题的原因:
你能尝试在 sonatype 上切换到 1.3-SNAPSHOT
并重新测试吗?
diff --git a/build.sbt b/build.sbt
index 6d18fe7..c13d44d 100644
--- a/build.sbt
+++ b/build.sbt
@@ -41,11 +41,10 @@ resolvers ++= Seq(
// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
val defaultVersions = Map(
- "chisel3" -> "3.1.+",
- "chisel-iotesters" -> "[1.2.5,1.3.0["
+ "chisel-iotesters" -> "1.3-SNAPSHOT"
)
-libraryDependencies ++= Seq("chisel3","chisel-iotesters").map {
+libraryDependencies ++= Seq("chisel-iotesters").map {
dep: String => "edu.berkeley.cs" %% dep % sys.props.getOrElse(dep + "Version", defaultVersions(dep)) }
scalacOptions ++= scalacOptionsVersion(scalaVersion.value)
通过对 build.sbt
的这些修改,我能够看到没有打印的预期行为。这与 Verilator 不同,后者在模拟开始前似乎只有一张打印件。使用 1.3-SNAPSHOT
:
sbt:chisel-module-template> test:runMain myrtl.TestMain --backend-name treadle
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running myrtl.TestMain --backend-name treadle
[info] [0.001] Elaborating design...
[info] [0.108] Done elaborating.
Total FIRRTL Compile Time: 408.8 ms
file loaded in 0.071117471 seconds, 15 symbols, 12 statements
[info] [0.001] SEED 1568033935603
test Foo Success: 0 tests passed in 6 cycles in 0.012474 seconds 481.00 Hz
[info] [0.003] RAN 1 CYCLES PASSED
[success] Total time: 2 s, completed Sep 9, 2019 8:58:56 AM
并且在使用 verilator 时(对输出进行一些剪切):
sbt:chisel-module-template> test:runMain myrtl.TestMain --backend-name verilator
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running myrtl.TestMain --backend-name verilator
[info] [0.001] Elaborating design...
[info] [0.108] Done elaborating.
Total FIRRTL Compile Time: 440.6 ms
[info] [0.001] SEED 1568034082729
[info] [0.007] v 0
[info] [0.007] 0
Enabling waves..
Exit Code: 0
[info] [0.011] RAN 1 CYCLES PASSED
[success] Total time: 4 s, completed Sep 9, 2019 9:01:25 AM
在 Chisel 的 iotester 中打印似乎输出了寄存器值的更新版本,这使得相同的 Chisel 打印代码在 Chisel 后端和 verilator 后端表现不同。
当使用Chisel后端时,打印似乎只是记录硬件对象的引用,但是在当前步骤的逻辑模拟之后执行打印,然后引用以更新的值回复。
我搜索了 Chisel repo 的问题和 chisel 用户组,但发现很少有关于此主题的讨论。
这是 chisel-template 存储库顶部的独立代码示例。
package myrtl
import chisel3._
import chisel3.iotesters._
class Foo extends Module {
val io = IO(new Bundle {
val in = Input(UInt(32.W))
val out = Output(UInt(32.W))
})
val v = Wire(UInt(32.W))
when (v === 0.U) {
printf(p"v $v\n")
}
val reg = RegInit(0.U(32.W))
reg := io.in
io.out := reg
v := reg
}
class FooTester(dut: Foo) extends PeekPokeTester(dut) {
poke(dut.io.in, 32)
step(1)
}
object TestMain extends App {
iotesters.Driver.execute(args, () => new Foo)(dut => new FooTester(dut))
}
注意printf
的情况。可笑的是 v === 0.U
启用了打印,但将此 v
作为 32
.
我相信这是一个报告的错误,其中 printf
语句没有正确计算它们的依赖关系(并且已修复)。
过去一年中进行了多次重构,可能是解决此问题的原因:
你能尝试在 sonatype 上切换到 1.3-SNAPSHOT
并重新测试吗?
diff --git a/build.sbt b/build.sbt
index 6d18fe7..c13d44d 100644
--- a/build.sbt
+++ b/build.sbt
@@ -41,11 +41,10 @@ resolvers ++= Seq(
// Provide a managed dependency on X if -DXVersion="" is supplied on the command line.
val defaultVersions = Map(
- "chisel3" -> "3.1.+",
- "chisel-iotesters" -> "[1.2.5,1.3.0["
+ "chisel-iotesters" -> "1.3-SNAPSHOT"
)
-libraryDependencies ++= Seq("chisel3","chisel-iotesters").map {
+libraryDependencies ++= Seq("chisel-iotesters").map {
dep: String => "edu.berkeley.cs" %% dep % sys.props.getOrElse(dep + "Version", defaultVersions(dep)) }
scalacOptions ++= scalacOptionsVersion(scalaVersion.value)
通过对 build.sbt
的这些修改,我能够看到没有打印的预期行为。这与 Verilator 不同,后者在模拟开始前似乎只有一张打印件。使用 1.3-SNAPSHOT
:
sbt:chisel-module-template> test:runMain myrtl.TestMain --backend-name treadle
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running myrtl.TestMain --backend-name treadle
[info] [0.001] Elaborating design...
[info] [0.108] Done elaborating.
Total FIRRTL Compile Time: 408.8 ms
file loaded in 0.071117471 seconds, 15 symbols, 12 statements
[info] [0.001] SEED 1568033935603
test Foo Success: 0 tests passed in 6 cycles in 0.012474 seconds 481.00 Hz
[info] [0.003] RAN 1 CYCLES PASSED
[success] Total time: 2 s, completed Sep 9, 2019 8:58:56 AM
并且在使用 verilator 时(对输出进行一些剪切):
sbt:chisel-module-template> test:runMain myrtl.TestMain --backend-name verilator
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running myrtl.TestMain --backend-name verilator
[info] [0.001] Elaborating design...
[info] [0.108] Done elaborating.
Total FIRRTL Compile Time: 440.6 ms
[info] [0.001] SEED 1568034082729
[info] [0.007] v 0
[info] [0.007] 0
Enabling waves..
Exit Code: 0
[info] [0.011] RAN 1 CYCLES PASSED
[success] Total time: 4 s, completed Sep 9, 2019 9:01:25 AM