-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
181 lines (151 loc) · 6.11 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
.SUFFIXES:
MAKEFLAGS := --jobs=$(shell nproc) --output-sync=target
# Setup CONFIG, DEVICE_RUNNER, and out/build dirs first
CONFIG ?= assert
ARCH_NAME ?= grayskull
# TODO: enable OUT to be per config (this impacts all scripts that run tests)
# OUT ?= build_$(DEVICE_RUNNER)_$(CONFIG)
OUT ?= build
PREFIX ?= $(OUT)
CONFIG_CFLAGS =
CONFIG_LDFLAGS =
CONFIG_CXXFLAGS =
ifeq ($(CONFIG), release)
CONFIG_CFLAGS += -O3
CONFIG_CXXFLAGS = -fvisibility-inlines-hidden
else ifeq ($(CONFIG), ci) # significantly smaller artifacts
CONFIG_CFLAGS += -O3 -DDEBUG -Werror
else ifeq ($(CONFIG), assert)
CONFIG_CFLAGS += -O3 -g -DDEBUG
else ifeq ($(CONFIG), asan)
CONFIG_CFLAGS += -O3 -g -DDEBUG -fsanitize=address
CONFIG_LDFLAGS += -fsanitize=address
ifeq ($(findstring clang,$(CC)),clang)
CONFIG_CFLAGS += -shared-libasan
CONFIG_LDFLAGS += -shared-libasan
endif
else ifeq ($(CONFIG), ubsan)
CONFIG_CFLAGS += -O3 -g -DDEBUG -fsanitize=undefined
CONFIG_LDFLAGS += -fsanitize=undefined
else ifeq ($(CONFIG), gprof)
CONFIG_CFLAGS += -O3 -g -DDEBUG -pg
CONFIG_LDFLAGS += -pg
else ifeq ($(CONFIG), debug)
CONFIG_CFLAGS += -O0 -g -DDEBUG
else
$(error Unknown value for CONFIG "$(CONFIG)")
endif
OBJDIR = $(OUT)/obj
LIBDIR = $(OUT)/lib
BINDIR = $(OUT)/bin
INCDIR = $(OUT)/include
TESTDIR = $(OUT)/test
DOCSDIR = $(OUT)/docs
SUBMODULESDIR = $(OUT)/submodules
TORCHVISIONDIR = build_deps/vision
export TT_BACKEND_ERISC_PRECOMPILED_BINARIES_PATH=./erisc_hex/
# Top level flags, compiler, defines etc.
#WARNINGS ?= -Wall -Wextra
WARNINGS ?= -Wdelete-non-virtual-dtor -Wreturn-type -Wswitch -Wuninitialized -Wno-unused-parameter
CC ?= gcc
CXX ?= g++
CFLAGS_NO_WARN ?= -MMD -I. $(CONFIG_CFLAGS) -mavx2 -DBUILD_DIR=\"$(OUT)\" -I$(INCDIR) -DFMT_HEADER_ONLY -Ithird_party/fmt -Ithird_party/pybind11/include
CFLAGS ?= $(CFLAGS_NO_WARN) $(WARNINGS)
CXXFLAGS ?= --std=c++17 -maes -mavx $(CONFIG_CXXFLAGS)
LDFLAGS ?= $(CONFIG_LDFLAGS) -Wl,-rpath,$(PREFIX)/lib -L$(LIBDIR) -Ldevice/lib
SHARED_LIB_FLAGS = -shared -fPIC
STATIC_LIB_FLAGS = -fPIC
ifeq ($(findstring clang,$(CC)),clang)
WARNINGS += -Wno-c++11-narrowing
LDFLAGS += -lstdc++
else
WARNINGS += -Wmaybe-uninitialized
LDFLAGS += -lstdc++
endif
GIT_COMMON_DIR=$(shell git rev-parse --git-common-dir)
SUBMODULES=$(shell git submodule status | grep -o "third_party/[^ ]*")
SUBMODULES_UPDATED=$(addprefix $(SUBMODULESDIR)/, $(SUBMODULES:%=%.checkout))
SKIP_BBE_UPDATE ?= 0
SKIP_SUBMODULE_UPDATE ?= $(SKIP_BBE_UPDATE)
ifeq ($(EMULATION_DEVICE_EN), 1)
TENSIX_EMULATION_ZEBU = $(TENSIX_EMULATION_ROOT)/zebu
TENSIX_EMULATION_ZCUI_WORK = $(TENSIX_EMULATION_ROOT)/targets/tensix_2x2_1dram_BH/zcui.work
endif
all: update_submodules build ;
# These must be in dependency order (enforces no circular deps)
include python_env/module.mk
include pybuda/module.mk
include docs/public/module.mk
update_submodules: $(SUBMODULES_UPDATED) emulation_device_links ;
$(SUBMODULESDIR)/%.checkout:
@mkdir -p $(dir $@)
ifeq ($(SKIP_SUBMODULE_UPDATE), 0)
git submodule update --init --recursive $(@:$(SUBMODULESDIR)/%.checkout=%)
git -C $(@:$(SUBMODULESDIR)/%.checkout=%) submodule foreach --recursive git lfs install || true
git -C $(@:$(SUBMODULESDIR)/%.checkout=%) submodule foreach --recursive git lfs pull
git -C $(@:$(SUBMODULESDIR)/%.checkout=%) submodule foreach --recursive git lfs checkout HEAD
endif
touch $@
emulation_device_links:
ifeq ($(EMULATION_DEVICE_EN), 1)
@echo "Linking and copying emulation device files..."
ln -sf $(TENSIX_EMULATION_ZCUI_WORK) $(OUT)/.
ln -sf $(TENSIX_EMULATION_ZCUI_WORK) ../
cp -f $(TENSIX_EMULATION_ZEBU)/scripts/designFeatures ./
endif
build: pybuda third_party/tvm torchvision ;
third_party/tvm: $(SUBMODULESDIR)/third_party/tvm.build ;
torchvision: build_deps/torchvision.build ;
build_deps/torchvision.build: python_env
@if [ ! -d $(TORCHVISIONDIR) ]; then \
git clone --depth 1 --branch v0.16.0 https://github.com/pytorch/vision.git $(TORCHVISIONDIR); \
fi
echo "Building torchvision..."
bash -c "source $(PYTHON_ENV)/bin/activate && cd $(TORCHVISIONDIR) && PYTORCH_VERSION=2.1.0 _GLIBCXX_USE_CXX11_ABI=1 python setup.py bdist_wheel -d build_out"
bash -c "source $(PYTHON_ENV)/bin/activate && pip install $(TORCHVISIONDIR)/build_out/torchvision*.whl"
touch $@
$(SUBMODULESDIR)/third_party/tvm.build: python_env $(SUBMODULESDIR)/third_party/tvm.checkout
bash -c "source $(PYTHON_ENV)/bin/activate && ./third_party/tvm/install.sh"
touch $@
build_tests: pybuda/csrc/balancer/tests pybuda/csrc/graph_lib/tests pybuda/csrc/passes/tests pybuda/csrc/pattern_matcher/tests pybuda/csrc/placer/tests ;
run_tests: build_tests
@echo "Running tests..."
@BUDA_HOME="third_party/budabackend" $(TESTDIR)/pybuda/csrc/balancer/tests/balancer_unit_tests
@BUDA_HOME="third_party/budabackend" $(TESTDIR)/pybuda/csrc/graph_lib/tests/graphlib_unit_tests
@BUDA_HOME="third_party/budabackend" $(TESTDIR)/pybuda/csrc/passes/tests/passes_unit_tests
@BUDA_HOME="third_party/budabackend" $(TESTDIR)/pybuda/csrc/pattern_matcher/tests/pattern_matcher_unit_tests
@BUDA_HOME="third_party/budabackend" $(TESTDIR)/pybuda/csrc/placer/tests/placer_unit_tests
clean: third_party/budabackend/clean
rm -rf $(OUT)
rm -rf third_party/tvm/build
rm -rf build_deps/
clean_no_python:
find $(OUT)/ -maxdepth 1 -mindepth 1 -type d -not -name 'python_env' -print0 | xargs -0 -I {} rm -Rf {}
find $(OUT)/ -maxdepth 1 -type f -delete
.PHONY: install
install: all
ifeq ($(PREFIX), $(OUT))
@echo "To install you must set PREFIX, e.g."
@echo ""
@echo " PREFIX=/usr CONFIG=release make install"
@echo ""
@exit 1
endif
cp -r $(LIBDIR)/* $(PREFIX)/lib/
cp -r $(INCDIR)/* $(PREFIX)/include/
cp -r $(BINDIR)/* $(PREFIX)/bin/
.PHONY: b0
b0: export LD_LIBRARY_PATH=versim/wormhole_b0/lib:versim/wormhole_b0/lib/ext
b0: export BACKEND_ARCH_NAME=wormhole_b0
b0: build ;
.PHONY: build_tvm
build_tvm: third_party/tvm ;
.PHONY: stubs
stubs:
pip install mypy
stubgen -m pybuda._C -m pybuda._C.autograd -m pybuda._C.balancer -m pybuda._C.graph -m pybuda._C.backend_api -m pybuda._C.pattern_matcher -m pybuda._C.scheduler -m pybuda._C.torch_device -o pybuda
# Cleaning PyBuda and BBE artifacts
.PHONY: clean_tt
clean_tt:
@rm -rf .hlkc_cache/ .pkl_memoize_py3/ generated_modules/ tt_build/
@rm -f *netlist.yaml