From 49831c4f18cb3408e2114f34b935f3b184445a35 Mon Sep 17 00:00:00 2001 From: Liangfu Chen Date: Sat, 17 Aug 2019 18:34:30 +0800 Subject: [PATCH 1/2] [VTA][TSIM] parallel hardware compilation with macOS and debug support --- vta/hardware/chisel/Makefile | 45 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/vta/hardware/chisel/Makefile b/vta/hardware/chisel/Makefile index 6d89a811c255..e2f72d0d652e 100644 --- a/vta/hardware/chisel/Makefile +++ b/vta/hardware/chisel/Makefile @@ -39,6 +39,8 @@ BUILD_NAME = build USE_TRACE = 0 VTA_LIBNAME = libvta_hw UNITTEST_NAME = all +CXX = g++ +DEBUG = 0 config_test = $(TOP_TEST)$(CONFIG) vta_dir = $(abspath ../../) @@ -57,7 +59,11 @@ verilator_opt += --top-module ${TOP_TEST} verilator_opt += -Mdir ${verilator_build_dir} verilator_opt += -I$(chisel_build_dir) -cxx_flags = -O2 -Wall -fPIC -shared +ifeq ($(DEBUG), 0) + cxx_flags = -O2 -Wall +else + cxx_flags = -O0 -g -Wall +endif cxx_flags += -fvisibility=hidden -std=c++11 cxx_flags += -DVL_TSIM_NAME=V$(TOP_TEST) cxx_flags += -DVL_PRINTF=printf @@ -73,23 +79,26 @@ cxx_flags += -I$(vta_dir)/include cxx_flags += -I$(tvm_dir)/include cxx_flags += -I$(tvm_dir)/3rdparty/dlpack/include -cxx_files = $(VERILATOR_INC_DIR)/verilated.cpp -cxx_files += $(VERILATOR_INC_DIR)/verilated_dpi.cpp -cxx_files += $(wildcard $(verilator_build_dir)/*.cpp) -cxx_files += $(vta_dir)/hardware/dpi/tsim_device.cc +ld_flags = -fPIC -shared + +cxx_objs = $(verilator_build_dir)/verilated.o $(verilator_build_dir)/verilated_dpi.o $(verilator_build_dir)/tsim_device.o +cxx_objs += $(patsubst %.cpp,%.o,$(wildcard $(verilator_build_dir)/*.cpp)) ifneq ($(USE_TRACE), 0) verilator_opt += --trace cxx_flags += -DVM_TRACE=1 cxx_flags += -DTSIM_TRACE_FILE=$(verilator_build_dir)/$(TOP_TEST).vcd - cxx_files += $(VERILATOR_INC_DIR)/verilated_vcd_c.cpp + cxx_objs += $(verilator_build_dir)/verilated_vcd_c.o else cxx_flags += -DVM_TRACE=0 endif +VPATH = $(VERILATOR_INC_DIR):$(verilator_build_dir):$(vta_dir)/hardware/dpi + # The following is to be consistent with cmake ifeq ($(shell uname), Darwin) lib_path = $(vta_dir)/$(BUILD_NAME)/$(VTA_LIBNAME).dylib + cxx_flags += -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk else lib_path = $(vta_dir)/$(BUILD_NAME)/$(VTA_LIBNAME).so endif @@ -97,8 +106,24 @@ endif default: lib lib: $(lib_path) -$(lib_path): $(verilator_build_dir)/V$(TOP_TEST).cpp - g++ $(cxx_flags) $(cxx_files) -o $@ + +$(verilator_build_dir)/%.o: $(verilator_build_dir)/%.cpp + $(CXX) -c $(cxx_flags) $^ -o $@ + +$(verilator_build_dir)/verilated.o: verilated.cpp + $(CXX) -c $(cxx_flags) $^ -o $@ + +$(verilator_build_dir)/verilated_dpi.o: verilated_dpi.cpp + $(CXX) -c $(cxx_flags) $^ -o $@ + +$(verilator_build_dir)/verilated_vcd_c.o: verilated_vcd_c.cpp + $(CXX) -c $(cxx_flags) $^ -o $@ + +$(verilator_build_dir)/tsim_device.o: tsim_device.cc + $(CXX) -c $(cxx_flags) $^ -o $@ + +$(lib_path): $(verilator_build_dir)/V$(TOP_TEST).cpp $(cxx_objs) + $(CXX) $(cxx_flags) $(ld_flags) $(cxx_objs) -o $@ verilator: $(verilator_build_dir)/V$(TOP_TEST).cpp $(verilator_build_dir)/V$(TOP_TEST).cpp: $(chisel_build_dir)/$(TOP_TEST).$(CONFIG).v @@ -119,4 +144,6 @@ clean: -rm -rf target project/target project/project test_run_dir cleanall: - -rm -rf $(vta_dir)/$(BUILD_NAME) + -rm -rf $(vta_dir)/$(BUILD_NAME)/chisel + -rm -rf $(vta_dir)/$(BUILD_NAME)/libvta_hw.so + -rm -rf $(vta_dir)/$(BUILD_NAME)/verilator From c03b188993c1e5c43c20fd8674a4934c61dad818 Mon Sep 17 00:00:00 2001 From: Liangfu Chen Date: Sun, 18 Aug 2019 17:20:13 +0800 Subject: [PATCH 2/2] simplify --- vta/hardware/chisel/Makefile | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/vta/hardware/chisel/Makefile b/vta/hardware/chisel/Makefile index e2f72d0d652e..8da90f2d72d9 100644 --- a/vta/hardware/chisel/Makefile +++ b/vta/hardware/chisel/Makefile @@ -107,16 +107,7 @@ default: lib lib: $(lib_path) -$(verilator_build_dir)/%.o: $(verilator_build_dir)/%.cpp - $(CXX) -c $(cxx_flags) $^ -o $@ - -$(verilator_build_dir)/verilated.o: verilated.cpp - $(CXX) -c $(cxx_flags) $^ -o $@ - -$(verilator_build_dir)/verilated_dpi.o: verilated_dpi.cpp - $(CXX) -c $(cxx_flags) $^ -o $@ - -$(verilator_build_dir)/verilated_vcd_c.o: verilated_vcd_c.cpp +$(verilator_build_dir)/%.o: %.cpp $(CXX) -c $(cxx_flags) $^ -o $@ $(verilator_build_dir)/tsim_device.o: tsim_device.cc