Skip to content

Commit 6e0dbee

Browse files
BenjaminTutmoreau89
authored andcommitted
[VTA][TSIM] Serial GEMM Application Added (apache#4082)
* app init push * fix on readme * change name, add bit serial explanantion * rm serialLoadMM, change doc * syntax change for readme * add parallel test functionality * fix readme * add python doc * syntax
1 parent 94354d6 commit 6e0dbee

File tree

15 files changed

+1237
-0
lines changed

15 files changed

+1237
-0
lines changed

apps/gemm/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
cmake_minimum_required(VERSION 3.2)
19+
project(tsim C CXX)
20+
21+
set(TVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../)
22+
set(VTA_DIR ${TVM_DIR}/vta)
23+
24+
include_directories("${TVM_DIR}/include")
25+
include_directories("${TVM_DIR}/3rdparty/dlpack/include")
26+
include_directories("${TVM_DIR}/3rdparty/dmlc-core/include")
27+
include_directories("${TVM_DIR}/vta/src/dpi")
28+
29+
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden")
30+
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11")
31+
32+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
33+
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
34+
set(CMAKE_CXX_FLAGS "-faligned-new ${CMAKE_CXX_FLAGS}")
35+
endif()
36+
37+
file(GLOB TSIM_SW_SRC src/driver.cc)
38+
list(APPEND TSIM_SW_SRC ${VTA_DIR}/src/vmem/virtual_memory.cc)
39+
list(APPEND TSIM_SW_SRC ${VTA_DIR}/src/dpi/module.cc)
40+
41+
add_library(sw SHARED ${TSIM_SW_SRC})
42+
target_include_directories(sw PRIVATE ${VTA_DIR}/include ${VTA_DIR}/src)
43+
44+
if(APPLE)
45+
set_target_properties(sw PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
46+
endif(APPLE)

apps/gemm/Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
export PYTHONPATH:=$(PWD)/python:$(PYTHONPATH)
19+
20+
BUILD_NAME = build
21+
build_dir = $(abspath .)/$(BUILD_NAME)
22+
23+
default: chisel driver
24+
python3 tests/python/chisel_accel.py serial
25+
26+
serial:
27+
python3 tests/python/chisel_accel.py serial
28+
29+
parallel:
30+
python3 tests/python/chisel_accel.py parallel
31+
32+
driver: | $(build_dir)
33+
cd $(build_dir) && cmake .. && make
34+
35+
$(build_dir):
36+
mkdir -p $@
37+
38+
chisel:
39+
make -C hardware/chisel
40+
41+
clean:
42+
-rm -rf $(build_dir)
43+
make -C hardware/chisel clean

apps/gemm/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
2+
<!--- or more contributor license agreements. See the NOTICE file -->
3+
<!--- distributed with this work for additional information -->
4+
<!--- regarding copyright ownership. The ASF licenses this file -->
5+
<!--- to you under the Apache License, Version 2.0 (the -->
6+
<!--- "License"); you may not use this file except in compliance -->
7+
<!--- with the License. You may obtain a copy of the License at -->
8+
9+
<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
10+
11+
<!--- Unless required by applicable law or agreed to in writing, -->
12+
<!--- software distributed under the License is distributed on an -->
13+
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
14+
<!--- KIND, either express or implied. See the License for the -->
15+
<!--- specific language governing permissions and limitations -->
16+
<!--- under the License. -->
17+
18+
VTA TSIM Application
19+
======================
20+
Prior to this application, please take a look at `<tvm-root>/vta/apps/tsim_example` for installation
21+
This is an application that performs Bit Serial Multiplication for GEMM utilizing TSIM.
22+
23+
**Bit Serial Multiplication for GEMM:**
24+
25+
General Matrix Multiplications (GEMM), are mostly calculated by repeatly calculating the dot product for each pair of vectors.
26+
The dot product is calculated by summing every product of the vector pair.
27+
We approach this operation with slicing and shifting, like how basic multiplication works, each vector elements before we accumulate them.
28+
We can sufficiently reduce the cycles required to perform a gemm given that the data bit width is small. This GEMM application uses TSIM for future accerlerator prototypes.
29+
30+
* Test Chisel3 backend with bit serial GEMM
31+
* Go to `<tvm-root>/vta/apps/gemm`
32+
* Run `make`
33+
34+
* If you have already compiled chisel backend (i.e. ran `make`)
35+
* Bit Serial test with another input set, run `make serial`
36+
* Bit parallel test with another input set, run `make parallel`
37+
38+
* Some steps for creating your own custom TSIM application
39+
* Go to `<tvm-root>/vta/apps/gemm`
40+
* Create custom circuit within `./hardware/chisel/src/scala.main/accel/Compute.scala`
41+
* Map the according Registers in `./hardware/chisel/src/scala.main/accel/RegFile.scala`
42+
* Create your test script
43+
* Map the registers in `./src/driver.cc` and link it with both `RegFile.scala` and the test script
44+
* Understanding of `<tvm-root>/vta/apps/tsim_example`, which performs add by one to a vector, is highly encouraged to create a more complex application
45+
46+
* Some pointers
47+
* Chisel3 tests in `<tvm-root>/vta/apps/gemm/tests/python`
48+
* Chisel3 accelerator backend `<tvm-root>/vta/apps/gemm/hardware/chisel`
49+
* Software C++ driver (backend) that handles the accelerator `<tvm-root>/vta/apps/gemm/src/driver.cc`
50+
* Software Python driver (frontend) that handles the accelerator `<tvm-root>/vta/apps/gemm/python/accel`

apps/gemm/hardware/chisel/Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
ifeq (, $(shell which verilator))
19+
$(error "No Verilator in $(PATH), consider doing apt-get install verilator")
20+
endif
21+
22+
# Change VERILATOR_INC_DIR if Verilator is installed on a different location
23+
ifeq (, $(VERILATOR_INC_DIR))
24+
ifeq (, $(wildcard /usr/local/share/verilator/include/*))
25+
ifeq (, $(wildcard /usr/share/verilator/include/*))
26+
$(error "Verilator include directory is not set properly")
27+
else
28+
VERILATOR_INC_DIR := /usr/share/verilator/include
29+
endif
30+
else
31+
VERILATOR_INC_DIR := /usr/local/share/verilator/include
32+
endif
33+
endif
34+
35+
TOP = TestAccel
36+
BUILD_NAME = build
37+
USE_TRACE = 1
38+
LIBNAME = libhw
39+
40+
vta_dir = $(abspath ../../../../)
41+
tvm_dir = $(abspath ../../../../../)
42+
build_dir = $(abspath .)/$(BUILD_NAME)
43+
verilator_build_dir = $(build_dir)/verilator
44+
chisel_build_dir = $(build_dir)/chisel
45+
46+
verilator_opt = --cc
47+
verilator_opt += +define+RANDOMIZE_GARBAGE_ASSIGN
48+
verilator_opt += +define+RANDOMIZE_REG_INIT
49+
verilator_opt += +define+RANDOMIZE_MEM_INIT
50+
verilator_opt += --x-assign unique
51+
verilator_opt += --output-split 20000
52+
verilator_opt += --output-split-cfuncs 20000
53+
verilator_opt += --top-module ${TOP}
54+
verilator_opt += -Mdir ${verilator_build_dir}
55+
verilator_opt += -I$(chisel_build_dir)
56+
57+
cxx_flags = -O2 -Wall -fPIC -shared
58+
cxx_flags += -fvisibility=hidden -std=c++11
59+
cxx_flags += -DVL_TSIM_NAME=V$(TOP)
60+
cxx_flags += -DVL_PRINTF=printf
61+
cxx_flags += -DVL_USER_FINISH
62+
cxx_flags += -DVM_COVERAGE=0
63+
cxx_flags += -DVM_SC=0
64+
cxx_flags += -Wno-sign-compare
65+
cxx_flags += -include V$(TOP).h
66+
cxx_flags += -I$(verilator_build_dir)
67+
cxx_flags += -I$(VERILATOR_INC_DIR)
68+
cxx_flags += -I$(VERILATOR_INC_DIR)/vltstd
69+
cxx_flags += -I$(vta_dir)/include
70+
cxx_flags += -I$(tvm_dir)/include
71+
cxx_flags += -I$(tvm_dir)/3rdparty/dlpack/include
72+
73+
cxx_files = $(VERILATOR_INC_DIR)/verilated.cpp
74+
cxx_files += $(VERILATOR_INC_DIR)/verilated_dpi.cpp
75+
cxx_files += $(wildcard $(verilator_build_dir)/*.cpp)
76+
cxx_files += $(vta_dir)/hardware/dpi/tsim_device.cc
77+
78+
ifneq ($(USE_TRACE), 0)
79+
verilator_opt += --trace
80+
cxx_flags += -DVM_TRACE=1
81+
cxx_flags += -DTSIM_TRACE_FILE=$(verilator_build_dir)/$(TOP).vcd
82+
cxx_files += $(VERILATOR_INC_DIR)/verilated_vcd_c.cpp
83+
else
84+
cxx_flags += -DVM_TRACE=0
85+
endif
86+
87+
# The following is to be consistent with cmake
88+
ifeq ($(shell uname), Darwin)
89+
lib_path = $(build_dir)/$(LIBNAME).dylib
90+
else
91+
lib_path = $(build_dir)/$(LIBNAME).so
92+
endif
93+
94+
default: lib
95+
96+
lib: $(lib_path)
97+
$(lib_path): $(verilator_build_dir)/V$(TOP).cpp
98+
g++ $(cxx_flags) $(cxx_files) -o $@
99+
100+
verilator: $(verilator_build_dir)/V$(TOP).cpp
101+
$(verilator_build_dir)/V$(TOP).cpp: $(chisel_build_dir)/$(TOP).v
102+
verilator $(verilator_opt) $<
103+
104+
verilog: $(chisel_build_dir)/$(TOP).v
105+
$(chisel_build_dir)/$(TOP).v: install_vta_package
106+
sbt 'test:runMain test.Elaborate --target-dir $(chisel_build_dir) --top-name $(TOP)'
107+
108+
install_vta_package:
109+
cd $(vta_dir)/hardware/chisel && sbt publishLocal
110+
111+
clean:
112+
-rm -rf $(build_dir) target project/target project/project
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
name := "accel"
21+
version := "0.1.0-SNAPSHOT"
22+
organization := "edu.washington.cs"
23+
24+
def scalacOptionsVersion(scalaVersion: String): Seq[String] = {
25+
Seq() ++ {
26+
// If we're building with Scala > 2.11, enable the compile option
27+
// switch to support our anonymous Bundle definitions:
28+
// https://github.com/scala/bug/issues/10047
29+
CrossVersion.partialVersion(scalaVersion) match {
30+
case Some((2, scalaMajor: Long)) if scalaMajor < 12 => Seq()
31+
case _ => Seq(
32+
"-Xsource:2.11",
33+
"-language:reflectiveCalls",
34+
"-language:implicitConversions",
35+
"-deprecation",
36+
"-Xlint",
37+
"-Ywarn-unused",
38+
)
39+
}
40+
}
41+
}
42+
43+
def javacOptionsVersion(scalaVersion: String): Seq[String] = {
44+
Seq() ++ {
45+
// Scala 2.12 requires Java 8. We continue to generate
46+
// Java 7 compatible code for Scala 2.11
47+
// for compatibility with old clients.
48+
CrossVersion.partialVersion(scalaVersion) match {
49+
case Some((2, scalaMajor: Long)) if scalaMajor < 12 =>
50+
Seq("-source", "1.7", "-target", "1.7")
51+
case _ =>
52+
Seq("-source", "1.8", "-target", "1.8")
53+
}
54+
}
55+
}
56+
57+
scalaVersion := "2.11.12"
58+
59+
resolvers ++= Seq(
60+
Resolver.sonatypeRepo("snapshots"),
61+
Resolver.sonatypeRepo("releases"))
62+
63+
libraryDependencies ++= Seq(
64+
"edu.berkeley.cs" %% "chisel3" % "3.1.7",
65+
"edu.washington.cs" %% "vta" % "0.1.0-SNAPSHOT",
66+
)
67+
68+
scalacOptions ++= scalacOptionsVersion(scalaVersion.value)
69+
javacOptions ++= javacOptionsVersion(scalaVersion.value)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
sbt.version = 1.1.1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
logLevel := Level.Warn

0 commit comments

Comments
 (0)