Debian Codegraph @

src/autoschedulers/anderson2021/Makefile

raw
1 THIS_MAKEFILE = $(realpath $(filter %Makefile, $(MAKEFILE_LIST)))
2 SRC = $(strip $(shell dirname $(THIS_MAKEFILE)))
3 HALIDE_SRC_ROOT = $(realpath $(SRC)/../../../)
4 COMMON_DIR ?= $(realpath $(SRC)/../common/)
5 HALIDE_TEST_DIR ?= $(HALIDE_SRC_ROOT)/test/autoschedulers/anderson2021
6
7 HALIDE_DISTRIB_PATH ?= $(HALIDE_SRC_ROOT)/distrib
8 HL_TARGET ?= host
9
10 $(info Looking for Halide distro at $(HALIDE_DISTRIB_PATH). If this is incorrect, set the make variable HALIDE_DISTRIB_PATH)
11
12 # Don't include an autoscheduler in the generator deps
13 AUTOSCHEDULER=
14 include $(HALIDE_SRC_ROOT)/apps/support/Makefile.inc
15
16 # Add the relative location of libHalide.so in the rpath in a distro
17 ifeq ($(UNAME), Darwin)
18 HALIDE_RPATH_FOR_BIN = '-Wl,-rpath,@executable_path/../lib'
19 HALIDE_RPATH_FOR_LIB = '-Wl,-rpath,@loader_path'
20 else
21 HALIDE_RPATH_FOR_BIN = '-Wl,-rpath,$$ORIGIN/../lib'
22 HALIDE_RPATH_FOR_LIB = '-Wl,-rpath,$$ORIGIN'
23 endif
24
25 CXXFLAGS += -I$(COMMON_DIR)
26
27 ENABLE_DEBUG_OUTPUT ?= false
28
29 AUTOSCHED_SAMPLES_OUT ?= $(SRC)/samples
30
31 AUTOSCHED_WEIGHT_OBJECTS=$(BIN)/baseline_weights.o
32
33 $(BIN)/binary2cpp: $(HALIDE_SRC_ROOT)/tools/binary2cpp.cpp
34 @mkdir -p $(@D)
35 $(CXX) $< -o $@
36
37 $(BIN)/baseline_weights.cpp: $(BIN)/binary2cpp $(SRC)/baseline.weights
38 @mkdir -p $(@D)
39 $(BIN)/binary2cpp baseline_weights < $(SRC)/baseline.weights > $@
40
41 $(BIN)/baseline_weights.o: $(BIN)/baseline_weights.cpp
42 $(CXX) -c $< -o $@
43
44 AUTOSCHED_COST_MODEL_LIBS=\
45 $(BIN)/cost_model/anderson2021_cost_model.a \
46 $(BIN)/cost_model/anderson2021_train_cost_model.a \
47
48 $(BIN)/cost_model.generator: $(SRC)/cost_model_generator.cpp \
49 $(SRC)/cost_model_schedule.h \
50 $(SRC)/NetworkSize.h \
51 $(GENERATOR_DEPS)
52 @mkdir -p $(@D)
53 $(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(USE_EXPORT_DYNAMIC)
54
55 $(BIN)/auto_schedule_runtime.a: $(BIN)/cost_model.generator
56 @mkdir -p $(@D)
57 $^ -r auto_schedule_runtime -o $(BIN) target=$(HL_TARGET)
58
59 $(BIN)/cost_model/anderson2021_%.a: $(BIN)/cost_model.generator
60 @mkdir -p $(@D)
61 $^ -g $* -o $(BIN)/anderson2021_cost_model -f $* -n anderson2021_$* target=$(HL_TARGET)-no_runtime enable_debug_output=$(ENABLE_DEBUG_OUTPUT) -e stmt,static_library,h,assembly
62
63 # It's important to use dynamic lookups for undefined symbols here: all of libHalide
64 # is expected to be present (in the loading binary), so we explicitly make the symbols
65 # undefined rather than dependent on libHalide.so.
66 $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT): $(SRC)/AutoSchedule.cpp \
67 $(SRC)/AutoSchedule.h \
68 $(COMMON_DIR)/ASLog.cpp \
69 $(SRC)/DefaultCostModel.h \
70 $(SRC)/DefaultCostModel.cpp \
71 $(SRC)/Weights.h \
72 $(SRC)/Weights.cpp \
73 $(SRC)/FunctionDAG.h \
74 $(SRC)/FunctionDAG.cpp \
75 $(SRC)/LoopNest.h \
76 $(SRC)/LoopNest.cpp \
77 $(SRC)/LoopNestParser.h \
78 $(SRC)/GPUMemInfo.h \
79 $(SRC)/GPULoopInfo.h \
80 $(SRC)/GPULoopInfo.cpp \
81 $(SRC)/ThreadInfo.h \
82 $(SRC)/Featurization.h \
83 $(SRC)/CostModel.h \
84 $(COMMON_DIR)/PerfectHashMap.h \
85 $(SRC)/SearchSpace.h \
86 $(SRC)/SearchSpace.cpp \
87 $(SRC)/SearchSpaceOptions.h \
88 $(SRC)/State.h \
89 $(SRC)/State.cpp \
90 $(SRC)/Statistics.h \
91 $(SRC)/Tiling.h \
92 $(SRC)/Tiling.cpp \
93 $(AUTOSCHED_WEIGHT_OBJECTS) \
94 $(AUTOSCHED_COST_MODEL_LIBS) \
95 $(GENERATOR_DEPS) \
96 $(BIN)/auto_schedule_runtime.a
97 @mkdir -p $(@D)
98 $(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) -I $(BIN)/anderson2021_cost_model $(filter-out %.h $(LIBHALIDE_LDFLAGS),$^) -o $@ -I .
99
100 $(BIN)/anderson2021_retrain_cost_model: $(SRC)/retrain_cost_model.cpp \
101 $(COMMON_DIR)/ASLog.cpp \
102 $(SRC)/DefaultCostModel.h \
103 $(SRC)/DefaultCostModel.cpp \
104 $(SRC)/Weights.h \
105 $(SRC)/Weights.cpp \
106 $(SRC)/CostModel.h \
107 $(SRC)/NetworkSize.h \
108 $(AUTOSCHED_COST_MODEL_LIBS) \
109 $(AUTOSCHED_WEIGHT_OBJECTS) \
110 $(BIN)/auto_schedule_runtime.a
111 @mkdir -p $(@D)
112 $(CXX) $(CXXFLAGS) -frtti -Wall -I ../support -I $(BIN)/anderson2021_cost_model $(OPTIMIZE) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(USE_OPEN_MP)
113
114 $(BIN)/anderson2021_weightsdir_to_weightsfile: $(SRC)/weightsdir_to_weightsfile.cpp $(SRC)/Weights.cpp
115 @mkdir -p $(@D)
116 $(CXX) $(CXXFLAGS) $^ $(OPTIMIZE) -o $@ -I .
117
118 # A sample generator to autoschedule. Note that if it statically links
119 # to libHalide, then it must be build with $(USE_EXPORT_DYNAMIC), or the
120 # autoscheduler can't find the libHalide symbols that it needs.
121 $(GENERATOR_BIN)/anderson2021_demo.generator: $(HALIDE_TEST_DIR)/demo_generator.cpp $(GENERATOR_DEPS)
122 @mkdir -p $(@D)
123 $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS)
124
125 # To use the autoscheduler, set a few environment variables and use the -p flag to the generator to load the autoscheduler as a plugin
126 $(BIN)/%/anderson2021_demo.a: $(GENERATOR_BIN)/anderson2021_demo.generator $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
127 @mkdir -p $(@D)
128 HL_WEIGHTS_DIR=$(SRC)/baseline.weights \
129 $(GENERATOR_BIN)/anderson2021_demo.generator -g demo -o $(@D) -f anderson2021_demo target=$* -p $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT) autoscheduler=Anderson2021
130
131 $(BIN)/%/anderson2021_demo.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/anderson2021_demo.registration.cpp $(BIN)/%/anderson2021_demo.a
132 @mkdir -p $(@D)
133 $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(IMAGE_IO_FLAGS)
134
135 # demonstrates single-shot use of the autoscheduler
136 anderson2021_demo: $(BIN)/$(HL_TARGET)/anderson2021_demo.rungen $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
137 $< --benchmarks=all --benchmark_min_time=1 --estimate_all
138
139 $(BIN)/featurization_to_sample $(BIN)/get_host_target:
140 @mkdir -p $(@D)
141 $(MAKE) -f $(COMMON_DIR)/Makefile $(BIN)/featurization_to_sample $(BIN)/get_host_target
142
143 # demonstrates an autotuning loop
144 # (using $(BIN) and $(SRC) here seems overkill, but makes copy-n-paste elsewhere easier)
145 autotune: $(GENERATOR_BIN)/anderson2021_demo.generator $(BIN)/featurization_to_sample $(BIN)/get_host_target $(BIN)/anderson2021_retrain_cost_model $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT) $(SRC)/anderson2021_autotune_loop.sh
146 SAMPLES_DIR=test_autotuned_samples \
147 bash $(SRC)/anderson2021_autotune_loop.sh \
148 $(GENERATOR_BIN)/anderson2021_demo.generator \
149 anderson2021_demo \
150 "" \
151 $(SRC)/baseline.weights \
152 $(BIN) \
153 0
154
155 $(BIN)/anderson2021_test_function_dag: test_function_dag.cpp FunctionDAG.h FunctionDAG.cpp $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp
156 @mkdir -p $(@D)
157 $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS)
158
159 # Simple jit-based test
160 $(BIN)/$(HL_TARGET)/test: $(HALIDE_TEST_DIR)/test.cpp $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
161 @mkdir -p $(@D)
162 $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $^ -o $@ $(LIBHALIDE_LDFLAGS)
163
164 anderson2021_test_function_dag: $(BIN)/anderson2021_test_function_dag
165 $^
166
167 run_test: $(BIN)/$(HL_TARGET)/test $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
168 HL_WEIGHTS_DIR=$(SRC)/baseline.weights LD_LIBRARY_PATH=$(BIN) $< $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
169
170 .PHONY: test clean
171
172 # Note that when running the *test*, we want to ensure that we generate samples
173 # to a subdir of $(BIN), so that they don't get inadvertently generated into
174 # our source tree. (Normally we want samples/ to be retained, to avoid data loss;
175 # for the test target, however, it's imperative it go into a transitory directory,
176 # to avoid eventually consuming all disk space on the buildbot...)
177 test: AUTOSCHED_SAMPLES_OUT = $(BIN)/test_samples_out
178
179 # Note that 'make build' and 'make test' is used by Halide buildbots
180 # to spot-check changes, so it's important to try a little of each of
181 # the important paths here, including single-shot and autotune-loop
182 build: $(BIN)/$(HL_TARGET)/test \
183 $(BIN)/anderson2021_test_function_dag \
184 $(BIN)/$(HL_TARGET)/included_schedule_file.rungen \
185 $(GENERATOR_BIN)/anderson2021_demo.generator \
186 $(BIN)/anderson2021_retrain_cost_model \
187 $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
188
189 test: test_bounds test_tiling test_storage_strides test_parser test_state test_thread_info run_test anderson2021_test_function_dag anderson2021_demo included_schedule_file autotune
190
191 TEST_DIR=$(SRC)/test
192
193 $(BIN)/test_bounds: $(TEST_DIR)/bounds.cpp LoopNest.h LoopNest.cpp FunctionDAG.cpp FunctionDAG.h $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp GPULoopInfo.cpp GPULoopInfo.h GPUMemInfo.h Tiling.h Tiling.cpp
194 @mkdir -p $(@D)
195 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
196
197 test_bounds: $(BIN)/test_bounds
198 $^
199
200 $(BIN)/test_tiling: $(TEST_DIR)/tiling.cpp Tiling.h Tiling.cpp
201 @mkdir -p $(@D)
202 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
203
204 test_tiling: $(BIN)/test_tiling
205 $^
206
207 $(BIN)/test_storage_strides: $(TEST_DIR)/storage_strides.cpp LoopNest.h LoopNest.cpp FunctionDAG.cpp FunctionDAG.h $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp GPULoopInfo.cpp GPULoopInfo.h GPUMemInfo.h Tiling.h Tiling.cpp
208 @mkdir -p $(@D)
209 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
210
211 test_storage_strides: $(BIN)/test_storage_strides
212 $^
213
214 $(BIN)/test_parser: $(TEST_DIR)/parser.cpp LoopNestParser.h $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp
215 @mkdir -p $(@D)
216 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
217
218 test_parser: $(BIN)/test_parser
219 $^
220
221 $(BIN)/test_state: $(TEST_DIR)/state.cpp State.h State.cpp LoopNest.h LoopNest.cpp FunctionDAG.cpp FunctionDAG.h $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp GPULoopInfo.cpp GPULoopInfo.h GPUMemInfo.h Tiling.h Tiling.cpp
222 @mkdir -p $(@D)
223 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
224
225 test_state: $(BIN)/test_state
226 $^
227
228 $(BIN)/test_thread_info: $(TEST_DIR)/thread_info.cpp LoopNest.h LoopNest.cpp FunctionDAG.cpp FunctionDAG.h $(COMMON_DIR)/ASLog.h $(COMMON_DIR)/ASLog.cpp GPULoopInfo.cpp GPULoopInfo.h GPUMemInfo.h Tiling.h Tiling.cpp
229 @mkdir -p $(@D)
230 $(CXX) $(OPTIMIZE) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) -I$(SRC)
231
232 test_thread_info: $(BIN)/test_thread_info
233 $^
234
235 clean:
236 rm -rf $(BIN)
237
238 # A sample generator to demonstrate including autogenerated .sample.h
239 # files for scheduling purposes; the catch here is that we'll need
240 # to be able to compile the Generator two different ways:
241 #
242 # - one that will be used to generate the .schedule.h
243 # - one that will consume the .schedule.h generated above
244 #
245 # We'll use the preprocessor (GENERATING_SCHEDULE) to distinguish between these two.
246
247 $(GENERATOR_BIN)/included_schedule_file_none.generator: $(HALIDE_TEST_DIR)/included_schedule_file_generator.cpp $(GENERATOR_DEPS)
248 @mkdir -p $(@D)
249 $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -DGENERATING_SCHEDULE -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS)
250
251 # This is the target you build to (re)generate the schedule file.
252 # (Note that we only need the schedule output, so we pass `-e schedule` to
253 # the Generator so that it can skip producing other outputs.)
254 $(BIN)/%/included_schedule_file.schedule.h: $(GENERATOR_BIN)/included_schedule_file_none.generator $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT)
255 @mkdir -p $(@D)
256 HL_WEIGHTS_DIR=$(SRC)/baseline.weights \
257 $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$* -p $(BIN)/libautoschedule_anderson2021.$(PLUGIN_EXT) autoscheduler=Anderson2021 autoscheduler.parallelism=80 -e schedule
258
259 # Note that this depends on $(HALIDE_TEST_DIR)/included_schedule_file.schedule.h rather than $(BIN)/%/included_schedule_file.schedule.h --
260 # the former should be generated by something like
261 #
262 # make bin/host/included_schedule_file.schedule.h
263 # cp bin/host/included_schedule_file.schedule.h included_schedule_file.schedule.h
264 #
265 $(GENERATOR_BIN)/included_schedule_file.generator: $(HALIDE_TEST_DIR)/included_schedule_file_generator.cpp $(HALIDE_TEST_DIR)/included_schedule_file.schedule.h $(GENERATOR_DEPS)
266 @mkdir -p $(@D)
267 $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS)
268
269 # Note that this does not depend on libauto_schedule nor does it call
270 # the autoscheduler at build time; it includes the generated schedule (included_schedule_file.schedule.h),
271 # which has been added to our local source control.
272 $(BIN)/%/included_schedule_file.a: $(GENERATOR_BIN)/included_schedule_file.generator
273 @mkdir -p $(@D)
274 $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$*
275
276 $(BIN)/%/included_schedule_file.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/included_schedule_file.registration.cpp $(BIN)/%/included_schedule_file.a
277 @mkdir -p $(@D)
278 $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(IMAGE_IO_FLAGS)
279
280 included_schedule_file: $(BIN)/$(HL_TARGET)/included_schedule_file.rungen
281 $^ --benchmarks=all --benchmark_min_time=1 --estimate_all