2017-03-12 21:34:04 +03:00
|
|
|
ROOTDIR = $(CURDIR)
|
|
|
|
|
2017-01-18 01:07:38 +03:00
|
|
|
ifndef config
|
|
|
|
ifneq ("$(wildcard ./config.mk)","")
|
2017-02-22 21:47:54 +03:00
|
|
|
config ?= config.mk
|
2017-01-18 01:07:38 +03:00
|
|
|
else
|
2017-02-22 21:47:54 +03:00
|
|
|
config ?= make/config.mk
|
2017-01-18 01:07:38 +03:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
include $(config)
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2017-07-11 04:23:47 +03:00
|
|
|
.PHONY: clean all test doc pylint cpplint lint verilog cython cython2 cython3 web runtime
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2017-05-31 07:17:52 +03:00
|
|
|
BUILD_TARGETS ?= lib/libtvm.so lib/libtvm_runtime.so
|
2017-05-25 05:06:32 +03:00
|
|
|
all: ${BUILD_TARGETS}
|
2017-06-17 00:15:00 +03:00
|
|
|
runtime: lib/libtvm_runtime.so
|
2017-07-11 04:23:47 +03:00
|
|
|
web: lib/libtvm_web_runtime.js lib/libtvm_web_runtime.bc
|
2016-10-26 21:32:43 +03:00
|
|
|
|
2017-06-01 03:20:31 +03:00
|
|
|
ifndef DMLC_CORE_PATH
|
|
|
|
DMLC_CORE_PATH = $(ROOTDIR)/dmlc-core
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef DLPACK_PATH
|
|
|
|
DLPACK_PATH = $(ROOTDIR)/dlpack
|
|
|
|
endif
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
# The source code dependencies
|
|
|
|
LIB_HALIDEIR = HalideIR/lib/libHalideIR.a
|
2016-10-26 21:32:43 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
CC_SRC = $(filter-out src/contrib/%.cc src/runtime/%.cc,\
|
|
|
|
$(wildcard src/*/*.cc src/*/*/*.cc))
|
2017-05-02 20:14:45 +03:00
|
|
|
METAL_SRC = $(wildcard src/runtime/metal/*.mm)
|
2017-05-20 19:05:12 +03:00
|
|
|
CUDA_SRC = $(wildcard src/runtime/cuda/*.cc)
|
|
|
|
OPENCL_SRC = $(wildcard src/runtime/opencl/*.cc)
|
|
|
|
RPC_SRC = $(wildcard src/runtime/rpc/*.cc)
|
|
|
|
RUNTIME_SRC = $(wildcard src/runtime/*.cc)
|
2017-05-05 20:55:34 +03:00
|
|
|
|
|
|
|
# Objectives
|
2017-05-02 20:14:45 +03:00
|
|
|
METAL_OBJ = $(patsubst src/%.mm, build/%.o, $(METAL_SRC))
|
2017-05-20 19:05:12 +03:00
|
|
|
CUDA_OBJ = $(patsubst src/%.cc, build/%.o, $(CUDA_SRC))
|
|
|
|
OPENCL_OBJ = $(patsubst src/%.cc, build/%.o, $(OPENCL_SRC))
|
|
|
|
RPC_OBJ = $(patsubst src/%.cc, build/%.o, $(RPC_SRC))
|
2017-05-05 20:55:34 +03:00
|
|
|
CC_OBJ = $(patsubst src/%.cc, build/%.o, $(CC_SRC))
|
|
|
|
RUNTIME_OBJ = $(patsubst src/%.cc, build/%.o, $(RUNTIME_SRC))
|
|
|
|
CONTRIB_OBJ =
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
UNAME_S := $(shell uname -s)
|
2017-02-24 21:32:11 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
# Deps
|
|
|
|
ALL_DEP = $(CC_OBJ) $(CONTRIB_OBJ) $(LIB_HALIDEIR)
|
|
|
|
RUNTIME_DEP = $(RUNTIME_OBJ)
|
2017-02-24 21:32:11 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
# The flags
|
2017-05-31 07:17:52 +03:00
|
|
|
LDFLAGS = -pthread -lm -ldl
|
2017-07-11 04:23:47 +03:00
|
|
|
INCLUDE_FLAGS = -Iinclude -I$(DLPACK_PATH)/include -I$(DMLC_CORE_PATH)/include -IHalideIR/src -Itopi/include
|
|
|
|
CFLAGS = -std=c++11 -Wall -O2 $(INCLUDE_FLAGS) -fPIC
|
2017-05-31 07:17:52 +03:00
|
|
|
LLVM_CFLAGS= -fno-rtti -DDMLC_ENABLE_RTTI=0
|
2017-05-05 20:55:34 +03:00
|
|
|
FRAMEWORKS =
|
|
|
|
OBJCFLAGS = -fno-objc-arc
|
2017-07-14 04:44:33 +03:00
|
|
|
EMCC_FLAGS= -s RESERVED_FUNCTION_POINTERS=2 -s NO_EXIT_RUNTIME=1 -s MAIN_MODULE=1 -DDMLC_LOG_STACK_TRACE=0\
|
2017-07-11 04:23:47 +03:00
|
|
|
-std=c++11 -Oz $(INCLUDE_FLAGS)
|
2017-01-18 01:07:38 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
# Dependency specific rules
|
2017-02-22 21:47:54 +03:00
|
|
|
ifdef CUDA_PATH
|
|
|
|
NVCC=$(CUDA_PATH)/bin/nvcc
|
|
|
|
CFLAGS += -I$(CUDA_PATH)/include
|
|
|
|
LDFLAGS += -L$(CUDA_PATH)/lib64
|
2017-01-18 01:07:38 +03:00
|
|
|
endif
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
ifeq ($(USE_CUDA), 1)
|
2017-01-18 01:07:38 +03:00
|
|
|
CFLAGS += -DTVM_CUDA_RUNTIME=1
|
2017-01-31 06:09:22 +03:00
|
|
|
LDFLAGS += -lcuda -lcudart -lnvrtc
|
2017-05-20 19:05:12 +03:00
|
|
|
RUNTIME_DEP += $(CUDA_OBJ)
|
2017-01-18 01:07:38 +03:00
|
|
|
else
|
|
|
|
CFLAGS += -DTVM_CUDA_RUNTIME=0
|
|
|
|
endif
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
ifeq ($(USE_OPENCL), 1)
|
2017-01-18 08:13:16 +03:00
|
|
|
CFLAGS += -DTVM_OPENCL_RUNTIME=1
|
|
|
|
ifeq ($(UNAME_S), Darwin)
|
|
|
|
FRAMEWORKS += -framework OpenCL
|
|
|
|
else
|
|
|
|
LDFLAGS += -lOpenCL
|
|
|
|
endif
|
2017-05-20 19:05:12 +03:00
|
|
|
RUNTIME_DEP += $(OPENCL_OBJ)
|
2017-01-18 08:13:16 +03:00
|
|
|
else
|
|
|
|
CFLAGS += -DTVM_OPENCL_RUNTIME=0
|
|
|
|
endif
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
ifeq ($(USE_METAL), 1)
|
2017-05-02 20:14:45 +03:00
|
|
|
CFLAGS += -DTVM_METAL_RUNTIME=1
|
|
|
|
LDFLAGS += -lObjc
|
|
|
|
RUNTIME_DEP += $(METAL_OBJ)
|
|
|
|
FRAMEWORKS += -framework Metal -framework Foundation
|
|
|
|
else
|
|
|
|
CFLAGS += -DTVM_METAL_RUNTIME=0
|
|
|
|
endif
|
|
|
|
|
2017-05-20 19:05:12 +03:00
|
|
|
ifeq ($(USE_RPC), 1)
|
|
|
|
RUNTIME_DEP += $(RPC_OBJ)
|
|
|
|
endif
|
|
|
|
|
2017-02-22 21:47:54 +03:00
|
|
|
# llvm configuration
|
2017-05-08 19:20:56 +03:00
|
|
|
ifdef LLVM_CONFIG
|
2017-02-22 21:47:54 +03:00
|
|
|
LLVM_VERSION=$(shell $(LLVM_CONFIG) --version| cut -b 1,3)
|
|
|
|
LLVM_INCLUDE=$(filter -I%, $(shell $(LLVM_CONFIG) --cxxflags))
|
|
|
|
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags --libs --system-libs)
|
2017-05-31 07:17:52 +03:00
|
|
|
LLVM_CFLAGS += $(LLVM_INCLUDE) -DTVM_LLVM_VERSION=$(LLVM_VERSION)
|
2017-02-22 21:47:54 +03:00
|
|
|
endif
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
include make/contrib/cblas.mk
|
2017-06-30 04:32:34 +03:00
|
|
|
include make/contrib/nnpack.mk
|
2017-05-05 20:55:34 +03:00
|
|
|
|
2017-04-18 19:39:42 +03:00
|
|
|
ifdef ADD_CFLAGS
|
2017-02-22 21:47:54 +03:00
|
|
|
CFLAGS += $(ADD_CFLAGS)
|
|
|
|
endif
|
|
|
|
|
2017-04-18 19:39:42 +03:00
|
|
|
ifdef ADD_LDFLAGS
|
2017-02-22 21:47:54 +03:00
|
|
|
LDFLAGS += $(ADD_LDFLAGS)
|
|
|
|
endif
|
2017-01-18 08:13:16 +03:00
|
|
|
|
2016-10-16 03:35:32 +03:00
|
|
|
include tests/cpp/unittest.mk
|
|
|
|
|
|
|
|
test: $(TEST)
|
|
|
|
|
2017-03-14 07:28:03 +03:00
|
|
|
include verilog/verilog.mk
|
|
|
|
verilog: $(VER_LIBS)
|
|
|
|
|
2017-05-31 07:17:52 +03:00
|
|
|
|
|
|
|
# Special rules for LLVM related modules.
|
|
|
|
build/codegen/llvm/%.o: src/codegen/llvm/%.cc
|
2016-10-15 04:07:37 +03:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
|
2017-05-31 07:17:52 +03:00
|
|
|
$(CXX) -c $(CFLAGS) $(LLVM_CFLAGS) -c $< -o $@
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2017-05-31 07:17:52 +03:00
|
|
|
build/runtime/metal/%.o: src/runtime/metal/%.mm
|
2017-05-02 20:14:45 +03:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
|
|
|
|
$(CXX) $(OBJCFLAGS) -c $(CFLAGS) -c $< -o $@
|
|
|
|
|
2017-05-31 07:17:52 +03:00
|
|
|
build/%.o: src/%.cc
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
|
|
|
|
$(CXX) -c $(CFLAGS) -c $< -o $@
|
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
lib/libtvm.so: $(ALL_DEP) $(RUNTIME_DEP)
|
2016-10-15 04:07:37 +03:00
|
|
|
@mkdir -p $(@D)
|
2017-02-24 21:32:11 +03:00
|
|
|
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2017-02-24 21:32:11 +03:00
|
|
|
lib/libtvm_runtime.so: $(RUNTIME_DEP)
|
2016-10-17 07:33:42 +03:00
|
|
|
@mkdir -p $(@D)
|
2017-01-18 08:13:16 +03:00
|
|
|
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
|
2016-10-17 07:33:42 +03:00
|
|
|
|
2017-07-11 04:23:47 +03:00
|
|
|
lib/libtvm_web_runtime.bc: web/web_runtime.cc
|
|
|
|
@mkdir -p build/web
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CXX) $(CFLAGS) -MM -MT lib/libtvm_web_runtime.bc $< >build/web/web_runtime.d
|
|
|
|
emcc $(EMCC_FLAGS) -o $@ web/web_runtime.cc
|
|
|
|
|
|
|
|
lib/libtvm_web_runtime.js: lib/libtvm_web_runtime.bc
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
emcc $(EMCC_FLAGS) -o $@ lib/libtvm_web_runtime.bc
|
2017-02-24 21:32:11 +03:00
|
|
|
|
2017-05-05 20:55:34 +03:00
|
|
|
$(LIB_HALIDEIR): LIBHALIDEIR
|
2016-10-26 21:32:43 +03:00
|
|
|
|
|
|
|
LIBHALIDEIR:
|
|
|
|
+ cd HalideIR; make lib/libHalideIR.a ; cd $(ROOTDIR)
|
|
|
|
|
2017-03-12 21:34:04 +03:00
|
|
|
cpplint:
|
2017-06-24 03:34:12 +03:00
|
|
|
python dmlc-core/scripts/lint.py topi cpp topi/include;
|
2017-06-15 19:45:18 +03:00
|
|
|
python dmlc-core/scripts/lint.py tvm cpp include src verilog\
|
|
|
|
examples/extension/src examples/graph_executor/src
|
2017-03-12 21:34:04 +03:00
|
|
|
|
|
|
|
pylint:
|
|
|
|
pylint python/tvm --rcfile=$(ROOTDIR)/tests/lint/pylintrc
|
2017-06-24 03:34:12 +03:00
|
|
|
pylint topi/python/topi --rcfile=$(ROOTDIR)/tests/lint/pylintrc
|
2017-03-12 21:34:04 +03:00
|
|
|
|
|
|
|
lint: cpplint pylint
|
2016-10-15 04:07:37 +03:00
|
|
|
|
2016-10-16 05:51:02 +03:00
|
|
|
doc:
|
|
|
|
doxygen docs/Doxyfile
|
|
|
|
|
2017-04-28 01:20:29 +03:00
|
|
|
# Cython build
|
|
|
|
cython:
|
|
|
|
cd python; python setup.py build_ext --inplace
|
|
|
|
|
|
|
|
cython2:
|
|
|
|
cd python; python2 setup.py build_ext --inplace
|
|
|
|
|
|
|
|
cython3:
|
|
|
|
cd python; python3 setup.py build_ext --inplace
|
|
|
|
|
|
|
|
cyclean:
|
|
|
|
rm -rf python/tvm/*/*/*.so python/tvm/*/*/*.cpp
|
|
|
|
|
2016-10-15 04:07:37 +03:00
|
|
|
clean:
|
2016-10-16 03:35:32 +03:00
|
|
|
$(RM) -rf build lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o */*.d */*/*.d */*/*/*.d
|
2017-06-01 01:07:57 +03:00
|
|
|
cd HalideIR; make clean; cd $(ROOTDIR)
|
2016-10-15 04:07:37 +03:00
|
|
|
|
|
|
|
-include build/*.d
|
|
|
|
-include build/*/*.d
|
2017-01-31 06:09:22 +03:00
|
|
|
-include build/*/*/*.d
|