You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/06/22 09:03:37 UTC

[GitHub] [tvm-vta] liangfu commented on a change in pull request #30: Chisel Pipelined GEMM

liangfu commented on a change in pull request #30:
URL: https://github.com/apache/tvm-vta/pull/30#discussion_r656005109



##########
File path: hardware/chisel/src/test/scala/unittest/TensorGemmTest.scala
##########
@@ -0,0 +1,742 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package unittest
+
+import chisel3._
+import chisel3.util._
+import chisel3.iotesters.PeekPokeTester
+import unittest.util._
+import vta.core._
+import vta.util.config._
+
+class TensorGemmTester(c: TensorGemmOrig) extends PeekPokeTester(c) {
+  poke(c.io.start, 0)
+  poke(c.io.dec.reset, 0)
+  poke(c.io.dec.uop_begin, 0)
+  poke(c.io.dec.uop_end, 1)
+  poke(c.io.dec.lp_0, 1)
+  poke(c.io.dec.lp_1, 1)
+  poke(c.io.dec.acc_0, 1)
+  poke(c.io.dec.acc_1, 1)
+  poke(c.io.dec.inp_0, 1)
+  poke(c.io.dec.inp_1, 1)
+  poke(c.io.dec.wgt_0, 1)
+  poke(c.io.dec.wgt_1, 1)
+  // Don't need empty_0, {push, pop}_{next, prev}, op
+
+  poke(c.io.uop.data.bits.u0, 0)
+  poke(c.io.uop.data.bits.u1, 0)
+  poke(c.io.uop.data.bits.u2, 0)
+
+  val inp = IndexedSeq.fill(c.io.inp.rd(0).data.bits(0).size){BigInt(1)}
+  for {lhs <- c.io.inp.rd(0).data.bits} {
+    poke(lhs, inp.reverse)
+  }
+
+  val wgt = IndexedSeq.fill(c.io.wgt.rd(0).data.bits(0).size){BigInt(1)}
+  for {lhs <- c.io.wgt.rd(0).data.bits} {
+    poke(lhs, wgt.reverse)
+  }
+
+  val acc = IndexedSeq.fill(c.io.acc.rd(0).data.bits(0).size){BigInt(1)}
+  for {lhs <- c.io.acc.rd(0).data.bits} {
+    poke(lhs, acc.reverse)
+  }
+
+  class TensorMasterMock(tm: TensorMaster) {
+    poke(tm.rd(0).data.valid, 0)
+    var valid = peek(tm.rd(0).idx.valid)
+
+    def logical_step(v: BigInt) {
+      poke(tm.rd(0).data.valid, valid)
+      valid = peek(tm.rd(0).idx.valid)
+      expect(tm.rd(0).idx.valid, v)
+    }
+  }
+
+  class UopMasterMock(um: UopMaster) {
+    poke(um.data.valid, 0)
+    var valid = peek(um.idx.valid)
+
+    def logical_step(v: BigInt) {
+      poke(um.data.valid, valid)
+      valid = peek(um.idx.valid)
+      expect(um.idx.valid, v)
+    }
+  }
+
+  class Mocks {
+    val uop_mock = new UopMasterMock(c.io.uop)
+    val inp_mock = new TensorMasterMock(c.io.inp)
+    val wgt_mock = new TensorMasterMock(c.io.wgt)
+    val acc_mock = new TensorMasterMock(c.io.acc)
+
+    def logical_step(sram_valid: BigInt, uop_valid: BigInt) {
+      step(1)
+      uop_mock.logical_step(uop_valid)
+      inp_mock.logical_step(sram_valid)
+      wgt_mock.logical_step(sram_valid)
+      acc_mock.logical_step(sram_valid)
+    }
+  }
+
+  val mocks = new Mocks
+  poke(c.io.start, 0)
+
+  step(1)
+
+  expect(c.io.state, c.sIdle)
+
+  poke(c.io.start, 1)
+  mocks.logical_step(0, 1)
+  expect(c.io.state, c.sReadUop)
+
+  expect(c.io.out.wr(0).valid, 0)
+  expect(c.io.acc.wr(0).valid, 0)
+
+  poke(c.io.start, 0)
+
+  mocks.logical_step(0, 0)
+  expect(c.io.state, c.sComputeIdx)
+  expect(c.io.out.wr(0).valid, 0)
+  expect(c.io.acc.wr(0).valid, 0)
+
+  mocks.logical_step(1, 0)
+  expect(c.io.state, c.sReadTensor)
+  expect(c.io.out.wr(0).valid, 0)
+  expect(c.io.acc.wr(0).valid, 0)
+
+  mocks.logical_step(0, 0)
+  expect(c.io.state, c.sExe)
+  expect(c.io.out.wr(0).valid, 0)
+  expect(c.io.acc.wr(0).valid, 0)
+  expect(c.io.done, 0)
+
+  mocks.logical_step(0, 0 /*1*/)

Review comment:
       remove unused comment

##########
File path: hardware/chisel/src/main/scala/core/TensorGemm.scala
##########
@@ -199,7 +322,7 @@ abstract class TensorGemmIfc(implicit p: Parameters) extends Module {
  * Also, the TensorGemm uses the reset field in the Gemm instruction to
  * clear or zero-out the acc-scratchpad locations based on the micro-ops.
  */
-class TensorGemm(debug: Boolean = false)(implicit p: Parameters) extends TensorGemmIfc {
+class TensorGemmOrig(debug: Boolean = false)(implicit p: Parameters) extends TensorGemmIfc {

Review comment:
       I think the `Orig` suffix could be better replace with something more meaningful, such as `Simple` or `Small`, indicating the the previous simple design consumes less logic elements, and it's easy to understand.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org