@@ -37,6 +37,19 @@ case class EyerissModelParam(
37
37
private val inActNumInOnePEArray : Int = peRow + peCol - 1 // TODO: make it more fine grain
38
38
/** the read time for one SRAM to send all the PE their inAct*/
39
39
val inActSRAMReadTimes : Int = inActNumInOnePEArray/ inActSRAMNum
40
+ require(inActNumInOnePEArray % inActSRAMNum == 0 , s " inActNumInOnePEArray = $inActNumInOnePEArray should be " +
41
+ s " multiple of inActSRAMNum = $inActSRAMNum" )
42
+ val pSumOneSPadNum : Int = M0 * E * N0 * F0
43
+ val inActMatrixWidth : Int = F0 * N0 * E // column
44
+ val inActMatrixHeight : Int = R * C0 // row
45
+ val weightMatrixWidth : Int = inActMatrixHeight // column
46
+ val weightMatrixHeight : Int = M0 // row
47
+ val inActNoCNum : Int = G1 * N1 * C1 * (F1 + S1 )
48
+ val weightNoCNum : Int = G1 * M1 * C1 * S1
49
+ val pSumNoCNum : Int = G1 * N1 * M1 * F1
50
+ val weightGLBNum : Int = G2 * M2 * C2 * S2
51
+ val inActGLBNum : Int = G2 * N2 * C2 * (F2 + S2 )
52
+ val pSumGLBNum : Int = G2 * N2 * M2 * F2
40
53
}
41
54
object nnShape {
42
55
object inAct {
@@ -88,9 +101,9 @@ class EyerissModel(sequencer: GenFunc, monitor: CompareMonitor, p: EyerissModelP
88
101
) {0 }
89
102
private var parallelCycle = 0
90
103
/** the first dimension is NoC level index, value true means have read this from mem, false means haven't read*/
91
- private val weightMemReadRecord : Array [Boolean ] = Array .fill(p.G1 * p. M1 * p. C1 * p. S1 ) {false }
104
+ private val weightMemReadRecord : Array [Boolean ] = Array .fill(p.mappingInfo.weightNoCNum ) {false }
92
105
/** the first dimension is NoC level index, value true means have read this from mem, false means haven't read*/
93
- private val inActMemReadRecord : Array [Boolean ] = Array .fill(p.G1 * p. N1 * p. C1 * (p. F1 + p. S1 ) ) {false }
106
+ private val inActMemReadRecord : Array [Boolean ] = Array .fill(p.mappingInfo.inActNoCNum ) {false }
94
107
/** assume the data stored in Mem is pre-processed */
95
108
/** the first dimension is cgRow idx, the second is cgCol idx, the third is inActSRAMIdx, inside is a list */
96
109
private val inActAdrSRAM : Array [Array [Array [List [Int ]]]] =
@@ -324,9 +337,124 @@ class CommonModel(sequencer: GenFunc, monitor: CompareMonitor, p: EyerissModelPa
324
337
class ScalaModelTest extends FlatSpec {
325
338
behavior of " compare the efficiency of Eyeriss"
326
339
/** model the behavior of Eyeriss cluster group */
327
- /* it should "changing mapping parameters" in {
328
-
329
- }*/
340
+ it should " changing mapping parameters" in {
341
+ object peRow {
342
+ val start = 1
343
+ val end = 4
344
+ val during : Int = end - start
345
+ }
346
+ object peCol {
347
+ val start = 1
348
+ val end = 4
349
+ val during : Int = end - start
350
+ }
351
+ val monitorSeq = Seq .fill(peRow.during, peCol.during, 2 ) {new CompareMonitor }
352
+ /** the min size of inAct adr SPad and data SPad to meet the requirement.
353
+ * [[SPadSizeConfig ]].[[inActAdrSPadSize ]] and [[SPadSizeConfig ]].[[inActDataSPadSize ]]*/
354
+ val inActSPadSizeNeed : Array [Array [Array [Int ]]] = Array .fill(peRow.during, peCol.during, 2 ) {0 }
355
+ /** the min size of inAct adr SRAM and data SRAM to meet the requirement.
356
+ * [[ClusterSRAMConfig ]].[[inActAdrSRAMSize ]] and [[ClusterSRAMConfig ]].[[inActDataSRAMSize ]]*/
357
+ val inActSRAMSizeNeed : Array [Array [Array [Int ]]] = Array .fill(peRow.during, peCol.during, 2 ) {0 }
358
+ /** the min bits of inAct adr to meet the requirement. [[PESizeConfig ]].[[inActAdrWidth ]]*/
359
+ val inActAdrWidthNeed : Array [Array [Int ]] = Array .fill(peRow.during, peCol.during) {0 }
360
+ /** the min bits of inAct data to meet the requirement. [[PESizeConfig ]].[[inActDataWidth ]]*/
361
+ val inActDataWidthNeed : Array [Array [Int ]] = Array .fill(peRow.during, peCol.during) {0 }
362
+ /** the min size of weight adr SPad and data SPad to meet the requirement.
363
+ * [[SPadSizeConfig ]].[[weightAdrSPadSize ]] and [[SPadSizeConfig ]].[[weightDataSPadSize ]]*/
364
+ val weightSPadSizeNeed : Array [Array [Array [Int ]]] = Array .fill(peRow.during, peCol.during, 2 ) {0 }
365
+ /** the min bits of weight adr to meet the requirement. [[PESizeConfig ]].[[weightAdrWidth ]]*/
366
+ val weightAdrWidthNeed : Array [Array [Int ]] = Array .fill(peRow.during, peCol.during) {0 }
367
+ /** the min bits of weight data to meet the requirement. [[PESizeConfig ]].[[weightDataWidth ]]*/
368
+ val weightDataWidthNeed : Array [Array [Int ]] = Array .fill(peRow.during, peCol.during) {0 }
369
+ for (peRowFactor <- peRow.start until peRow.end) {
370
+ for (peColFactor <- peCol.start until peCol.end) {
371
+ val peRowIdx = peRowFactor - peRow.start
372
+ val peColIdx = peColFactor - peCol.start
373
+ val peRowNum = 3 * peRowFactor
374
+ val peColNum = 4 * peColFactor
375
+ var readTime = 2
376
+ while ((peRowNum + peColNum - 1 ) % readTime != 0 ) {
377
+ readTime += 1
378
+ }
379
+ val inActSRAMNum = (peRowNum + peColNum - 1 ) / readTime
380
+ val param = EyerissModelParam (peRow = peRowNum, peCol = peColNum,
381
+ S1 = peRowNum, F1 = peColNum, inActSRAMNum = inActSRAMNum)
382
+ val sequencer = new GenFunc (inActSparseRatio = 0.6 , weightSparseRatio = 0.6 , p = param)
383
+ val eyerissModel = new EyerissModel (sequencer = sequencer,
384
+ monitor = monitorSeq(peRowIdx)(peColIdx).head,
385
+ p = param, printDetails = false )
386
+ val common = new CommonModel (sequencer = sequencer,
387
+ monitor = monitorSeq(peRowIdx)(peColIdx)(1 ),
388
+ p = param, printDetails = false , needPSum = false )
389
+ inActSPadSizeNeed(peRowIdx)(peColIdx)(0 ) =
390
+ sequencer.dataSequencer.glb.separatedSPadCSCData.inActAdr.map(x => x.map(y => y.length).max).max
391
+ inActSPadSizeNeed(peRowIdx)(peColIdx)(1 ) =
392
+ sequencer.dataSequencer.glb.separatedSPadCSCData.inActData.map(x => x.map(y => y.length).max).max
393
+ inActSRAMSizeNeed(peRowIdx)(peColIdx)(0 ) =
394
+ sequencer.dataSequencer.glb.cscData.inActAdr.map(x => x.length).max
395
+ inActSRAMSizeNeed(peRowIdx)(peColIdx)(1 ) =
396
+ sequencer.dataSequencer.glb.cscData.inActData.map(x => x.length).max
397
+ inActAdrWidthNeed(peRowIdx)(peColIdx) =
398
+ log2Ceil(sequencer.dataSequencer.glb.cscData.inActAdr.flatten.filter(x => x != scala.math.pow(2 ,7 )- 1 ).max)
399
+ inActDataWidthNeed(peRowIdx)(peColIdx) =
400
+ log2Ceil(sequencer.dataSequencer.glb.cscData.inActData.flatten.filter(x => x != scala.math.pow(2 ,12 )- 1 ).max)
401
+ weightSPadSizeNeed(peRowIdx)(peColIdx)(0 ) =
402
+ sequencer.dataSequencer.glb.separatedSPadCSCData.weightAdr.map(x => x.map(y => y.length).max).max
403
+ weightSPadSizeNeed(peRowIdx)(peColIdx)(1 ) =
404
+ sequencer.dataSequencer.glb.separatedSPadCSCData.weightData.map(x => x.map(y => y.length).max).max
405
+ weightAdrWidthNeed(peRowIdx)(peColIdx) =
406
+ log2Ceil(sequencer.dataSequencer.glb.cscData.weightAdr.flatten.filter(x => x != scala.math.pow(2 ,7 )- 1 ).max)
407
+ weightDataWidthNeed(peRowIdx)(peColIdx) =
408
+ log2Ceil(sequencer.dataSequencer.glb.cscData.weightData.flatten.filter(x => x != scala.math.pow(2 ,12 )- 1 ).max)
409
+ println(s " [ ${MAGENTA }Info $RESET] current peRow = $peRowNum, peCol = $peColNum, inActSRAM = $inActSRAMNum" )
410
+ if (peRowFactor == peRow.end - 1 && peColFactor == peCol.end - 1 ) {
411
+ param.nnShape.printNNShapeInfo()
412
+ param.physicalInfo.printlnPhysicalInfo()
413
+ }
414
+ }
415
+ }
416
+ println(" |pRow\t |pCol\t |cycle%\t\t |mac%\t\t |iMem%\t\t |wMem%\t\t |iGLB%\t\t |iSPad%\t\t |" )
417
+ for (peRowFactor <- peRow.start until peRow.end) {
418
+ for (peColFactor <- peCol.start until peCol.end) {
419
+ val peRowIdx = peRowFactor - peRow.start
420
+ val peColIdx = peColFactor - peCol.start
421
+ val eyerissMonitor = monitorSeq(peRowIdx)(peColIdx).head
422
+ val commonMonitor = monitorSeq(peRowIdx)(peColIdx).last
423
+ val inActGLBWriteTotal = eyerissMonitor.inActWrite.adr.glb + eyerissMonitor.inActWrite.data.glb
424
+ val inActGLBReadTotal = eyerissMonitor.inActRead.adr.glb + eyerissMonitor.inActRead.data.glb
425
+ val inActSPadWriteTotal = eyerissMonitor.inActWrite.adr.sPad + eyerissMonitor.inActWrite.data.sPad
426
+ val inActSPadReadTotal = eyerissMonitor.inActRead.adr.sPad + eyerissMonitor.inActRead.data.sPad
427
+ /** inAct GLB R / GLB W */
428
+ val eyerissInActGLBRW = f " ${(inActGLBReadTotal.toFloat/ inActGLBWriteTotal.toFloat)* 100 }%.2f%% "
429
+ /** inAct SPad W / GLB R */
430
+ val eyerissInActSPadReuse = f " ${(inActSPadWriteTotal.toFloat/ inActGLBReadTotal.toFloat)* 100 }%.2f%% "
431
+ val cycleEfficiency = f " ${(eyerissMonitor.cycle.toFloat / commonMonitor.cycle.toFloat)* 100 }%.4f%% "
432
+ val macEfficiency = f " ${(eyerissMonitor.macNum.toFloat / commonMonitor.macNum.toFloat)* 100 }%.4f%% "
433
+ val inActMemReadEfficiency =
434
+ f " ${(eyerissMonitor.inActRead.mem.toFloat / commonMonitor.inActRead.mem.toFloat)* 100 }%.4f%% "
435
+ val weightMemReadEfficiency =
436
+ f " ${(eyerissMonitor.weightRead.mem.toFloat / commonMonitor.weightRead.mem.toFloat)* 100 }%.4f%% "
437
+ println(s " | ${peRowFactor* 3 }\t\t | ${peColFactor* 4 }\t\t | $cycleEfficiency\t | " +
438
+ s " $macEfficiency\t | $inActMemReadEfficiency\t | $weightMemReadEfficiency\t | " +
439
+ s " $eyerissInActGLBRW\t | $eyerissInActSPadReuse\t | " )
440
+ }
441
+ }
442
+ println(" \n |pRow\t |pCol\t |inActAdrSPad\t |inActDataSPad\t |weightAdrSPad\t |weightDataSPad\t |inActAdrSRAM\t |inActDataSRAM\t |" )
443
+ for (peRowFactor <- peRow.start until peRow.end) {
444
+ for (peColFactor <- peCol.start until peCol.end) {
445
+ val peRowIdx = peRowFactor - peRow.start
446
+ val peColIdx = peColFactor - peCol.start
447
+ println(s " | ${peRowFactor* 3 }\t\t | ${peColFactor* 4 }\t\t | " +
448
+ s " ${inActSPadSizeNeed(peRowIdx)(peColIdx)(0 )}\t ${inActAdrWidthNeed(peRowIdx)(peColIdx)}-bit \t | " +
449
+ s " ${inActSPadSizeNeed(peRowIdx)(peColIdx)(1 )}\t ${inActDataWidthNeed(peRowIdx)(peColIdx)}-bit \t | " +
450
+ s " ${weightSPadSizeNeed(peRowIdx)(peColIdx)(0 )}\t ${weightAdrWidthNeed(peRowIdx)(peColIdx)}-bit \t | " +
451
+ s " ${weightSPadSizeNeed(peRowIdx)(peColIdx)(1 )}\t ${weightDataWidthNeed(peRowIdx)(peColIdx)}-bit \t | " +
452
+ s " ${inActSRAMSizeNeed(peRowIdx)(peColIdx)(0 )}\t | " +
453
+ s " ${inActSRAMSizeNeed(peRowIdx)(peColIdx)(1 )}\t | "
454
+ )
455
+ }
456
+ }
457
+ }
330
458
331
459
it should " compare the info across sparse ratio between eyeriss and common device" in {
332
460
val param = EyerissModelParam ()
0 commit comments