Skip to content

Commit

Permalink
[INFRASTRUCTURE] Migrate to json based config. Move gemm test to inte…
Browse files Browse the repository at this point in the history
…gration. (#28)

* Migrate to json based config. Move gemm test to integration.

* temp checkin

* checkin  example json
  • Loading branch information
tqchen committed Jul 12, 2018
1 parent 5481665 commit a24fadb
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 526 deletions.
57 changes: 13 additions & 44 deletions vta/Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,12 @@
ROOTDIR = $(CURDIR)

ifndef config
ifneq ("$(wildcard ./config.mk)", "")
config = config.mk
else
config = make/config.mk
endif
endif
include $(config)

export LDFLAGS = -pthread -lm
export CFLAGS = -std=c++11 -Wall -O2 -Iinclude -fPIC

ifdef NNVM_PATH
CFLAGS += -I$(NNVM_PATH)/include
else
NNVM_PATH = $(ROOTDIR)/nnvm
CFLAGS += -I$(NNVM_PATH)/include
endif

ifdef TVM_PATH
CFLAGS += -I$(TVM_PATH)/include -I$(TVM_PATH)/dlpack/include -I$(TVM_PATH)/HalideIR/src
else
TVM_PATH = $(NNVM_PATH)/tvm
CFLAGS += -I$(TVM_PATH)/include -I$(TVM_PATH)/dlpack/include -I$(TVM_PATH)/HalideIR/src
endif

ifdef DMLC_CORE_PATH
CFLAGS += -I$(DMLC_CORE_PATH)/include
else
CFLAGS += -I$(NNVM_PATH)/dmlc-core/include
endif

ifneq ($(ADD_CFLAGS), NONE)
CFLAGS += $(ADD_CFLAGS)
endif

ifneq ($(ADD_LDFLAGS), NONE)
LDFLAGS += $(ADD_LDFLAGS)
endif
VTA_CONFIG = python make/vta_config.py
CFLAGS += `${VTA_CONFIG} --cflags`
LDFLAGS += `${VTA_CONFIG} --ldflags`
VTA_TARGET := $(shell ${VTA_CONFIG} --target)

UNAME_S := $(shell uname -s)

Expand All @@ -53,29 +21,30 @@ else
NO_WHOLE_ARCH= --no-whole-archive
endif

VTA_LIB_SRC = $(wildcard src/*.cc src/tvm/*.cc)

ifeq ($(VTA_TARGET), pynq)
VTA_LIB_SRC = $(wildcard src/*.cc)

ifeq (${VTA_TARGET}, pynq)
VTA_LIB_SRC += $(wildcard src/pynq/*.cc)
LDFLAGS += -L/usr/lib -lsds_lib
LDFLAGS += -L/opt/python3.6/lib/python3.6/site-packages/pynq/drivers/
LDFLAGS += -L/opt/python3.6/lib/python3.6/site-packages/pynq/lib/
LDFLAGS += -l:libdma.so
endif

ifeq ($(VTA_TARGET), sim)
ifeq (${VTA_TARGET}, sim)
VTA_LIB_SRC += $(wildcard src/sim/*.cc)
endif

VTA_LIB_OBJ = $(patsubst src/%.cc, build/%.o, $(VTA_LIB_SRC))

all: lib/libvta.so
all: lib/libvta.so lib/libvta.so.json

build/%.o: src/%.cc
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CXX) -c $(CFLAGS) -c $< -o $@

lib/libvta.so.json: lib/libvta.so
@mkdir -p $(@D)
${VTA_CONFIG} --cfg-json > $@

lib/libvta.so: $(VTA_LIB_OBJ)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o, $^) $(LDFLAGS)
Expand Down
8 changes: 8 additions & 0 deletions vta/make/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# VTA Configuration

Each VTA runtime/hardware configuration is specified by config.json file.
You can copy the config.json to project root and modify the configuration
before you type make.

The config is going to affect the behavior of python package as well as
the hardware runtime build.
14 changes: 14 additions & 0 deletions vta/make/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"TARGET" : "pynq",
"LOG_INP_WIDTH" : 3,
"LOG_WGT_WIDTH" : 3,
"LOG_ACC_WIDTH" : 5,
"LOG_OUT_WIDTH" : 3,
"LOG_BATCH" : 0,
"LOG_BLOCK_IN" : 4,
"LOG_BLOCK_OUT" : 4,
"LOG_UOP_BUFF_SIZE" : 15,
"LOG_INP_BUFF_SIZE" : 15,
"LOG_WGT_BUFF_SIZE" : 15,
"LOG_ACC_BUFF_SIZE" : 17
}
99 changes: 0 additions & 99 deletions vta/make/config.mk

This file was deleted.

65 changes: 65 additions & 0 deletions vta/make/vta_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""VTA config tool"""
import os
import sys
import json
import argparse

def get_pkg_config(cfg):
"""Get the pkg config object."""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
proj_root = os.path.abspath(os.path.join(curr_path, "../"))
pkg_config_py = os.path.join(proj_root, "python/vta/pkg_config.py")
libpkg = {"__file__": pkg_config_py}
exec(compile(open(pkg_config_py, "rb").read(), pkg_config_py, "exec"), libpkg, libpkg)
PkgConfig = libpkg["PkgConfig"]
return PkgConfig(cfg, proj_root)


def main():
"""Main funciton"""
parser = argparse.ArgumentParser()
parser.add_argument("--cflags", action="store_true",
help="print the cflags")
parser.add_argument("--update", action="store_true",
help="Print out the json option.")
parser.add_argument("--ldflags", action="store_true",
help="print the cflags")
parser.add_argument("--cfg-json", action="store_true",
help="print all the config json")
parser.add_argument("--target", action="store_true",
help="print the target")
args = parser.parse_args()

if len(sys.argv) == 1:
parser.print_help()
return

curr_path = os.path.dirname(
os.path.abspath(os.path.expanduser(__file__)))
proj_root = os.path.abspath(os.path.join(curr_path, "../"))
path_list = [
os.path.join(proj_root, "config.json"),
os.path.join(proj_root, "make/config.json")
]
ok_path_list = [p for p in path_list if os.path.exists(p)]
if not ok_path_list:
raise RuntimeError("Cannot find config in %s" % str(path_list))
cfg = json.load(open(ok_path_list[0]))
cfg["LOG_OUT_WIDTH"] = cfg["LOG_INP_WIDTH"]
pkg = get_pkg_config(cfg)

if args.target:
print(pkg.target)

if args.cflags:
print(" ".join(pkg.cflags))

if args.ldflags:
print(" ".join(pkg.ldflags))

if args.cfg_json:
print(pkg.cfg_json)


if __name__ == "__main__":
main()
10 changes: 4 additions & 6 deletions vta/python/vta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""TVM-based VTA Compiler Toolchain"""
from __future__ import absolute_import as _abs
import sys


from .environment import get_env, Environment
from . import arm_conv2d, vta_conv2d
from .build_module import build_config, lower, build
from .rpc_client import reconfig_runtime, program_fpga

try:
# allow optional import in config mode.
from . import arm_conv2d, vta_conv2d
from .build_module import build_config, lower, build
from .rpc_client import reconfig_runtime, program_fpga

from . import graph
except (ImportError, RuntimeError):
pass
Loading

0 comments on commit a24fadb

Please sign in to comment.