Got an unnexpected error: "Attempted reassignment of binding to chisel3.core.UInt@29a" when declaring a Module's io

Got an unnexpected error: "Attempted reassignment of binding to chisel3.core.UInt@29a" when declaring a Module's io

声明新模块的 io 时出现以下错误:

[error] (run-main-e) chisel3.core.Binding$RebindingException: Attempted reassignment of binding to chisel3.core.UInt@29a
[error] chisel3.core.Binding$RebindingException: Attempted reassignment of binding to chisel3.core.UInt@29a
[error]     at chisel3.core.Data.binding_$eq(Data.scala:250)
[error]     at chisel3.core.Element.bind(Bits.scala:22)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:23)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:22)
[error]     at scala.collection.Iterator$class.foreach(Iterator.scala:891)
[error]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
[error]     at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
[error]     at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
[error]     at chisel3.core.Aggregate.bind(Aggregate.scala:22)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:23)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:22)
[error]     at scala.collection.Iterator$class.foreach(Iterator.scala:891)
[error]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
[error]     at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
[error]     at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
[error]     at chisel3.core.Aggregate.bind(Aggregate.scala:22)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:23)
[error]     at chisel3.core.Aggregate$$anonfun$bind.apply(Aggregate.scala:22)
[error]     at scala.collection.Iterator$class.foreach(Iterator.scala:891)
[error]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
[error]     at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
[error]     at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
[error]     at chisel3.core.Aggregate.bind(Aggregate.scala:22)
[error]     at chisel3.core.BaseModule._bindIoInPlace(Module.scala:249)
[error]     at chisel3.core.BaseModule.IO(Module.scala:282)
[error]     at RayIntersect.LeafIntersect.<init>(PrimIntersect.scala:71)
[error]     at RayIntersect.MyTopLevelVerilog$$anonfun.apply(RayIntersectTest.scala:11)
[error]     at RayIntersect.MyTopLevelVerilog$$anonfun.apply(RayIntersectTest.scala:11)
[error]     at chisel3.core.Module$.do_apply(Module.scala:49)
[error]     at chisel3.Driver$$anonfun$elaborate.apply(Driver.scala:93)
[error]     at chisel3.Driver$$anonfun$elaborate.apply(Driver.scala:93)
[error]     at chisel3.internal.Builder$$anonfun$build.apply(Builder.scala:297)
[error]     at chisel3.internal.Builder$$anonfun$build.apply(Builder.scala:295)
[error]     at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
[error]     at chisel3.internal.Builder$.build(Builder.scala:295)
[error]     at chisel3.Driver$.elaborate(Driver.scala:93)
[error]     at chisel3.Driver$.execute(Driver.scala:140)
[error]     at chisel3.Driver$.execute(Driver.scala:202)
[error]     at RayIntersect.MyTopLevelVerilog$.delayedEndpoint$RayIntersect$MyTopLevelVerilog(RayIntersectTest.scala:11)
[error]     at RayIntersect.MyTopLevelVerilog$delayedInit$body.apply(RayIntersectTest.scala:5)
[error]     at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
[error]     at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[error]     at scala.App$$anonfun$main.apply(App.scala:76)
[error]     at scala.App$$anonfun$main.apply(App.scala:76)
[error]     at scala.collection.immutable.List.foreach(List.scala:392)
[error]     at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
[error]     at scala.App$class.main(App.scala:76)
[error]     at RayIntersect.MyTopLevelVerilog$.main(RayIntersectTest.scala:5)
[error]     at RayIntersect.MyTopLevelVerilog.main(RayIntersectTest.scala)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]     at java.lang.reflect.Method.invoke(Method.java:498)
[error]     at sbt.Run.invokeMain(Run.scala:93)
[error]     at sbt.Run.run0(Run.scala:87)
[error]     at sbt.Run.execute(Run.scala:65)
[error]     at sbt.Run.$anonfun$run(Run.scala:77)
[error]     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]     at sbt.util.InterfaceUtil$$anon.get(InterfaceUtil.scala:10)
[error]     at sbt.TrapExit$App.run(TrapExit.scala:252)
[error]     at java.lang.Thread.run(Thread.java:745)

错误中引用的行(RayIntersect.LeafIntersect 的第 71 行)如下:

