Skip to content

Commit 59f6eef

Browse files
committed
[DRIVER] Add simulator, unify testcase to unittest (apache#25)
1 parent 374be00 commit 59f6eef

File tree

19 files changed

+1217
-541
lines changed

19 files changed

+1217
-541
lines changed

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ ifneq ($(ADD_LDFLAGS), NONE)
4040
LDFLAGS += $(ADD_LDFLAGS)
4141
endif
4242

43+
UNAME_S := $(shell uname -s)
44+
45+
ifeq ($(UNAME_S), Darwin)
46+
SHARED_LIBRARY_SUFFIX := dylib
47+
WHOLE_ARCH= -all_load
48+
NO_WHOLE_ARCH= -noall_load
49+
LDFLAGS += -undefined dynamic_lookup
50+
else
51+
SHARED_LIBRARY_SUFFIX := so
52+
WHOLE_ARCH= --whole-archive
53+
NO_WHOLE_ARCH= --no-whole-archive
54+
endif
55+
4356

4457
all: lib/libvta.so lib/libvta_runtime.so
4558

@@ -53,6 +66,10 @@ ifeq ($(TARGET), VTA_PYNQ_TARGET)
5366
LDFLAGS += -l:libdma.so
5467
endif
5568

69+
ifeq ($(TARGET), sim)
70+
VTA_LIB_SRC += $(wildcard src/sim/*.cc)
71+
endif
72+
5673
VTA_LIB_OBJ = $(patsubst src/%.cc, build/%.o, $(VTA_LIB_SRC))
5774

5875
build/%.o: src/%.cc
@@ -71,7 +88,7 @@ lib/libvta_runtime.so: build/runtime.o
7188
lint: pylint cpplint
7289

7390
cpplint:
74-
python nnvm/dmlc-core/scripts/lint.py vta cpp include src hardware tests
91+
python nnvm/dmlc-core/scripts/lint.py vta cpp include src
7592

7693
pylint:
7794
pylint python/vta --rcfile=$(ROOTDIR)/tests/lint/pylintrc
@@ -86,3 +103,4 @@ clean:
86103
-include build/*.d
87104
-include build/*/*.d
88105
-include build/*/*/*.d
106+
-include build/*/*/*/*.d

include/vta/driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void VTAMemFree(void* buf);
7777
* \param buf Pointer to memory region allocated with VTAMemAlloc.
7878
* \return The physical address of the memory region.
7979
*/
80-
vta_phy_addr_t VTAGetMemPhysAddr(void* buf);
80+
vta_phy_addr_t VTAMemGetPhyAddr(void* buf);
8181

8282
/*!
8383
* \brief Flushes the region of memory out of the CPU cache to DRAM.

include/vta/hw_spec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ typedef struct {
519519
uint64_t alu_opcode : VTA_ALU_OPCODE_BIT_WIDTH;
520520
/*! \brief Use immediate is true */
521521
uint64_t use_imm : 1;
522-
/*! \brief Immediate value */
523-
uint64_t imm : VTA_ALUOP_IMM_BIT_WIDTH;
522+
/*! \brief Immediate value: allow negative value */
523+
int64_t imm : VTA_ALUOP_IMM_BIT_WIDTH;
524524
} VTAAluInsn;
525525

526526
/*! \brief VTA ALU instruction converter */

include/vta/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void VTAUopPush(uint32_t mode,
196196
uint32_t wgt_index,
197197
uint32_t opcode,
198198
uint32_t use_imm,
199-
uint32_t imm_val);
199+
int32_t imm_val);
200200

