question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

For this code the time from firrtl to verilg could be very slow

See original GitHub issue

I wrote a code (pasted following) which the run time from firrtl to verilog was hours long. Could you help on this performance issue? The running log looks like:

mkdir: cannot create directory `target’: File exists warning: there was one deprecation warning; re-run with -deprecation for details warning: there were 49 feature warnings; re-run with -feature for details two warnings found Run starting. Expected test count is: 2 Test: [info] [0.002] Elaborating design… [info] [0.712] Done elaborating.

  • elaborate [info] [0.000] Elaborating design… [info] [0.255] Done elaborating.

From this point on, the time will be very long to the end.

@jackkoenig I think you are the one who answered me at https://stackoverflow.com/questions/44849211/can-chisel-translates-firrtl-to-verilog-in-parallel-multi-cpu, Thanks. I had another trouble on sbt so I compiled my code like this way: mkdir target cp /opt/RISCV/top.cpp target scalac -d target -cp $CP Top.scala Test.scala scala -cp $CP org.scalatest.run Test # this step takes hours

The scala compiler and code runner version 2.11.8

something went wrong and the file can not be processed so I just pasted the code here, please take a look at the last class Top:

import chisel3._
import chisel3.util._

object ce_pm{
  val div = 4
  val e = 1   
  val ec= 1   
  val p = 10 // 16/div        
  val s = p*p       
  val w = s*e       

  val ext = 64      
  val extw= ext*e   

  val irp = 10 // 32/div  // this parameter matters !! 32 will cost much more time.
  val irn = irp*irp 
}

class Mux4(n: Int) extends Module {
  val io = IO(new Bundle{
    val i = Input(Vec(4,UInt(n.W)))
    val s = Input(UInt(2.W))
    val o = Output(UInt(n.W))
  })
  val mux00 = Wire(UInt(n.W))
  val mux01 = Wire(UInt(n.W))
  mux00 := Mux(io.s(0)===1.U,io.i(1),io.i(0))
  mux01 := Mux(io.s(0)===1.U,io.i(3),io.i(2))
  io.o  := Mux(io.s(1)===1.U,mux01,mux00)
}

class CEIO_TwoD_Torus extends Bundle {
  val n = Input(UInt(ce_pm.e.W))
  val s = Input(UInt(ce_pm.e.W))
  val w = Input(UInt(ce_pm.e.W))
  val e = Input(UInt(ce_pm.e.W))
}

class TwoD_TorusReg extends Module {
  val io = IO(new Bundle{
    val i = new CEIO_TwoD_Torus()
    val o = new CEIO_TwoD_Torus().flip
    val d = Input(UInt(ce_pm.e.W)) // set data
    val c = Input(Vec(4,UInt(1.W)))
  })
  val r = Reg(UInt(ce_pm.e.W),init=0.U)
  val u_mux4 = Module(new Mux4(ce_pm.e))
  u_mux4.io.i(0) := io.i.e
  u_mux4.io.i(1) := io.i.s
  u_mux4.io.i(2) := io.i.w
  u_mux4.io.i(3) := io.i.n
  u_mux4.io.s    := Cat(io.c(2),io.c(1))
  when (io.c(0) === 1.U) {
    when (io.c(3) === 0.U) {
      r := u_mux4.io.o
    } .otherwise {
      r := io.d
    }
  } 
  io.o.e := r
  io.o.s := r
  io.o.w := r
  io.o.n := r
}

class Top extends Module {    
  val io = IO(new Bundle{
    val i = Input (UInt(ce_pm.extw.W))
    val o = Output(Vec(ce_pm.p,Vec(ce_pm.p,UInt(ce_pm.e.W))))
    val c = Input (UInt(7.W))
  })
  val n  = ce_pm.irp // n matters when set 32 takes much more time
  val r_vec = (0 to n-1).map ( i=>
                (0 to n-1).map ( j=>
                  Module(new TwoD_TorusReg) // I inst many of them and then do interconnections
                )
              )
  for (i <- 0 to n-1) {
    for (j <- 0 to n-1) {
      //r_vec(i)(j).io.c := Cat(io.c(1),io.c(3),io.c(2),io.c(0)).asBits
      r_vec(i)(j).io.c(0) := io.c(1)
      r_vec(i)(j).io.c(3) := io.c(0)
      r_vec(i)(j).io.c(2) := io.c(2)
      r_vec(i)(j).io.c(1) := io.c(3)
    }
  }
  // out
  val m = ce_pm.p
  (0 to m-1).map(i=>{
    (0 to m-1).map(j=>{
      io.o(i)(j) := r_vec(i)(j).io.o.e
    })
  })
  //2-D-Torus interconnection
  (1 to n-1).map(i=>{
    (1 to n-1).map(j=>{
      r_vec(i)(j).io.i.w := r_vec(i)(j-1).io.o.e
      r_vec(i)(j).io.i.n := r_vec(i-1)(j).io.o.s
    })
  })
  (0 to n-2).map(i=>{
    (0 to n-2).map(j=>{
      r_vec(i)(j).io.i.e := r_vec(i)(j+1).io.o.w
      r_vec(i)(j).io.i.s := r_vec(i+1)(j).io.o.n
    })
  })
  (0 to n-1).map(i=>{
    r_vec(i)(0).io.i.w := r_vec(i)(n-1).io.o.e
    r_vec(0)(i).io.i.n := r_vec(n-1)(i).io.o.s
  })
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chickcommented, Jul 4, 2017

@apolonic If you are referring to the map statements here

  val r_vec = (0 to n-1).map ( i=>
                (0 to n-1).map ( j=>
                  Module(new TwoD_TorusReg)
                )
              )

You cannot use foreach in this case, so map is ok, but the simplest way of getting your 2d data structure is

  val r_vec = Array.fill(n, n)(Module(new TwoD_TorusReg))

Checkout Creating collections from scratch for a handy cheatsheet. I like to use tabulate when the elements I am creating depend on their indices. In the case at hand though, fill is the proper way.

0reactions
ducky64commented, Nov 8, 2017

This has been inactive for a while, if it’s still an issue feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

For this code the time from firrtl to verilg could be very slow #640
I wrote a code (pasted following) which the run time from firrtl to verilog was hours long. Could you help on this performance...
Read more >
freechipsproject/firrtl - Gitter
We've got the VCS compile time down to 20 seconds or so using some of their partitioning options. Are their any ways to...
Read more >
Chisel compiled successfully but can't generate correctly verilog
I use Chisel write an RISC-V CPU, Chisel code compiled successfully and Firrtl code generate successfully too, but ...
Read more >
Errors while running firtool, but Verilog still generated - CIRCT
This indicates that you may have divergence from the SFC due to unsupported features.
Read more >
Unlocking Design Reuse with Hardware Compiler Frameworks
Chisel and FIRRTL ecosystem, upon which this entire thesis is built: ... Thirdly, slow but correct code can be iteratively improved upon via....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found