val io = IO(new Bundle {

以下是 io 声明的其余部分,如果有帮助的话:

val io = IO(new Bundle {
    val rayNodeStackIn = Flipped(DecoupledIO(new RayBVHNodeStackIdx(id_width, index_width)))
    val shadow         = Input(Bool())
    val rayNodeOut     = DecoupledIO(new RayBVHNode(id_width, index_width))
    val dataOut        = DecoupledIO(new Bundle {
        val foundInt = Bool()
        val f        = UInt(index_width.W)
        val its      = new Intersection()         
    })

    //Memory system interface
    val addrOut   = DecoupledIO(new Bundle {
       val id    = UInt(id_width.W)
       val trIdx = UInt(prim_id_width.W) 
    }
    val dataIn    = Flipped(DecoupledIO(new Bundle {
        val id    = UInt(id_width.W)
        val data  = UInt((new Triangle()).getWidth)
    }))
})

这是使用的捆绑包的代码:

class Triangle() extends Bundle {
    val p0        = Vec(3, UInt(32.W))
    val p1        = Vec(3, UInt(32.W))
    val p2        = Vec(3, UInt(32.W))
    val idx       = UInt(32.W)
    val meshAddr = UInt(32.W)
}

class BVHNode() extends Bundle {
    val data = UInt(64.W)

    val bbox = new Bundle {
        val min = Vec(3, UInt(32.W))
        val max = Vec(3, UInt(32.W))
    }

    def rightChild: UInt = (data << 32) 
    def leafStart : UInt = (data << 32)
    def leafSize  : UInt = (data << 1) & 0xFFFFFFFE.U
    def start     : UInt = leafStart
    def end       : UInt = leafStart + leafSize

    def isLeaf    : Bool = data(0)

    override def cloneType = (new BVHNode()).asInstanceOf[this.type]
}

class Ray(sid_width : Int) extends Bundle {
    val origin  = Vec(3, UInt(32.W))
    val dir     = Vec(3, UInt(32.W))
    val dRcp    = Vec(3, UInt(32.W)) //Componentwise reciprocals of the ray direction
    val minT    = UInt(32.W)
    val maxT    = UInt(32.W)
    val id      = UInt(32.W)

    override def cloneType = (new Ray(sid_width)).asInstanceOf[this.type]
}

class RayBVHNodeStackIdx(id_width: Int, index_width: Int) extends Bundle {
    val ray      = new Ray(id_width)
    val node     = new BVHNode()
    val nodeIdx  = UInt(index_width.W)
    val stackIdx = UInt(index_width.W)

    override def cloneType = (new RayBVHNodeStackIdx(id_width, index_width)).asInstanceOf[this.type]
}

class RayBVHNode(id_width: Int, index_width : Int) extends Bundle {
    val ray     = new Ray(id_width)
    val node    = new BVHNode()
    val nodeIdx = UInt(index_width.W)

    override def cloneType = (new RayBVHNode(id_width, index_width)).asInstanceOf[this.type]
}

class Intersection() extends Bundle {
    val t = UInt(32.W)          //Unoccluded distance along the ray
    val u = UInt(32.W)          //UV coordinate, if any
    val v = UInt(32.W)          //Other UV coordinate
    val mesh    = UInt(32.W)            //pointer to the intersected mesh
}

根据我的阅读,这个错误通常发生在尝试使用裸 Chisel 类型作为硬件时,但是我真的不明白为什么错误来自 io 声明...

有没有其他人在他们的实施中遇到过这个问题,如果遇到过,您是否有机会知道如何解决它?

我能够 运行 这段代码只需稍加修改就可以了。我添加了一个 .Wval data = UInt((new Triangle()).getWidth.W):

    val dataIn    = Flipped(DecoupledIO(new Bundle {
        val id    = UInt(id_width.W)
        val data  = UInt((new Triangle()).getWidth)
    }))

变成

    val dataIn    = Flipped(DecoupledIO(new Bundle {
        val id    = UInt(id_width.W)
        val data  = UInt((new Triangle()).getWidth.W)
    }))

从堆栈跟踪和错误消息来看,这看起来像是旧版本的 Chisel。在 Chisel 3.2.0 之前,UInt(someInt) 创建了一个文字,与 someInt.U 相同(尽管自 Chisel 3.0.0 以来它已被弃用)。我能够使用 Chisel 3.1.8 重现报告的错误。我在 运行 与 3.2.2 结合此代码时收到的错误指出了问题,使其很容易修复!

我建议尽可能使用最新版本的 Chisel(截至 2020 年 1 月 13 日,即 3.2.2)。您可以关注 repo 的 "releases" 页面以查看新版本:https://github.com/freechipsproject/chisel3/releases.