201201
/*!
202202
* \brief Mark start of a micro op loop.

make/config.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ADD_LDFLAGS=
2727
ADD_CFLAGS=
2828

2929
# the hardware target
30-
TARGET = VTA_PYNQ_TARGET
30+
TARGET = pynq
3131

3232
#---------------------
3333
# VTA hardware parameters
@@ -89,7 +89,6 @@ VTA_OUT_BUFF_SIZE = $(shell echo "$$(( 1 << $(VTA_LOG_OUT_BUFF_SIZE) ))" )
8989

9090
# Update ADD_CFLAGS
9191
ADD_CFLAGS += \
92-
-D$(TARGET) \
9392
-DVTA_LOG_WGT_WIDTH=$(VTA_LOG_WGT_WIDTH) -DVTA_LOG_INP_WIDTH=$(VTA_LOG_INP_WIDTH) \
9493
-DVTA_LOG_ACC_WIDTH=$(VTA_LOG_ACC_WIDTH) -DVTA_LOG_OUT_WIDTH=$(VTA_LOG_OUT_WIDTH) \
9594
-DVTA_LOG_BATCH=$(VTA_LOG_BATCH) \

python/vta/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from . import arm_conv2d, vta_conv2d
99
from .build_module import build_config, lower, build
1010
from .rpc_client import reconfig_runtime, program_fpga
11+
1112
from . import graph
1213
except ImportError:
1314
pass

python/vta/environment.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Environment(object):
8989
"""
9090
current = None
9191
cfg_keys = [
92-
"target",
92+
"TARGET",
9393
"LOG_INP_WIDTH",
9494
"LOG_WGT_WIDTH",
9595
"LOG_ACC_WIDTH",
@@ -204,9 +204,19 @@ def gemm(self):
204204

205205
@property
206206
def gevm(self):
207-
"""GEMM intrinsic"""
207+
"""GEVM intrinsic"""
208208
return self.dev.gevm
209209

210+
@property
211+
def target_host(self):
212+
"""The target host"""
213+
if self.TARGET == "pynq":
214+
return "llvm -target=armv7-none-linux-gnueabihf"
215+
elif self.TARGET == "sim":
216+
return "llvm"
217+
else:
218+
raise ValueError("Unknown target %s" % self.TARGET)
219+
210220

211221
def get_env():
212222
"""Get the current VTA Environment.
@@ -278,6 +288,7 @@ def _init_env():
278288

279289
for k in Environment.cfg_keys:
280290
keys.add("VTA_" + k)
291+
keys.add("TARGET")
281292

282293
if not os.path.isfile(filename):
283294
raise RuntimeError(
@@ -290,8 +301,11 @@ def _init_env():
290301
for k in keys:
291302
if k +" =" in line:
292303
val = line.split("=")[1].strip()
293-
cfg[k[4:]] = int(val)
294-
cfg["target"] = "pynq"
304+
if k.startswith("VTA_"):
305+
k = k[4:]
306+
cfg[k] = int(val)
307+
else:
308+
cfg[k] = val
295309
return Environment(cfg)
296310

297311
Environment.current = _init_env()

python/vta/ir_pass.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def _visit(op):
7878
if not fail[0]:
7979
begin = tvm.call_extern(
8080
"int32", "VTAUopLoopBegin", stmt.extent, *gemm_offsets)
81-
end = tvm.call_extern(
82-
"int32", "VTAUopLoopEnd", stmt.extent, *gemm_offsets)
81+
end = tvm.call_extern("int32", "VTAUopLoopEnd")
8382
return [begin, ret, end]
8483
raise ValueError("Failed to fold the GEMM instructions..")
8584

@@ -683,8 +682,14 @@ def _flatten_loop(src_coeff, dst_coeff, extents):
683682
else:
684683
raise RuntimeError(
685684
"Function call not recognized %s" % (loop_body.value.name))
685+
elif isinstance(loop_body.value, tvm.expr.Load):
686+
alu_opcode = env.dev.ALU_OPCODE_SHR
687+
lhs = loop_body.value
688+
rhs = tvm.const(0)
686689
else:
687-
raise RuntimeError("Expression not recognized %s" % (type(loop_body.value)))
690+
raise RuntimeError(
691+
"Expression not recognized %s, %s, %s" % (
692+
type(loop_body.value), str(loop_body.value), str(stmt)))
688693

689694
# Derive array index coefficients
690695
dst_coeff = tvm.arith.DetectLinearEquation(dst_idx, indices)
@@ -772,7 +777,9 @@ def _flatten_loop(src_coeff, dst_coeff, extents):
772777
irb = tvm.ir_builder.create()
773778
for idx, extent in enumerate(extents):
774779
irb.emit(tvm.call_extern(
775-
"int32", "VTAUopLoopBegin", extent, dst_coeff[idx], src_coeff[idx]))
780+
"int32", "VTAUopLoopBegin",
781+
extent, dst_coeff[idx], src_coeff[idx], 0))
782+
use_imm = int(use_imm)
776783
irb.emit(tvm.call_extern(
777784
"int32", "VTAUopPush",
778785
1, 0,
@@ -804,5 +811,6 @@ def debug_print(stmt):
804811
stmt : Stmt
805812
The
806813
"""
814+
# pylint: disable=superfluous-parens
807815
print(stmt)
808816
return stmt

python/vta/rpc_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def reconfig_runtime(remote):
2424
"VTA_LOG_WGT_BUFF_SIZE",
2525
"VTA_LOG_ACC_BUFF_SIZE",
2626
"VTA_LOG_OUT_BUFF_SIZE"]
27-
28-
cflags = ["-DVTA_%s_TARGET" % env.target.upper()]
27+
cflags = []
2928
for k in keys:
3029
cflags += ["-D%s=%s" % (k, str(getattr(env, k[4:])))]
3130
freconfig = remote.get_function("tvm.contrib.vta.reconfig_runtime")

python/vta/testing/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Testing utilities, this namespace is not imported by default."""
2+
3+
from . util import run

0 commit comments

Comments
 (0)