generated from mpskex/chisel-docker-build
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
287 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// See README.md for license details. | ||
|
||
package isa.backend | ||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
class NCoreCUBundle (val size: Int = 4096) extends Bundle { | ||
val accum = Bool() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,41 @@ | ||
// See README.md for license details | ||
package ncore | ||
import isa.backend._ | ||
import pe._ | ||
|
||
import chisel3._ | ||
|
||
|
||
/** | ||
* This is the neural core design | ||
*/ | ||
class NeuralCoreforTest(val n: Int = 8, val nbits: Int = 8, val ctrl_width: Int = 8) extends Module { | ||
class NeuralCore(val n: Int = 8, val nbits: Int = 8, val sram_size: Int = 4096) extends Module { | ||
val io = IO(new Bundle { | ||
val vec_a = Input(Vec(n, UInt(nbits.W))) // vector `a` is the left input | ||
val vec_b = Input(Vec(n, UInt(nbits.W))) // vector `b` is the top input | ||
val ctrl = Input(UInt(ctrl_width.W)) | ||
val ctrl = Input(new NCoreCUBundle()) | ||
val out = Output(Vec(n * n, UInt((2 * nbits + 12).W))) | ||
}) | ||
|
||
// Create n x n pe blocks | ||
val pe_io = VecInit(Seq.fill(n * n) {Module(new pe.PE(nbits)).io}) | ||
// Create 2d register for horizontal & vertical | ||
val pe_reg_h = RegInit(VecInit(Seq.fill((n - 1) * n)(0.U(nbits.W)))) | ||
val pe_reg_v = RegInit(VecInit(Seq.fill((n - 1) * n)(0.U(nbits.W)))) | ||
|
||
// we use systolic array to pipeline the instructions | ||
// this will avoid bubble and inst complexity | ||
// while simplifying design with higher efficiency | ||
val ctrl_array = Module(new cu.ControlUnit(n, ctrl_width)) | ||
val ctrl_array = Module(new cu.ControlUnit(n, sram_size)) | ||
ctrl_array.io.cbus_in := io.ctrl | ||
|
||
val sarray = Module(new sa.SystolicArray2D(n, nbits)) | ||
sarray.io.vec_a := io.vec_a | ||
sarray.io.vec_b := io.vec_b | ||
|
||
for (i <- 0 until n){ | ||
for (j <- 0 until n) { | ||
// ==== OUTPUT ==== | ||
// pe array's output mapped to the matrix position | ||
pe_io(n * i + j).in_a := sarray.io.out_a(n * i + j) | ||
pe_io(n * i + j).in_b := sarray.io.out_b(n * i + j) | ||
pe_io(n * i + j).ctrl := ctrl_array.io.cbus_out(n * i + j) | ||
io.out(n * i + j) := pe_io(n * i + j).out | ||
|
||
// ==== INPUT ==== | ||
// vertical | ||
if (i==0) { | ||
pe_io(j).in_b := io.vec_b(j) | ||
} else { | ||
pe_io(n * i + j).in_b := pe_reg_v(n * (i - 1) + j) | ||
} | ||
if (i < n - 1 && j < n) | ||
pe_reg_v(n * i + j) := pe_io(n * i + j).in_b | ||
|
||
// horizontal | ||
if (j==0) { | ||
pe_io(n * i).in_a := io.vec_a(i) | ||
} else { | ||
pe_io(n * i + j).in_a := pe_reg_h((n - 1) * i + (j - 1)) | ||
} | ||
if (i < n && j < n - 1) | ||
pe_reg_h((n - 1) * i + j) := pe_io(n * i + j).in_a | ||
|
||
// ==== CONTROL ==== | ||
// Currently we only have one bit control | ||
// which is `ACCUM` | ||
// TODO: | ||
// Add ALU control to pe elements | ||
val ctrl = ctrl_array.io.cbus_out(n * i + j).asBools | ||
pe_io(n * i + j).accum := ctrl(0) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// See README.md for license details | ||
package ncore.sa | ||
|
||
import chisel3._ | ||
|
||
|
||
/** | ||
* This is the neural core design | ||
*/ | ||
class SystolicArray2D(val n: Int = 8, val nbits: Int = 8) extends Module { | ||
val io = IO(new Bundle { | ||
val vec_a = Input(Vec(n, UInt(nbits.W))) // vector `a` is the left input | ||
val vec_b = Input(Vec(n, UInt(nbits.W))) // vector `b` is the top input | ||
val out_a = Output(Vec(n * n, UInt(nbits.W))) | ||
val out_b = Output(Vec(n * n, UInt(nbits.W))) | ||
|
||
}) | ||
|
||
// Create 2d register for horizontal & vertical | ||
val reg_h = RegInit(VecInit(Seq.fill((n - 1) * n)(0.U(nbits.W)))) | ||
val reg_v = RegInit(VecInit(Seq.fill((n - 1) * n)(0.U(nbits.W)))) | ||
|
||
for (i <- 0 until n){ | ||
for (j <- 0 until n) { | ||
|
||
// ==== INPUT ==== | ||
// vertical | ||
if (i==0) { | ||
io.out_b(j) := io.vec_b(j) | ||
} else { | ||
io.out_b(n * i + j) := reg_v(n * (i - 1) + j) | ||
} | ||
if (i < n - 1 && j < n) | ||
reg_v(n * i + j) := io.out_b(n * i + j) | ||
|
||
// horizontal | ||
if (j==0) { | ||
io.out_a(n * i) := io.vec_a(i) | ||
} else { | ||
io.out_a(n * i + j) := reg_h((n - 1) * i + (j - 1)) | ||
} | ||
if (i < n && j < n - 1) | ||
reg_h((n - 1) * i + j) := io.out_a(n * i + j) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.