Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Proper Control Flow for FIR filter #257

Open
mattfel1 opened this issue Jan 25, 2018 · 0 comments
Open

Proper Control Flow for FIR filter #257

mattfel1 opened this issue Jan 25, 2018 · 0 comments

Comments

@mattfel1
Copy link
Member

 def FIR_Filter(args: Array[String]) {
   val input = StreamIn[Int](target.In)
   val output = StreamOut[Int](target.Out)
   val weights = DRAM[Int](32)
   val width = ArgIn[Int]
   val P = 16 (1,1,32)

   // Initialize width with the first console argument
   setArg(width, min(32, args(0).to[Int]) )

   // Transfer weights from the host to accelerator
   sendArray(weights, loadData[Int]("weights.csv"))

   Accel(*) {
     val wts = RegFile[Int](32)
     val ins = RegFile[Int](32)
     val sum = Reg[Int]
    
     // Load weights from DRAM into local registers
     wts load weights(0::width)
    
     // Stream continuously
     Stream(*) {
     // Shift in the most recent input
     ins <<= input
    
     // Create a reduce-accumulate tree with P inputs
     Reduce(sum)(0 until width par P){i =>
       // Multiply corresponding weight and input
       wts(i) * ins(i)
     }{(a,b) => a + b }
    
     // Assign the result of computing the average
     // to the output stream
     output := sum / width
   }
 }

To make this actually correct, we need a Pipe wrapped just inside the Stream(*) because the Reduce and output := pipes will actually just run all the time no matter what. Or we need stream-aware memory structures for this kind of thing, like shift-acknowledgements and register staleness

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant