Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up various autoscheduler tool issues #7483

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2374,23 +2374,33 @@ ifeq ($(UNAME), Darwin)
install_name_tool -id @rpath/$(@F) $(CURDIR)/$@
endif

# Build some common tools
$(DISTRIB_DIR)/bin/featurization_to_sample $(DISTRIB_DIR)/bin/get_host_target: $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT)
@mkdir -p $(@D)
$(MAKE) -f $(SRC_DIR)/autoschedulers/common/Makefile $(BIN_DIR)/featurization_to_sample $(BIN_DIR)/get_host_target HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR)
for TOOL in featurization_to_sample get_host_target; do \
cp $(BIN_DIR)/$${TOOL} $(DISTRIB_DIR)/bin/; \
done

# Adams2019 also includes autotuning tools
$(DISTRIB_DIR)/lib/libautoschedule_adams2019.$(PLUGIN_EXT): $(BIN_DIR)/libautoschedule_adams2019.$(PLUGIN_EXT)
@mkdir -p $(@D)
$(MAKE) -f $(SRC_DIR)/autoschedulers/adams2019/Makefile $(BIN_DIR)/retrain_cost_model $(BIN_DIR)/featurization_to_sample $(BIN_DIR)/get_host_target HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR)
$(MAKE) -f $(SRC_DIR)/autoschedulers/adams2019/Makefile $(BIN_DIR)/adams2019_retrain_cost_model $(BIN_DIR)/adams2019_weightsdir_to_weightsfile HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR)
cp $< $(DISTRIB_DIR)/lib/
for TOOL in retrain_cost_model featurization_to_sample get_host_target; do \
cp $(BIN_DIR)/$${TOOL} $(DISTRIB_DIR)/bin/; \
for TOOL in adams2019_retrain_cost_model adams2019_weightsdir_to_weightsfile; do \
cp $(BIN_DIR)/$${TOOL} $(DISTRIB_DIR)/bin/; \
done
cp $(SRC_DIR)/autoschedulers/adams2019/autotune_loop.sh $(DISTRIB_DIR)/tools/
cp $(SRC_DIR)/autoschedulers/adams2019/adams2019_autotune_loop.sh $(DISTRIB_DIR)/tools/
ifeq ($(UNAME), Darwin)
install_name_tool -id @rpath/$(@F) $(CURDIR)/$@
endif

