Skip to content

Commit 2c0fa90

Browse files
authored
Merge pull request #43 from tensil-ai/peter/sc-443/test-sampling-in-simulation
2 parents 6b795cc + a66f64b commit 2c0fa90

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

rtl/src/test/scala/tensil/zynq/tcu/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package object tcu {
1414
def setClocks(): Unit = {
1515
m.instruction.setSourceClock(m.clock)
1616
m.status.setSinkClock(m.clock)
17+
m.sample.setSinkClock(m.clock)
1718
m.dram0.writeAddress.setSinkClock(m.clock)
1819
m.dram0.writeData.setSinkClock(m.clock)
1920
m.dram0.writeResponse.setSourceClock(m.clock)

sim/test/src/zynq/tcu/AXIWrapperTCUSpec.scala

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ import tensil.tools.compiler.MemoryAddressHelper
3030
import tensil.{InstructionLayout}
3131

3232
import tensil.axi
33-
import tensil.tcu.LocalDataFlowControl
33+
import tensil.tcu.{LocalDataFlowControl, TCUOptions}
3434
import tensil.tcu.instruction.{
3535
Opcode,
3636
Instruction,
3737
DataMoveFlags,
3838
DataMoveArgs,
39-
DataMoveKind
39+
DataMoveKind,
40+
ConfigureArgs,
41+
Configure
4042
}
4143
import tensil.mem.MemKind
4244
import tensil.tools.{Util, ResNet}
@@ -497,6 +499,87 @@ class AXIWrapperTCUSpec extends FunUnitSpec {
497499
}
498500
}
499501

502+
def sample(
503+
programSize: Int,
504+
interval: Int,
505+
blockSize: Int
506+
) =
507+
it(
508+
s"should sample with size=$programSize, interval=$interval, blockSize=$blockSize",
509+
Slow
510+
) {
511+
test(
512+
new AXIWrapperTCU(
513+
gen,
514+
layout,
515+
AXIWrapperTCUOptions(
516+
inner = TCUOptions(sampleBlockSize = blockSize),
517+
dramAxiConfig = axiConfig
518+
)
519+
)
520+
).withAnnotations(Seq(VerilatorBackendAnnotation)) { m =>
521+
m.setClocks()
522+
m.clock.setTimeout(Int.MaxValue)
523+
524+
implicit val layout: InstructionLayout =
525+
m.setInstructionParameters()
526+
527+
val cycleCount = 3 * programSize
528+
529+
// drams to listen
530+
fork {
531+
dram0.listen(m.clock, m.dram0)
532+
}
533+
fork {
534+
dram1.listen(m.clock, m.dram1)
535+
}
536+
val t0 = fork {
537+
m.sample.ready.poke(true.B)
538+
539+
val samples = (0 until cycleCount / interval).map({
540+
case 0 => (1, false)
541+
case x =>
542+
(
543+
Math.min(x * interval - 1, 1000),
544+
(x + 1) % blockSize == 0
545+
)
546+
})
547+
548+
for ((programCounter, last) <- samples) {
549+
m.sample.waitForValid()
550+
m.sample.bits.bits.programCounter.expect(programCounter.U)
551+
m.sample.bits.last.expect(last.B)
552+
553+
m.clock.step()
554+
}
555+
}
556+
val t1 = fork {
557+
var pc = 0
558+
559+
m.instruction.enqueue(
560+
Instruction(
561+
Opcode.Configure,
562+
ConfigureArgs(Configure.sampleInterval, interval)
563+
)
564+
)
565+
566+
m.instruction.enqueue(
567+
Instruction(
568+
Opcode.Configure,
569+
ConfigureArgs(Configure.programCounter, 0)
570+
)
571+
)
572+
573+
for (_ <- 0 until programSize) {
574+
m.instruction.enqueue(Instruction(Opcode.NoOp))
575+
}
576+
}
577+
578+
t0.join()
579+
t1.join()
580+
}
581+
}
582+
500583
val dataMoveSizes =
501584
(1 to 7)
502585
.map(Math.pow(2, _).toInt)
@@ -505,14 +588,16 @@ class AXIWrapperTCUSpec extends FunUnitSpec {
505588
.distinct
506589
.filter(_ <= arch.accumulatorDepth)
507590

508-
val tests = Seq(
509-
() => xor4(batchSize = 1),
510-
() => xor4(batchSize = 2),
511-
() => xor4(batchSize = 4),
512-
() => resnet(batchSize = 1, inputSize = 1),
513-
() => resnet(batchSize = 10, inputSize = 10),
514-
) ++ dataMoveSizes.map(size => () => dataMove(size, 4, true)) ++
515-
dataMoveSizes.map(size => () => dataMove(size, 4, false))
591+
val tests =
592+
Seq(
593+
() => sample(programSize = 1000, interval = 10, blockSize = 16),
594+
() => xor4(batchSize = 1),
595+
() => xor4(batchSize = 2),
596+
() => xor4(batchSize = 4),
597+
() => resnet(batchSize = 1, inputSize = 1),
598+
() => resnet(batchSize = 10, inputSize = 10),
599+
) ++ dataMoveSizes.map(size => () => dataMove(size, 4, true)) ++
600+
dataMoveSizes.map(size => () => dataMove(size, 4, false))
516601

517602
for (t <- tests) {
518603
if (randomizeDrams) {

0 commit comments

Comments
 (0)