我正在研究一种矩阵求和类型的设计。编译器需要 4+ 小时才能生成 1+ 百万行代码。每一行都是“分配.....”我不知道这是编译器效率低下还是我的编码风格不好。如果有人可以提出一些替代方案,那就太好了!
这是代码的描述输入将是一个随机矩阵元素的AND,并使用.reduce求和,所以结果矩阵应该是140X6 vec,它们一起给我一个840位的输出
(rndvec,它应该是一个 140x840x6 位的随机矩阵。因为我不知道如何生成随机值,所以我从一个固定的 140x6 开始表示一行并一遍又一遍地输入它)
以下是我的代码
import Chisel._
import scala.collection.mutable.HashMap
import util.Random
class LBio(n: Int) extends Bundle {
var myinput = UInt(INPUT,840)
var myoutput = UInt (OUTPUT,840)
}
class Lbi(q: Int,n:Int,m :Int ) extends Module{
def mask(orig: Vec[UInt],maska:UInt,mi:Int)={
val result = Vec.fill(840){UInt(width =6)}
for (i<-0 until 840 ){
result(i) := orig(i)&Fill(6,maska(i)) //every bits of input AND with random vector
}
result
}
val io= new LBio(840)
val rndvec = Vec.fill(840){UInt("h13",6)} //random vector, for now its just replication of 0x13....
val resultvec = Vec.fill(140){UInt(width = 6)}
for (i<-0 until 140){
resultvec(i) := mask(rndvec,io.myinput,m).reduce(_+_) //add the entire row of 6 bits element together with reduce
}
io.myoutput := resultvec.toBits
}
终端报告:
started inference
finished inference (4)
start width checking
finished width checking
started flattenning
finished flattening (941783)
resolving nodes to the components
finished resolving
started transforms
finished transforms
checking for combinational loops
NO COMBINATIONAL LOOP FOUND
COMPILING class TutorialExamples.Lbi 0 CHILDREN (0,0)
[success] Total time: 33453 s, completed Oct 16, 2013 10:32:10 PM