autoschedulers: \
$(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(PLUGIN_EXT) \
$(DISTRIB_DIR)/lib/libautoschedule_li2018.$(PLUGIN_EXT) \
$(DISTRIB_DIR)/lib/libautoschedule_adams2019.$(PLUGIN_EXT)
$(DISTRIB_DIR)/lib/libautoschedule_adams2019.$(PLUGIN_EXT) \
$(DISTRIB_DIR)/bin/featurization_to_sample \
$(DISTRIB_DIR)/bin/get_host_target

.PHONY: distrib
distrib: $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT) autoschedulers
Expand Down
12 changes: 9 additions & 3 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ install(TARGETS Halide Halide_Generator Halide_LanguageOptions
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if (TARGET Halide_Adams2019)
install(TARGETS Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016
install(TARGETS Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016 Halide_Anderson2021
EXPORT Halide_Interfaces
LIBRARY DESTINATION ${Halide_INSTALL_PLUGINDIR} COMPONENT Halide_Runtime
NAMELINK_COMPONENT Halide_Development)
Expand Down Expand Up @@ -79,7 +79,12 @@ else ()
set(rbase $ORIGIN)
endif ()

foreach (util IN ITEMS adams2019_retrain_cost_model adams2019_featurization_to_sample adams2019_get_host_target adams2019_weightsdir_to_weightsfile)
foreach (util IN ITEMS adams2019_retrain_cost_model
adams2019_weightsdir_to_weightsfile
anderson2021_retrain_cost_model
anderson2021_weightsdir_to_weightsfile
featurization_to_sample
get_host_target)
if (TARGET ${util})
if (NOT CMAKE_INSTALL_RPATH)
set_target_properties(${util} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}")
Expand Down Expand Up @@ -121,7 +126,8 @@ install(DIRECTORY ${Halide_SOURCE_DIR}/tools/
PATTERN "build_halide_h.cpp" EXCLUDE
PATTERN "find_inverse.cpp" EXCLUDE)

install(PROGRAMS ${Halide_SOURCE_DIR}/src/autoschedulers/adams2019/autotune_loop.sh
install(PROGRAMS ${Halide_SOURCE_DIR}/src/autoschedulers/adams2019/adams2019_autotune_loop.sh
${Halide_SOURCE_DIR}/src/autoschedulers/anderson2021/anderson2021_autotune_loop.sh
DESTINATION ${Halide_INSTALL_TOOLSDIR}
COMPONENT Halide_Development)

Expand Down
26 changes: 7 additions & 19 deletions src/autoschedulers/adams2019/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ if (APPLE AND num_archs GREATER 1)
)
endif ()

# retrain_cost_model
# adams2019_retrain_cost_model
if (WITH_UTILS)
add_executable(adams2019_retrain_cost_model
DefaultCostModel.cpp
${COMMON_DIR}/Weights.cpp
Weights.cpp
retrain_cost_model.cpp
$<TARGET_OBJECTS:adams2019_weights_obj>)
target_include_directories(adams2019_retrain_cost_model PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/adams2019")
Expand All @@ -98,7 +98,7 @@ add_autoscheduler(
FunctionDAG.cpp
LoopNest.cpp
State.cpp
${COMMON_DIR}/Weights.cpp
Weights.cpp
$<TARGET_OBJECTS:adams2019_weights_obj>
)

Expand All @@ -107,16 +107,10 @@ target_link_libraries(Halide_Adams2019 PRIVATE ASLog ParamParser adams2019_cost_

# ====================================================
# Auto-tuning support utilities.
# TODO(#4053): implement auto-tuning support in CMake?

if (WITH_UTILS)
add_executable(adams2019_featurization_to_sample ${COMMON_DIR}/featurization_to_sample.cpp)

add_executable(adams2019_get_host_target ${COMMON_DIR}/get_host_target.cpp)
target_link_libraries(adams2019_get_host_target PRIVATE Halide::Halide)

add_executable(adams2019_weightsdir_to_weightsfile ${COMMON_DIR}/weightsdir_to_weightsfile.cpp ${COMMON_DIR}/Weights.cpp)
target_include_directories(adams2019_weightsdir_to_weightsfile PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/adams2019" ${COMMON_DIR})
add_executable(adams2019_weightsdir_to_weightsfile weightsdir_to_weightsfile.cpp Weights.cpp)
target_include_directories(adams2019_weightsdir_to_weightsfile PRIVATE ${COMMON_DIR})
target_link_libraries(adams2019_weightsdir_to_weightsfile PRIVATE Halide::Runtime)
endif ()

Expand All @@ -125,15 +119,9 @@ endif ()
# which is handled in tests/autoschedulers/Adams2019)

if (WITH_TESTS)

add_executable(adams2019_test_perfect_hash_map ${COMMON_DIR}/test_perfect_hash_map.cpp)
add_test(NAME adams2019_test_perfect_hash_map COMMAND adams2019_test_perfect_hash_map)
set_tests_properties(adams2019_test_perfect_hash_map PROPERTIES LABELS "adams2019;autoschedulers;auto_schedule")

add_executable(adams2019_test_function_dag ${COMMON_DIR}/test_function_dag.cpp FunctionDAG.cpp)
target_include_directories(adams2019_test_function_dag PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/adams2019" ${COMMON_DIR})
add_executable(adams2019_test_function_dag test_function_dag.cpp FunctionDAG.cpp)
# target_include_directories(adams2019_test_function_dag PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/adams2019" ${COMMON_DIR})
target_link_libraries(adams2019_test_function_dag PRIVATE ASLog Halide::Halide Halide::Tools Halide::Plugin)
add_test(NAME adams2019_test_function_dag COMMAND adams2019_test_function_dag)
set_tests_properties(adams2019_test_function_dag PROPERTIES LABELS "adams2019;autoschedulers;auto_schedule")

endif()
25 changes: 9 additions & 16 deletions src/autoschedulers/adams2019/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $(BIN)/auto_schedule_runtime.a: $(BIN)/cost_model.generator

$(BIN)/cost_model/adams2019_%.a: $(BIN)/cost_model.generator
@mkdir -p $(@D)
$^ -g $* -o $(BIN)/cost_model -f $* -n adams2019_$* target=$(HL_TARGET)-no_runtime -e stmt,static_library,h,assembly
$^ -g $* -o $(BIN)/adams2019_cost_model -f $* -n adams2019_$* target=$(HL_TARGET)-no_runtime -e stmt,static_library,h,assembly
steven-johnson marked this conversation as resolved.
Show resolved Hide resolved

# It's important to use dynamic lookups for undefined symbols here: all of libHalide
# is expected to be present (in the loading binary), so we explicitly make the symbols
Expand All @@ -68,8 +68,8 @@ $(BIN)/libautoschedule_adams2019.$(PLUGIN_EXT): \
$(SRC)/Cache.cpp \
$(SRC)/DefaultCostModel.h \
$(SRC)/DefaultCostModel.cpp \
$(COMMON_DIR)/Weights.h \
$(COMMON_DIR)/Weights.cpp \
$(SRC)/Weights.h \
$(SRC)/Weights.cpp \
$(SRC)/FunctionDAG.h \
$(SRC)/FunctionDAG.cpp \
$(SRC)/LoopNest.h \
Expand All @@ -85,30 +85,23 @@ $(BIN)/libautoschedule_adams2019.$(PLUGIN_EXT): \
$(BIN)/auto_schedule_runtime.a \
| $(LIB_HALIDE)
@mkdir -p $(@D)
$(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) -I $(BIN)/cost_model $(filter-out %.h $(LIBHALIDE_LDFLAGS),$^) -o $@ $(HALIDE_SYSTEM_LIBS) $(HALIDE_RPATH_FOR_LIB) -I $(SRC)
$(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) -I $(BIN)/adams2019_cost_model $(filter-out %.h $(LIBHALIDE_LDFLAGS),$^) -o $@ $(HALIDE_SYSTEM_LIBS) $(HALIDE_RPATH_FOR_LIB) -I $(SRC)

$(BIN)/retrain_cost_model: $(SRC)/retrain_cost_model.cpp \
$(BIN)/adams2019_retrain_cost_model: $(SRC)/retrain_cost_model.cpp \
$(COMMON_DIR)/ASLog.cpp \
$(SRC)/DefaultCostModel.h \
$(SRC)/DefaultCostModel.cpp \
$(COMMON_DIR)/Weights.h \
$(COMMON_DIR)/Weights.cpp \
$(SRC)/Weights.h \
$(SRC)/Weights.cpp \
$(SRC)/CostModel.h \
$(SRC)/NetworkSize.h \
$(AUTOSCHED_COST_MODEL_LIBS) \
$(AUTOSCHED_WEIGHT_OBJECTS) \
$(BIN)/auto_schedule_runtime.a
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -frtti -Wall -I ../support -I $(BIN)/cost_model $(OPTIMIZE) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(USE_OPEN_MP) $(HALIDE_RPATH_FOR_BIN) -I $(SRC)
$(CXX) $(CXXFLAGS) -frtti -Wall -I ../support -I $(BIN)/adams2019_cost_model $(OPTIMIZE) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(USE_OPEN_MP) $(HALIDE_RPATH_FOR_BIN) -I $(SRC)

$(BIN)/featurization_to_sample: $(COMMON_DIR)/featurization_to_sample.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $< $(OPTIMIZE) -o $@

$(BIN)/get_host_target: $(COMMON_DIR)/get_host_target.cpp $(LIB_HALIDE) $(HALIDE_DISTRIB_PATH)/include/Halide.h
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(filter %.cpp,$^) $(LIBHALIDE_LDFLAGS) $(OPTIMIZE) -o $@ $(HALIDE_RPATH_FOR_BIN)
$(BIN)/weightsdir_to_weightsfile: $(COMMON_DIR)/weightsdir_to_weightsfile.cpp $(COMMON_DIR)/Weights.cpp
$(BIN)/adams2019_weightsdir_to_weightsfile: $(SRC)/weightsdir_to_weightsfile.cpp $(SRC)/Weights.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $^ $(OPTIMIZE) -o $@ -I $(SRC)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fi
echo Training target is: ${HL_TARGET}

if [ -z ${GENERATOR} ]; then
GENERATOR=./bin/demo.generator
GENERATOR=./bin/adams2019_demo.generator
fi

if [ -z ${PIPELINE} ]; then
Expand Down Expand Up @@ -213,7 +213,7 @@ for ((BATCH_ID=$((FIRST+1));BATCH_ID<$((FIRST+1+NUM_BATCHES));BATCH_ID++)); do
echo Retraining model...

find ${SAMPLES} -name "*.sample" | \
${AUTOSCHED_BIN}/retrain_cost_model \
${AUTOSCHED_BIN}/adams2019_retrain_cost_model \
--epochs=${BATCH_SIZE} \
--rates="0.0001" \
--num_cores=32 \
Expand Down
26 changes: 5 additions & 21 deletions src/autoschedulers/anderson2021/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ add_halide_library(anderson2021_train_cost_model FROM anderson2021_cost_model.ge
if (WITH_UTILS)
add_executable(anderson2021_retrain_cost_model
DefaultCostModel.cpp
${COMMON_DIR}/Weights.cpp
Weights.cpp
retrain_cost_model.cpp
$<TARGET_OBJECTS:anderson2021_weights_obj>)
target_include_directories(anderson2021_retrain_cost_model PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/anderson2021")
Expand All @@ -55,7 +55,7 @@ add_autoscheduler(
SearchSpace.cpp
State.cpp
Tiling.cpp
${COMMON_DIR}/Weights.cpp
Weights.cpp
$<TARGET_OBJECTS:anderson2021_weights_obj>
)

Expand All @@ -64,17 +64,9 @@ target_link_libraries(Halide_Anderson2021 PRIVATE ASLog ParamParser
anderson2021_cost_model anderson2021_train_cost_model)

## ====================================================
## Auto-tuning support utilities.
## TODO(#4053): implement auto-tuning support in CMake?

if (WITH_UTILS)
add_executable(anderson2021_featurization_to_sample ${COMMON_DIR}/featurization_to_sample.cpp)

add_executable(anderson2021_get_host_target ${COMMON_DIR}/get_host_target.cpp)
target_link_libraries(anderson2021_get_host_target PRIVATE Halide::Halide)

add_executable(anderson2021_weightsdir_to_weightsfile ${COMMON_DIR}/weightsdir_to_weightsfile.cpp ${COMMON_DIR}/Weights.cpp)
target_include_directories(anderson2021_weightsdir_to_weightsfile PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/anderson2021" ${COMMON_DIR})
add_executable(anderson2021_weightsdir_to_weightsfile weightsdir_to_weightsfile.cpp Weights.cpp)
target_include_directories(anderson2021_weightsdir_to_weightsfile PRIVATE ${COMMON_DIR})
target_link_libraries(anderson2021_weightsdir_to_weightsfile PRIVATE Halide::Runtime)
endif ()

Expand All @@ -83,17 +75,9 @@ endif ()
# which is handled in tests/autoschedulers/anderson2021)

if (WITH_TESTS)

add_executable(anderson2021_test_perfect_hash_map ${COMMON_DIR}/test_perfect_hash_map.cpp)

add_test(NAME anderson2021_test_perfect_hash_map COMMAND test_perfect_hash_map)
set_tests_properties(anderson2021_test_perfect_hash_map
PROPERTIES
LABELS Anderson2021)

##

add_executable(anderson2021_test_function_dag ${COMMON_DIR}/test_function_dag.cpp FunctionDAG.cpp)
add_executable(anderson2021_test_function_dag test_function_dag.cpp FunctionDAG.cpp)
target_include_directories(anderson2021_test_function_dag PRIVATE "${Halide_SOURCE_DIR}/src/autoschedulers/anderson2021")
target_link_libraries(anderson2021_test_function_dag PRIVATE ASLog Halide::Halide Halide::Tools Halide::Plugin)

Expand Down
Loading