diff --git a/CMakeLists.txt b/CMakeLists.txt index 692fb968c596..794c000e7b94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) message(STATUS "Building Python bindings disabled") endif () - option(WITH_APPS "Build apps" ON) + cmake_dependent_option(WITH_APPS "Build apps" ON "BUILD_SHARED_LIBS" OFF) if (WITH_APPS) message(STATUS "Building apps enabled") add_subdirectory(apps) diff --git a/Makefile b/Makefile index a9867a02d292..010ab920e9f3 100644 --- a/Makefile +++ b/Makefile @@ -399,7 +399,6 @@ SOURCE_FILES = \ AssociativeOpsTable.cpp \ Associativity.cpp \ AsyncProducers.cpp \ - AutoSchedule.cpp \ AutoScheduleUtils.cpp \ BoundaryConditions.cpp \ Bounds.cpp \ @@ -573,7 +572,6 @@ HEADER_FILES = \ AssociativeOpsTable.h \ Associativity.h \ AsyncProducers.h \ - AutoSchedule.h \ AutoScheduleUtils.h \ BoundaryConditions.h \ Bounds.h \ @@ -1081,7 +1079,7 @@ test_tutorial: $(TUTORIALS:$(ROOT_DIR)/tutorial/%.cpp=tutorial_%) test_valgrind: $(CORRECTNESS_TESTS:$(ROOT_DIR)/test/correctness/%.cpp=valgrind_%) test_avx512: $(CORRECTNESS_TESTS:$(ROOT_DIR)/test/correctness/%.cpp=avx512_%) test_opengl: $(OPENGL_TESTS:$(ROOT_DIR)/test/opengl/%.cpp=opengl_%) -test_auto_schedule: $(AUTO_SCHEDULE_TESTS:$(ROOT_DIR)/test/auto_schedule/%.cpp=auto_schedule_%) +test_auto_schedule: test_mullapudi2016 test_li2018 test_adams2019 .PHONY: test_correctness_multi_gpu test_correctness_multi_gpu: correctness_gpu_multi_device @@ -1500,9 +1498,15 @@ $(FILTERS_DIR)/external_code.halide_generated.cpp: $(BIN_DIR)/external_code.gene @mkdir -p $(@D) $(CURDIR)/$< -g external_code -e c_source -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime external_code_is_bitcode=false -$(FILTERS_DIR)/autograd_grad.a: $(BIN_DIR)/autograd.generator +$(FILTERS_DIR)/autograd_grad.a: $(BIN_DIR)/autograd.generator $(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(SHARED_EXT) @mkdir -p $(@D) - $(CURDIR)/$< -g autograd $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) -f autograd_grad -d 1 target=$(TARGET)-no_runtime auto_schedule=true + # FIXME: The autoscheduler looks for libHalide in the same + # directory, which is normally a distro. But the generator + # tests use bin/libHalide.so instead of a distro. For now, + # just copy the autoscheduler to a place where it won't + # confuse the linker. + cp $(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(SHARED_EXT) $(BIN_DIR) + $(CURDIR)/$< -g autograd $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) -f autograd_grad target=$(TARGET)-no_runtime auto_schedule=true -d 1 -p $(BIN_DIR)/libautoschedule_mullapudi2016.$(SHARED_EXT) -s Mullapudi2016 # Usually, it's considered best practice to have one Generator per # .cpp file, with the generator-name and filename matching; @@ -1755,11 +1759,13 @@ $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate: $(ROOT_DIR)/tutorial/less # ...in that order. LESSON_21_MACHINE_PARAMS = 32,16777216,40 -$(BIN_DIR)/tutorial_lesson_21_auto_scheduler_run: $(ROOT_DIR)/tutorial/lesson_21_auto_scheduler_run.cpp $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate +$(BIN_DIR)/tutorial_lesson_21_auto_scheduler_run: $(ROOT_DIR)/tutorial/lesson_21_auto_scheduler_run.cpp $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate $(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(SHARED_EXT) @-mkdir -p $(TMP_DIR) # Run the generator $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate -g auto_schedule_gen -o $(TMP_DIR) -e static_library,c_header,schedule -f auto_schedule_false target=host auto_schedule=false - $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate -g auto_schedule_gen -o $(TMP_DIR) -e static_library,c_header,schedule -f auto_schedule_true target=host-no_runtime auto_schedule=true machine_params=$(LESSON_21_MACHINE_PARAMS) + # FIXME: The relative path of the autoscheduler and libHalide must be preserved on OS X, or it tries to load the wrong libHalide.dylib + cp $(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(SHARED_EXT) $(BIN_DIR) + $(BIN_DIR)/tutorial_lesson_21_auto_scheduler_generate -g auto_schedule_gen -o $(TMP_DIR) -e static_library,c_header,schedule -f auto_schedule_true target=host-no_runtime auto_schedule=true machine_params=$(LESSON_21_MACHINE_PARAMS) -p $(BIN_DIR)/libautoschedule_mullapudi2016.$(SHARED_EXT) -s Mullapudi2016 # Compile the runner $(CXX) $(TUTORIAL_CXX_FLAGS) $(IMAGE_IO_CXX_FLAGS) $(OPTIMIZE_FOR_BUILD_TIME) $< \ -I$(INCLUDE_DIR) -L$(BIN_DIR) -I $(TMP_DIR) $(TMP_DIR)/auto_schedule_*.a \ @@ -1847,11 +1853,25 @@ tutorial_%: $(BIN_DIR)/tutorial_% $(TMP_DIR)/images/rgb.png $(TMP_DIR)/images/gr cd $(TMP_DIR) ; $(CURDIR)/$< @-echo -auto_schedule_%: $(BIN_DIR)/auto_schedule_% +test_mullapudi2016: $(AUTO_SCHEDULE_TESTS:$(ROOT_DIR)/test/auto_schedule/%.cpp=auto_schedule_%) + +# These tests were written for the Mullapudi2016 autoscheduler. +# TODO: either make them work with all autoschedulers or move them under src/autoschedulers/mullapudi2016 +auto_schedule_%: $(BIN_DIR)/auto_schedule_% $(BIN_DIR)/libautoschedule_mullapudi2016.$(SHARED_EXT) @-mkdir -p $(TMP_DIR) - cd $(TMP_DIR) ; $(CURDIR)/$< + cd $(TMP_DIR) ; $(CURDIR)/$< $(realpath $(BIN_DIR))/libautoschedule_mullapudi2016.$(SHARED_EXT) @-echo +# The other autoschedulers contain their own tests +test_adams2019: distrib + $(MAKE) -f $(SRC_DIR)/autoschedulers/adams2019/Makefile test \ + HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR) + +test_li2018: distrib build_python_bindings + $(MAKE) -f $(SRC_DIR)/autoschedulers/li2018/Makefile test \ + HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR) \ + HALIDE_PYTHON_BINDINGS_PATH=$(CURDIR)/$(BIN_DIR)/python3_bindings + time_compilation_test_%: $(BIN_DIR)/test_% $(TIME_COMPILATION) compile_times_correctness.csv make -f $(THIS_MAKEFILE) $(@:time_compilation_test_%=test_%) @@ -1866,7 +1886,6 @@ time_compilation_generator_%: $(BIN_DIR)/%.generator TEST_APPS=\ HelloMatlab \ - autoscheduler \ bilateral_grid \ bgu \ blur \ @@ -1874,7 +1893,6 @@ TEST_APPS=\ camera_pipe \ conv_layer \ fft \ - gradient_autoscheduler \ hist \ interpolate \ lens_blur \ @@ -2128,8 +2146,9 @@ $(BUILD_DIR)/halide_config.%: $(ROOT_DIR)/tools/halide_config.%.tpl | sed -e 's;@HALIDE_LLVM_CXX_FLAGS_RAW@;${LLVM_CXX_FLAGS};g' > $@ -$(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \ - $(BIN_DIR)/libHalide.$(SHARED_EXT) \ +$(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT): \ + $(LIB_DIR)/libHalide.a \ + $(BIN_DIR)/libHalide.$(SHARED_EXT) \ $(INCLUDE_DIR)/Halide.h \ $(RUNTIME_EXPORTED_INCLUDES) \ $(ROOT_DIR)/README*.md \ @@ -2143,7 +2162,7 @@ $(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \ $(DISTRIB_DIR)/tutorial/images \ $(DISTRIB_DIR)/tools \ $(DISTRIB_DIR)/tutorial/figures - cp $(BIN_DIR)/libHalide.$(SHARED_EXT) $(DISTRIB_DIR)/bin + cp $(BIN_DIR)/libHalide.$(SHARED_EXT) $(DISTRIB_DIR)/lib cp $(LIB_DIR)/libHalide.a $(DISTRIB_DIR)/lib cp $(INCLUDE_DIR)/Halide.h $(DISTRIB_DIR)/include cp $(INCLUDE_DIR)/HalideBuffer.h $(DISTRIB_DIR)/include @@ -2168,6 +2187,39 @@ $(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \ cp $(ROOT_DIR)/tools/halide_trace_config.h $(DISTRIB_DIR)/tools cp $(ROOT_DIR)/README*.md $(DISTRIB_DIR) cp $(BUILD_DIR)/halide_config.* $(DISTRIB_DIR) +ifeq ($(UNAME), Darwin) + install_name_tool -id @rpath/libHalide.$(SHARED_EXT) $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT) +endif + +$(DISTRIB_DIR)/lib/libautoschedule_%.$(SHARED_EXT): $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT) + $(MAKE) -f $(SRC_DIR)/autoschedulers/$*/Makefile bin/libautoschedule_$*.$(SHARED_EXT) HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR) + cp $(BIN_DIR)/libautoschedule_$*.$(SHARED_EXT) $(DISTRIB_DIR)/lib +ifeq ($(UNAME), Darwin) + install_name_tool -id @rpath/$(@F) $(CURDIR)/$@ +endif + +# Adams2019 also includes autotuning tools +$(DISTRIB_DIR)/lib/libautoschedule_adams2019.$(SHARED_EXT): $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT) + $(MAKE) -f $(SRC_DIR)/autoschedulers/adams2019/Makefile bin/libautoschedule_adams2019.$(SHARED_EXT) HALIDE_DISTRIB_PATH=$(CURDIR)/$(DISTRIB_DIR) bin/retrain_cost_model bin/featurization_to_sample bin/get_host_target + cp $(BIN_DIR)/libautoschedule_adams2019.$(SHARED_EXT) $(DISTRIB_DIR)/lib/ + for TOOL in retrain_cost_model featurization_to_sample get_host_target; do \ + cp $(BIN_DIR)/$${TOOL} $(DISTRIB_DIR)/bin/; \ + done + cp $(SRC_DIR)/autoschedulers/adams2019/autotune_loop.sh $(DISTRIB_DIR)/tools/ +ifeq ($(UNAME), Darwin) + install_name_tool -id @rpath/$(@F) $(CURDIR)/$@ +endif + +.PHONY: autoschedulers +autoschedulers: \ +$(DISTRIB_DIR)/lib/libautoschedule_mullapudi2016.$(SHARED_EXT) \ +$(DISTRIB_DIR)/lib/libautoschedule_li2018.$(SHARED_EXT) \ +$(DISTRIB_DIR)/lib/libautoschedule_adams2019.$(SHARED_EXT) + +.PHONY: distrib +distrib: $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT) autoschedulers + +$(DISTRIB_DIR)/halide.tgz: distrib ln -sf $(DISTRIB_DIR) halide tar -czf $(BUILD_DIR)/halide.tgz \ halide/bin \ @@ -2180,10 +2232,6 @@ $(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \ rm -rf halide mv $(BUILD_DIR)/halide.tgz $(DISTRIB_DIR)/halide.tgz - -.PHONY: distrib -distrib: $(DISTRIB_DIR)/halide.tgz - $(BIN_DIR)/HalideTraceViz: $(ROOT_DIR)/util/HalideTraceViz.cpp $(INCLUDE_DIR)/HalideRuntime.h $(ROOT_DIR)/tools/halide_image_io.h $(ROOT_DIR)/tools/halide_trace_config.h $(CXX) $(OPTIMIZE) -std=c++11 $(filter %.cpp,$^) -I$(INCLUDE_DIR) -I$(ROOT_DIR)/tools -L$(BIN_DIR) -o $@ diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 53ea697cda23..db7c90f1335a 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -26,7 +26,7 @@ function(add_app_test NAME) return() endif () - unset(cmakeToolchainOpts) + set(cmakeToolchainOpts "") if (NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") list(APPEND cmakeToolchainOpts "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") if (NOT "${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" STREQUAL "") @@ -34,7 +34,7 @@ function(add_app_test NAME) endif () endif () - unset(cmakeGenOpts) + set(cmakeGenOpts "") if (NOT "${CMAKE_GENERATOR_TOOLSET}" STREQUAL "") list(APPEND cmakeGenOpts --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}") endif () @@ -89,12 +89,3 @@ add_app_test(resize) add_app_test(stencil_chain) add_app_test(unsharp) add_app_test(wavelet) - -# Add the autoschedulers. -# TODO(#4053): refactor into separate modules -if (TARGET_WEBASSEMBLY AND Halide_TARGET MATCHES "wasm") - # Don't attempt to build these for wasm yet. -else () - add_subdirectory(autoscheduler) - add_subdirectory(gradient_autoscheduler) -endif () diff --git a/apps/autoscheduler/Makefile b/apps/autoscheduler/Makefile deleted file mode 100644 index 908717fc836c..000000000000 --- a/apps/autoscheduler/Makefile +++ /dev/null @@ -1,130 +0,0 @@ -include ../support/Makefile.inc -include ../support/autoscheduler.inc - -# A sample generator to autoschedule. Note that if it statically links -# to libHalide, then it must be build with $(USE_EXPORT_DYNAMIC), or the -# autoscheduler can't find the libHalide symbols that it needs. -$(GENERATOR_BIN)/demo.generator: demo_generator.cpp $(GENERATOR_DEPS) - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS) - -# To use the autoscheduler, set a few environment variables and use the -p flag to the generator to load the autoscheduler as a plugin -$(BIN)/%/demo.a: $(GENERATOR_BIN)/demo.generator $(AUTOSCHED_BIN)/libauto_schedule.so - @mkdir -p $(@D) - HL_WEIGHTS_DIR=$(AUTOSCHED_SRC)/baseline.weights \ - $(GENERATOR_BIN)/demo.generator -g demo -o $(@D) -f demo target=$* auto_schedule=true -p $(AUTOSCHED_BIN)/libauto_schedule.so -s Adams2019 - -$(BIN)/%/demo.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/demo.registration.cpp $(BIN)/%/demo.a - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) - -# demonstrates single-shot use of the autoscheduler -demo: $(BIN)/$(HL_TARGET)/demo.rungen $(AUTOSCHED_BIN)/libauto_schedule.so - $< --benchmarks=all --benchmark_min_time=1 --estimate_all - -# demonstrates an autotuning loop -# (using $(AUTOSCHED_BIN) and $(AUTOSCHED_SRC) here seems overkill, but makes copy-n-paste elsewhere easier) -autotune: $(GENERATOR_BIN)/demo.generator $(AUTOSCHED_BIN)/featurization_to_sample $(AUTOSCHED_BIN)/get_host_target $(AUTOSCHED_BIN)/retrain_cost_model $(AUTOSCHED_BIN)/libauto_schedule.so $(AUTOSCHED_SRC)/autotune_loop.sh - bash $(AUTOSCHED_SRC)/autotune_loop.sh \ - $(GENERATOR_BIN)/demo.generator \ - demo \ - "" \ - $(AUTOSCHED_SRC)/baseline.weights \ - $(AUTOSCHED_BIN) \ - $(HALIDE_DISTRIB_PATH) \ - $(AUTOSCHED_SAMPLES_OUT) - -$(BIN)/test_perfect_hash_map: test_perfect_hash_map.cpp PerfectHashMap.h - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $< -o $@ - -$(BIN)/test_function_dag: test_function_dag.cpp FunctionDAG.h FunctionDAG.cpp ASLog.h ASLog.cpp - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -# Simple jit-based test -$(BIN)/%/test: test.cpp $(AUTOSCHED_BIN)/libauto_schedule.so - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $^ -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -test_perfect_hash_map: $(BIN)/test_perfect_hash_map - $^ - -test_function_dag: $(BIN)/test_function_dag - $^ - -run_test: $(BIN)/$(HL_TARGET)/test - HL_WEIGHTS_DIR=$(AUTOSCHED_SRC)/baseline.weights LD_LIBRARY_PATH=$(AUTOSCHED_BIN) $< - -.PHONY: test clean - -# Note that when running the *test*, we want to ensure that we generate samples -# to a subdir of $(BIN), so that they don't get inadvertently generated into -# our source tree. (Normally we want samples/ to be retained, to avoid data loss; -# for the test target, however, it's imperative it go into a transitory directory, -# to avoid eventually consuming all disk space on the buildbot...) -test: AUTOSCHED_SAMPLES_OUT = $(BIN)/test_samples_out - -# Note that 'make build' and 'make test' is used by Halide buildbots -# to spot-check changes, so it's important to try a little of each of -# the important paths here, including single-shot and autotune-loop -build: $(BIN)/$(HL_TARGET)/test \ - $(BIN)/test_perfect_hash_map \ - $(BIN)/test_function_dag \ - $(BIN)/$(HL_TARGET)/included_schedule_file.rungen \ - $(GENERATOR_BIN)/demo.generator \ - $(AUTOSCHED_BIN)/featurization_to_sample \ - $(AUTOSCHED_BIN)/get_host_target \ - $(AUTOSCHED_BIN)/retrain_cost_model \ - $(AUTOSCHED_BIN)/libauto_schedule.so - -test: run_test test_perfect_hash_map test_function_dag demo included_schedule_file autotune - -clean: - rm -rf $(BIN) - -# A sample generator to demonstrate including autogenerated .sample.h -# files for scheduling purposes; the catch here is that we'll need -# to be able to compile the Generator two different ways: -# -# - one that will be used to generate the .schedule.h -# - one that will consume the .schedule.h generated above -# -# We'll use the preprocessor (GENERATING_SCHEDULE) to distinguish between these two. - -$(GENERATOR_BIN)/included_schedule_file_none.generator: included_schedule_file_generator.cpp $(GENERATOR_DEPS) - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -DGENERATING_SCHEDULE -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -# This is the target you build to (re)generate the schedule file. -# (Note that we only need the schedule output, so we pass `-e schedule` to -# the Generator so that it can skip producing other outputs.) -$(BIN)/%/included_schedule_file.schedule.h: $(GENERATOR_BIN)/included_schedule_file_none.generator $(AUTOSCHED_BIN)/libauto_schedule.so - @mkdir -p $(@D) - HL_WEIGHTS_DIR=$(AUTOSCHED_SRC)/baseline.weights \ - $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$* auto_schedule=true -p $(AUTOSCHED_BIN)/libauto_schedule.so -s Adams2019 -e schedule - -# Note that this depends on included_schedule_file.schedule.h rather than $(BIN)/%/included_schedule_file.schedule.h -- -# the former should be generated by something like -# -# make bin/host/included_schedule_file.schedule.h -# cp bin/host/included_schedule_file.schedule.h included_schedule_file.schedule.h -# -$(GENERATOR_BIN)/included_schedule_file.generator: included_schedule_file_generator.cpp included_schedule_file.schedule.h $(GENERATOR_DEPS) - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -# Note that this does not depend on libauto_schedule nor does it call -# the autoscheduler at build time; it includes the generated schedule (included_schedule_file.schedule.h), -# which has been added to our local source control. -$(BIN)/%/included_schedule_file.a: $(GENERATOR_BIN)/included_schedule_file.generator - @mkdir -p $(@D) - $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$* - -$(BIN)/%/included_schedule_file.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/included_schedule_file.registration.cpp $(BIN)/%/included_schedule_file.a - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) - -included_schedule_file: $(BIN)/$(HL_TARGET)/included_schedule_file.rungen - $^ --benchmarks=all --benchmark_min_time=1 --estimate_all - diff --git a/apps/bgu/CMakeLists.txt b/apps/bgu/CMakeLists.txt index e22e15299ef1..ffba5714d889 100644 --- a/apps/bgu/CMakeLists.txt +++ b/apps/bgu/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(bgu.generator PRIVATE Halide::Generator Halide::Tools) add_halide_library(bgu FROM bgu.generator) add_halide_library(bgu_auto_schedule FROM bgu.generator GENERATOR bgu - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(bgu_filter filter.cpp) diff --git a/apps/bilateral_grid/CMakeLists.txt b/apps/bilateral_grid/CMakeLists.txt index 6244696b581d..ffab600382da 100644 --- a/apps/bilateral_grid/CMakeLists.txt +++ b/apps/bilateral_grid/CMakeLists.txt @@ -24,7 +24,7 @@ add_halide_library(bilateral_grid_auto_schedule FROM bilateral_grid.generator GENERATOR bilateral_grid STMT bilateral_grid_auto_schedule_STMT SCHEDULE bilateral_grid_auto_schedule_SCHEDULE - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(bilateral_grid_process filter.cpp) diff --git a/apps/camera_pipe/CMakeLists.txt b/apps/camera_pipe/CMakeLists.txt index c06422745581..35f6de32dfbe 100644 --- a/apps/camera_pipe/CMakeLists.txt +++ b/apps/camera_pipe/CMakeLists.txt @@ -22,7 +22,7 @@ target_link_libraries(camera_pipe.generator add_halide_library(camera_pipe FROM camera_pipe.generator) add_halide_library(camera_pipe_auto_schedule FROM camera_pipe.generator GENERATOR camera_pipe - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(camera_pipe_process process.cpp) diff --git a/apps/conv_layer/CMakeLists.txt b/apps/conv_layer/CMakeLists.txt index 5b074701b1bc..fbc70d5494b1 100644 --- a/apps/conv_layer/CMakeLists.txt +++ b/apps/conv_layer/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(conv_layer.generator add_halide_library(conv_layer FROM conv_layer.generator) add_halide_library(conv_layer_auto_schedule FROM conv_layer.generator GENERATOR conv_layer - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(conv_layer_process process.cpp) diff --git a/apps/depthwise_separable_conv/CMakeLists.txt b/apps/depthwise_separable_conv/CMakeLists.txt index 2eae5db79820..8907777cb0fa 100644 --- a/apps/depthwise_separable_conv/CMakeLists.txt +++ b/apps/depthwise_separable_conv/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(depthwise_separable_conv.generator add_halide_library(depthwise_separable_conv FROM depthwise_separable_conv.generator) add_halide_library(depthwise_separable_conv_auto_schedule FROM depthwise_separable_conv.generator GENERATOR depthwise_separable_conv - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(depthwise_separable_conv_process process.cpp) diff --git a/apps/gradient_autoscheduler/ASLog.cpp b/apps/gradient_autoscheduler/ASLog.cpp deleted file mode 100644 index 601ceabd3c71..000000000000 --- a/apps/gradient_autoscheduler/ASLog.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "ASLog.h" - -namespace Halide { -namespace Internal { - -namespace { - -std::string get_env_variable(char const *env_var_name) { - if (!env_var_name) { - return ""; - } - -#ifdef _MSC_VER - // call getenv_s without a buffer to determine the correct string length: - size_t length = 0; - if ((getenv_s(&length, NULL, 0, env_var_name) != 0) || (length == 0)) { - return ""; - } - // call it again to retrieve the value of the environment variable; - // note that 'length' already accounts for the null-terminator - std::string lvl(length - 1, '@'); - size_t read = 0; - if ((getenv_s(&read, &lvl[0], length, env_var_name) != 0) || (read != length)) { - return ""; - } - return lvl; -#else - char *lvl = getenv(env_var_name); - if (lvl) return std::string(lvl); -#endif - - return ""; -} - -} // namespace - -int aslog::aslog_level() { - static int cached_aslog_level = ([]() -> int { - // If HL_DEBUG_AUTOSCHEDULE is defined, use that value. - std::string lvl = get_env_variable("HL_DEBUG_AUTOSCHEDULE"); - if (!lvl.empty()) { - return atoi(lvl.c_str()); - } - // Otherwise, use HL_DEBUG_CODEGEN. - lvl = get_env_variable("HL_DEBUG_CODEGEN"); - return !lvl.empty() ? atoi(lvl.c_str()) : 0; - })(); - return cached_aslog_level; -} - -} // namespace Internal -} // namespace Halide diff --git a/apps/gradient_autoscheduler/ASLog.h b/apps/gradient_autoscheduler/ASLog.h deleted file mode 100644 index 9ba9844ce342..000000000000 --- a/apps/gradient_autoscheduler/ASLog.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef ASLOG_H -#define ASLOG_H - -// This class is used by train_cost_model, which doesn't link to -// libHalide, so (despite the namespace) we are better off not -// including Halide.h, lest we reference something we won't have available - -#include -#include -#include - -namespace Halide { -namespace Internal { - -class aslog { - const bool logging; - -public: - aslog(int verbosity) - : logging(verbosity <= aslog_level()) { - } - - template - aslog &operator<<(T &&x) { - if (logging) { - std::cerr << std::forward(x); - } - return *this; - } - - static int aslog_level(); -}; - -} // namespace Internal -} // namespace Halide - -#endif diff --git a/apps/gradient_autoscheduler/CMakeLists.txt b/apps/gradient_autoscheduler/CMakeLists.txt deleted file mode 100644 index 909d25fd99ac..000000000000 --- a/apps/gradient_autoscheduler/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -# ================================================================================ -# Halide autoscheduler plugins rely on weak linking to work with static libraries. -# This is not standard C++ and only works on Linux / macOS. Nothing special needs -# to be done when linking to a shared version of Halide, however. - -if (NOT BUILD_SHARED_LIBS) - if (MSVC) - message(WARNING "Autoscheduler plugins cannot be built against static Halide on Windows") - return() - endif () - - # Need to enable exports for the plugins to find Halide's symbols. - set(CMAKE_ENABLE_EXPORTS ON) -endif () - -# ================================= -# Define the autoscheduler library. - -add_library(Halide_Li2018 MODULE GradientAutoscheduler.cpp ASLog.cpp) -add_library(Halide::Li2018 ALIAS Halide_Li2018) -set_target_properties(Halide_Li2018 PROPERTIES - EXPORT_NAME Li2018 - OUTPUT_NAME gradient_autoscheduler) - -target_link_libraries(Halide_Li2018 PRIVATE Halide::Plugin) - -if (NOT Halide_ENABLE_RTTI) - target_compile_options(Halide_Li2018 PRIVATE - $<$:/GR-> - $<$,$>>:-fno-rtti>) -endif () - -# ========================================================== -# TODO(#4053): move these to a separate folder since they're tests. - -add_executable(demo_gradient.generator demo_generator.cpp) -target_link_libraries(demo_gradient.generator PRIVATE Halide::Generator) - -add_halide_library(demo_gradient FROM demo_gradient.generator - GENERATOR demo - FUNCTION_NAME demo - PARAMS auto_schedule=true - AUTOSCHEDULER Halide::Li2018 - REGISTRATION DEMO_REGISTRATION_FILE) - -add_executable(demo_gradient_autoscheduler ${DEMO_REGISTRATION_FILE}) -target_link_libraries(demo_gradient_autoscheduler PRIVATE demo_gradient Halide::RunGenMain) - -add_test(NAME demo_gradient_autoscheduler - COMMAND demo_gradient_autoscheduler --benchmarks=all --benchmark_min_time=1 --estimate_all) - -set_tests_properties(demo_gradient_autoscheduler PROPERTIES LABELS Li2018) - -## - -# Hack to include all symbols in the gradient autoscheduler test. -# DerivativeUtils.h/inference_bounds is not used elsewhere and so doesn't get linked to the test. -unset(WHOLE_ARCHIVE) -unset(NO_WHOLE_ARCHIVE) -if (NOT BUILD_SHARED_LIBS) - set(WHOLE_ARCHIVE $<$:-Wl,-whole-archive> $<$:-Wl,-all_load>) - set(NO_WHOLE_ARCHIVE $<$:-Wl,-no-whole-archive> $<$:-Wl,-noall_load>) -endif () - -add_executable(gradient_autoscheduler_test_cpp test.cpp) -target_link_libraries(gradient_autoscheduler_test_cpp PRIVATE ${WHOLE_ARCHIVE} Halide::Halide ${NO_WHOLE_ARCHIVE}) - -add_test(NAME gradient_autoscheduler_test_cpp - COMMAND gradient_autoscheduler_test_cpp - WORKING_DIRECTORY $) - -set_tests_properties(gradient_autoscheduler_test_cpp PROPERTIES - LABELS Li2018 - ENVIRONMENT "LD_LIBRARY_PATH=$") - -## - -if (WITH_PYTHON_BINDINGS) - # TODO(#4053): rework this as an app under python_bindings. - # TODO(#4876): Disabled due to issue #4876 - if (FALSE) - find_package(Python3 REQUIRED COMPONENTS Interpreter Development) - - add_test(NAME gradient_autoscheduler_test_py - COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/test.py") - - set(PYTHONPATH "$>") - - if (WIN32) - set(SEP "\\$") - else () - set(SEP ":") - endif () - - set(_PATH "$>;$>;$ENV{PATH}") - string(REPLACE ";" "${SEP}" _PATH "${_PATH}") - set_tests_properties(gradient_autoscheduler_test_py PROPERTIES - LABELS Li2018 - ENVIRONMENT "PYTHONPATH=${PYTHONPATH};PATH=${_PATH}") - endif () -endif () diff --git a/apps/gradient_autoscheduler/Errors.h b/apps/gradient_autoscheduler/Errors.h deleted file mode 100644 index 0057b2fbc3a9..000000000000 --- a/apps/gradient_autoscheduler/Errors.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ERRORS_H -#define ERRORS_H - -#include "Halide.h" - -#ifndef user_error -#define user_error Halide::Internal::ErrorReport(__FILE__, __LINE__, nullptr, Halide::Internal::ErrorReport::User) -#endif - -#ifndef user_warning -#define user_warning Halide::Internal::ErrorReport(__FILE__, __LINE__, nullptr, Halide::Internal::ErrorReport::User | Halide::Internal::ErrorReport::Warning) -#endif - -#ifndef user_assert -#define user_assert(c) _halide_internal_assertion(c, Halide::Internal::ErrorReport::User) -#endif - -#ifndef internal_assert -#define internal_assert(c) _halide_internal_assertion(c, 0) -#endif - -#ifndef internal_error -#define internal_error Halide::Internal::ErrorReport(__FILE__, __LINE__, nullptr, 0) -#endif - -#endif diff --git a/apps/gradient_autoscheduler/Makefile b/apps/gradient_autoscheduler/Makefile deleted file mode 100644 index e782f2bf2c26..000000000000 --- a/apps/gradient_autoscheduler/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -include ../support/Makefile.inc - -$(BIN)/libgradient_autoscheduler.so: GradientAutoscheduler.cpp ASLog.cpp $(LIB_HALIDE) - @mkdir -p $(@D) - $(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) $^ -o $@ $(HALIDE_SYSTEM_LIBS) - -# Demonstrate a JIT-based use of gradient autoscheuler -$(BIN)/test: test.cpp $(BIN)/libgradient_autoscheduler.so - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) test.cpp -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -# Demonstrate a generator-based use of gradient autoscheuler -$(GENERATOR_BIN)/demo.generator: demo_generator.cpp $(GENERATOR_DEPS) - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) - -# Use the -p flag to the generator to load the autoscheduler as a plugin -$(BIN)/%/demo.a: $(GENERATOR_BIN)/demo.generator $(BIN)/libgradient_autoscheduler.so - @mkdir -p $(@D) - $(GENERATOR_BIN)/demo.generator -g demo -o $(@D) -f demo target=$* auto_schedule=true -p $(BIN)/libgradient_autoscheduler.so -s Li2018 - -$(BIN)/%/demo.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/demo.registration.cpp $(BIN)/%/demo.a - @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) - -.PHONY: build test clean run_test_cpp run_test_py test_generator - -# demonstrates single-shot use of the autoscheduler -test_generator: $(BIN)/$(HL_TARGET)/demo.rungen $(BIN)/libgradient_autoscheduler.so - $< --benchmarks=all --benchmark_min_time=1 --estimate_all - -run_test_cpp: $(BIN)/test - LD_LIBRARY_PATH=$(BIN) $< - -run_test_py: test.py $(BIN)/libgradient_autoscheduler.so - PYTHONPATH=$(BIN):$(HALIDE_PYTHON_BINDINGS_PATH):$(HALIDE_DISTRIB_PATH)/bin:$$PYTHONPATH \ - LD_LIBRARY_PATH=$(BIN):$(HALIDE_PYTHON_BINDINGS_PATH):$(HALIDE_DISTRIB_PATH)/bin \ - $(PYTHON) test.py - -build: $(BIN)/test $(BIN)/$(HL_TARGET)/demo.rungen $(BIN)/libgradient_autoscheduler.so - -test: run_test_cpp run_test_py test_generator - -clean: - rm -rf $(BIN) diff --git a/apps/harris/CMakeLists.txt b/apps/harris/CMakeLists.txt index f409834dc17c..a61a0c0fcd67 100644 --- a/apps/harris/CMakeLists.txt +++ b/apps/harris/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(harris.generator PRIVATE Halide::Generator Halide::Tools) add_halide_library(harris FROM harris.generator) add_halide_library(harris_auto_schedule FROM harris.generator GENERATOR harris - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(harris_filter filter.cpp) diff --git a/apps/hist/CMakeLists.txt b/apps/hist/CMakeLists.txt index bbef5aef6d84..94db41663980 100644 --- a/apps/hist/CMakeLists.txt +++ b/apps/hist/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(hist.generator PRIVATE Halide::Generator Halide::Tools) add_halide_library(hist FROM hist.generator) add_halide_library(hist_auto_schedule FROM hist.generator GENERATOR hist - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(hist_filter filter.cpp) diff --git a/apps/iir_blur/CMakeLists.txt b/apps/iir_blur/CMakeLists.txt index 196f4410e16d..a2c39634c058 100644 --- a/apps/iir_blur/CMakeLists.txt +++ b/apps/iir_blur/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(iir_blur.generator PRIVATE Halide::Generator) add_halide_library(iir_blur FROM iir_blur.generator) add_halide_library(iir_blur_auto_schedule FROM iir_blur.generator GENERATOR iir_blur - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(iir_blur_filter filter.cpp) diff --git a/apps/interpolate/CMakeLists.txt b/apps/interpolate/CMakeLists.txt index c1464867da50..207597384e5b 100644 --- a/apps/interpolate/CMakeLists.txt +++ b/apps/interpolate/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(interpolate.generator PRIVATE Halide::Generator Halide::To add_halide_library(interpolate FROM interpolate.generator) add_halide_library(interpolate_auto_schedule FROM interpolate.generator GENERATOR interpolate - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(interpolate_filter filter.cpp) diff --git a/apps/lens_blur/CMakeLists.txt b/apps/lens_blur/CMakeLists.txt index 5d5add734655..8515d77f40b7 100644 --- a/apps/lens_blur/CMakeLists.txt +++ b/apps/lens_blur/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(lens_blur.generator PRIVATE Halide::Generator Halide::Tool add_halide_library(lens_blur FROM lens_blur.generator) add_halide_library(lens_blur_auto_schedule FROM lens_blur.generator GENERATOR lens_blur - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(lens_blur_filter process.cpp) diff --git a/apps/linear_algebra/CMakeLists.txt b/apps/linear_algebra/CMakeLists.txt index 60af2f407c48..2d649e0ec684 100644 --- a/apps/linear_algebra/CMakeLists.txt +++ b/apps/linear_algebra/CMakeLists.txt @@ -12,8 +12,8 @@ set(CMAKE_CXX_EXTENSIONS NO) find_package(Halide REQUIRED COMPONENTS Halide) # Find BLAS-es -unset(DEFAULT_BLAS) -unset(BLAS_TARGETS) +set(DEFAULT_BLAS "") +set(BLAS_TARGETS "") set(BLAS_VENDORS OpenBLAS ATLAS Apple Generic) # ATLAS is weird and has extra requirements diff --git a/apps/local_laplacian/CMakeLists.txt b/apps/local_laplacian/CMakeLists.txt index a816551342b5..4b6ab9384e6b 100644 --- a/apps/local_laplacian/CMakeLists.txt +++ b/apps/local_laplacian/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(local_laplacian.generator PRIVATE Halide::Generator Halide add_halide_library(local_laplacian FROM local_laplacian.generator) add_halide_library(local_laplacian_auto_schedule FROM local_laplacian.generator GENERATOR local_laplacian - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(local_laplacian_process process.cpp) diff --git a/apps/max_filter/CMakeLists.txt b/apps/max_filter/CMakeLists.txt index ff2486b5ef59..35aabf94e9a3 100644 --- a/apps/max_filter/CMakeLists.txt +++ b/apps/max_filter/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(max_filter.generator PRIVATE Halide::Generator Halide::Too add_halide_library(max_filter FROM max_filter.generator) add_halide_library(max_filter_auto_schedule FROM max_filter.generator GENERATOR max_filter - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(max_filter_filter filter.cpp) diff --git a/apps/nl_means/CMakeLists.txt b/apps/nl_means/CMakeLists.txt index d09f0d0d31d8..274bb1d2abd7 100644 --- a/apps/nl_means/CMakeLists.txt +++ b/apps/nl_means/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(nl_means.generator PRIVATE Halide::Generator Halide::Tools add_halide_library(nl_means FROM nl_means.generator) add_halide_library(nl_means_auto_schedule FROM nl_means.generator GENERATOR nl_means - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(nl_means_process process.cpp) diff --git a/apps/stencil_chain/CMakeLists.txt b/apps/stencil_chain/CMakeLists.txt index 0efebaf63c98..4dbcd508d89a 100644 --- a/apps/stencil_chain/CMakeLists.txt +++ b/apps/stencil_chain/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(stencil_chain.generator PRIVATE Halide::Generator Halide:: add_halide_library(stencil_chain FROM stencil_chain.generator) add_halide_library(stencil_chain_auto_schedule FROM stencil_chain.generator GENERATOR stencil_chain - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(stencil_chain_process process.cpp) diff --git a/apps/support/Makefile.inc b/apps/support/Makefile.inc index a0865f86aaae..cf8203da1011 100644 --- a/apps/support/Makefile.inc +++ b/apps/support/Makefile.inc @@ -124,14 +124,25 @@ LDFLAGS-arm-32-android ?= -llog -fPIE -pie LIB_HALIDE_STATIC = $(HALIDE_DISTRIB_PATH)/lib/libHalide.a -LIB_HALIDE = $(HALIDE_DISTRIB_PATH)/bin/libHalide.$(SHARED_EXT) +LIB_HALIDE = $(HALIDE_DISTRIB_PATH)/lib/libHalide.$(SHARED_EXT) -GENERATOR_DEPS ?= $(LIB_HALIDE) $(HALIDE_DISTRIB_PATH)/include/Halide.h $(HALIDE_DISTRIB_PATH)/tools/GenGen.cpp +GENERATOR_DEPS ?= $(LIB_AUTOSCHEDULER) $(LIB_HALIDE) $(HALIDE_DISTRIB_PATH)/include/Halide.h $(HALIDE_DISTRIB_PATH)/tools/GenGen.cpp GENERATOR_DEPS_STATIC ?= $(LIB_HALIDE_STATIC) $(HALIDE_DISTRIB_PATH)/include/Halide.h $(HALIDE_DISTRIB_PATH)/tools/GenGen.cpp # Generators which use autoscheduler plugin need to specify the linker where to find libHalide.so required by the plugin. LIBHALIDE_LDFLAGS ?= -Wl,-rpath,$(dir $(LIB_HALIDE)) -L $(dir $(LIB_HALIDE)) -lHalide $(LDFLAGS) -LIBHALIDE_LDFLAGS_STATIC ?= -L $(dir $(LIB_HALIDE_STATIC)) -lHalide $(LDFLAGS) +LIBHALIDE_LDFLAGS_STATIC ?= $(LIB_HALIDE_STATIC) $(LDFLAGS) + +# Autoschedulers. Mullapudi2016 is currently the default, because it's fast. +AUTOSCHEDULER ?= mullapudi2016 +ifneq ($(AUTOSCHEDULER),) +LIB_AUTOSCHEDULER ?= $(HALIDE_DISTRIB_PATH)/lib/libautoschedule_$(AUTOSCHEDULER).$(SHARED_EXT) +ifeq ($(UNAME), Darwin) +LIBHALIDE_LDFLAGS += -Wl,-force_load $(HALIDE_DISTRIB_PATH)/lib/libautoschedule_$(AUTOSCHEDULER).$(SHARED_EXT) +else +LIBHALIDE_LDFLAGS += -Wl,--no-as-needed -lautoschedule_$(AUTOSCHEDULER) -Wl,--as-needed +endif +endif LIBPNG_LIBS_DEFAULT = $(shell libpng-config --ldflags) LIBPNG_CXX_FLAGS ?= $(shell libpng-config --cflags) diff --git a/apps/support/viz_auto.sh b/apps/support/viz_auto.sh old mode 100644 new mode 100755 diff --git a/apps/unsharp/CMakeLists.txt b/apps/unsharp/CMakeLists.txt index 222c15d36142..4221f1fa24eb 100644 --- a/apps/unsharp/CMakeLists.txt +++ b/apps/unsharp/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(unsharp.generator PRIVATE Halide::Generator Halide::Tools) add_halide_library(unsharp FROM unsharp.generator) add_halide_library(unsharp_auto_schedule FROM unsharp.generator GENERATOR unsharp - PARAMS auto_schedule=true) + AUTOSCHEDULER Halide::Mullapudi2016) # Main executable add_executable(unsharp_filter filter.cpp) diff --git a/cmake/BundleStatic.cmake b/cmake/BundleStatic.cmake index da250c56a3e5..1a834c528552 100644 --- a/cmake/BundleStatic.cmake +++ b/cmake/BundleStatic.cmake @@ -183,7 +183,7 @@ function(transfer_locations) message(VERBOSE "Transferring ${languages}[${cfg}] objects from ${lib} to ${ARG_TO}") - unset(globs) + set(globs "") foreach (lang IN LISTS languages) list(APPEND globs "${stage}/*${CMAKE_${lang}_OUTPUT_EXTENSION}") endforeach () diff --git a/cmake/HalideGeneratorHelpers.cmake b/cmake/HalideGeneratorHelpers.cmake index a6cc2e41d0b3..7b431d19f395 100644 --- a/cmake/HalideGeneratorHelpers.cmake +++ b/cmake/HalideGeneratorHelpers.cmake @@ -177,18 +177,22 @@ function(add_halide_library TARGET) # Attach an autoscheduler if the user requested it ## - unset(GEN_AUTOSCHEDULER) + set(GEN_AUTOSCHEDULER "") if (ARG_AUTOSCHEDULER) - if ("${ARG_AUTOSCHEDULER}" MATCHES "::" AND TARGET "${ARG_AUTOSCHEDULER}") + if ("${ARG_AUTOSCHEDULER}" MATCHES "::") + if (NOT TARGET "${ARG_AUTOSCHEDULER}") + message(FATAL_ERROR "Autoscheduler ${ARG_AUTOSCHEDULER} does not exist.") + endif () + # Convention: if the argument names a target like "Namespace::Scheduler" then # it is assumed to be a MODULE target providing a scheduler named "Scheduler". list(APPEND ARG_PLUGINS "${ARG_AUTOSCHEDULER}") string(REGEX REPLACE ".*::(.*)" "\\1" ARG_AUTOSCHEDULER "${ARG_AUTOSCHEDULER}") elseif (NOT ARG_PLUGINS) - # TODO(#4053): this is spurious when the default autoscheduler is requested message(AUTHOR_WARNING "AUTOSCHEDULER set to a scheduler name but no plugins were loaded") endif () set(GEN_AUTOSCHEDULER -s "${ARG_AUTOSCHEDULER}") + list(PREPEND ARG_PARAMS auto_schedule=true) endif () ## @@ -207,7 +211,7 @@ function(add_halide_library TARGET) endif () # Load the plugins and setup dependencies - unset(GEN_PLUGINS) + set(GEN_PLUGINS "") if (ARG_PLUGINS) foreach (p IN LISTS ARG_PLUGINS) list(APPEND GEN_PLUGINS "$") @@ -254,7 +258,7 @@ function(_Halide_add_halide_runtime RT) if (crosscompiling) set(GEN_OUTS "${RT}${static_library_suffix}") - unset(GEN_ARGS) + set(GEN_ARGS "") else () set(GEN_OUTS "${RT}${object_suffix}") set(GEN_ARGS -e object) diff --git a/cmake/HalideTestHelpers.cmake b/cmake/HalideTestHelpers.cmake index d049d5cf004b..7fe18e35630e 100644 --- a/cmake/HalideTestHelpers.cmake +++ b/cmake/HalideTestHelpers.cmake @@ -38,7 +38,7 @@ endif () function(add_halide_test TARGET) set(options EXPECT_FAILURE) set(oneValueArgs WORKING_DIRECTORY) - set(multiValueArgs GROUPS COMMAND) + set(multiValueArgs GROUPS COMMAND ARGS) cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if (NOT args_COMMAND) @@ -46,17 +46,15 @@ function(add_halide_test TARGET) endif () add_test(NAME ${TARGET} - COMMAND ${args_COMMAND} + COMMAND ${args_COMMAND} ${args_ARGS} WORKING_DIRECTORY "${args_WORKING_DIRECTORY}") set_tests_properties(${TARGET} PROPERTIES LABELS "${args_GROUPS}" ENVIRONMENT "HL_TARGET=${Halide_TARGET};HL_JIT_TARGET=${Halide_TARGET}" PASS_REGULAR_EXPRESSION "Success!" - SKIP_REGULAR_EXPRESSION "\\[SKIP\\]") - if (${args_EXPECT_FAILURE}) - set_tests_properties(${TARGET} PROPERTIES WILL_FAIL true) - endif () + SKIP_REGULAR_EXPRESSION "\\[SKIP\\]" + WILL_FAIL ${args_EXPECT_FAILURE}) # Add a meta-target for each group, to allow us to build by group easily foreach (GROUP IN LISTS args_GROUPS) @@ -72,7 +70,7 @@ endfunction() function(tests) set(options EXPECT_FAILURE) set(oneValueArgs) - set(multiValueArgs SOURCES GROUPS) + set(multiValueArgs SOURCES GROUPS ARGS) cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) list(GET args_GROUPS 0 PRIMARY_GROUP) @@ -91,10 +89,10 @@ function(tests) endif () if (args_EXPECT_FAILURE) - add_halide_test("${TARGET}" GROUPS ${args_GROUPS} EXPECT_FAILURE) + add_halide_test("${TARGET}" ARGS ${args_ARGS} GROUPS ${args_GROUPS} EXPECT_FAILURE) target_link_libraries("${TARGET}" PRIVATE Halide::ExpectAbort) else () - add_halide_test("${TARGET}" GROUPS ${args_GROUPS}) + add_halide_test("${TARGET}" ARGS ${args_ARGS} GROUPS ${args_GROUPS}) endif () endforeach () diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt index 3f6835b3e62f..b2ae240a8bf0 100644 --- a/packaging/CMakeLists.txt +++ b/packaging/CMakeLists.txt @@ -24,9 +24,14 @@ endforeach () # Main library exports ## -# TODO(#4053): add autoschedulers when refactored +set(optional_targets "") +foreach (target IN ITEMS Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016) + if (TARGET ${target}) + list(APPEND optional_targets ${target}) + endif () +endforeach () -install(TARGETS Halide Halide_Generator Halide_RunGenMain +install(TARGETS Halide Halide_Generator Halide_RunGenMain ${optional_targets} EXPORT Halide_Targets RUNTIME @@ -55,6 +60,28 @@ install(TARGETS Halide_Runtime EXPORT Halide_Interfaces INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +set(exes "") +foreach (exe IN ITEMS retrain_cost_model featurization_to_sample get_host_target weightsdir_to_weightsfile) + if (TARGET ${exe}) + list(APPEND exes ${exe}) + endif () +endforeach () + +file(RELATIVE_PATH lib_dir + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) + +if (APPLE) + set(rbase @loader_path) +else () + set(rbase $ORIGIN) +endif () + +set_target_properties(${exes} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}") + +install(TARGETS ${exes} + EXPORT Halide_Interfaces) + # Captures both the runtime and Halide.h install(DIRECTORY ${Halide_BINARY_DIR}/include/ TYPE INCLUDE FILES_MATCHING PATTERN "include/*.h") @@ -75,6 +102,7 @@ install(FILES install(DIRECTORY ${Halide_SOURCE_DIR}/tools TYPE DATA + COMPONENT Halide_Development FILES_MATCHING PATTERN "*.h" PATTERN "*.cpp" @@ -83,6 +111,14 @@ install(DIRECTORY ${Halide_SOURCE_DIR}/tools PATTERN "build_halide_h.cpp" EXCLUDE PATTERN "find_inverse.cpp" EXCLUDE) +install(FILES ${Halide_SOURCE_DIR}/src/autoschedulers/adams2019/autotune_loop.sh + DESTINATION ${CMAKE_INSTALL_DATADIR}/tools + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE + COMPONENT Halide_Development) + ## # Tutorial ## @@ -119,7 +155,9 @@ if (Halide_SHARED_LLVM OR (NOT BUILD_SHARED_LIBS AND NOT Halide_BUNDLE_LLVM)) file(APPEND "${depFile}" "find_dependency(LLD CONFIG HINTS \"\${LLVM_DIR}/../lld\")\n") endif () - install(FILES "${depFile}" DESTINATION ${HALIDE_INSTALL_CMAKEDIR}) + install(FILES "${depFile}" + DESTINATION ${HALIDE_INSTALL_CMAKEDIR} + COMPONENT Halide_Development) endif () install(EXPORT Halide_Targets @@ -145,14 +183,17 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/HalideConfigVersion.cmake ${Halide_SOURCE_DIR}/cmake/HalideGeneratorHelpers.cmake ${Halide_SOURCE_DIR}/cmake/HalideTargetHelpers.cmake - DESTINATION ${HALIDE_INSTALL_CMAKEDIR}) + DESTINATION ${HALIDE_INSTALL_CMAKEDIR} + COMPONENT Halide_Development) ## # Documentation ## if (WITH_DOCS) - install(DIRECTORY ${Halide_BINARY_DIR}/doc/html/ TYPE DOC) + install(DIRECTORY ${Halide_BINARY_DIR}/doc/html/ + TYPE DOC + COMPONENT Halide_Documentation) endif () ## diff --git a/packaging/HalideConfig.cmake b/packaging/HalideConfig.cmake index 9ee50f1d2fb5..b364086960ce 100644 --- a/packaging/HalideConfig.cmake +++ b/packaging/HalideConfig.cmake @@ -62,7 +62,7 @@ macro(_Halide_include TYPE CAUSE) include("${CMAKE_CURRENT_LIST_DIR}/Halide-Targets-${TYPE}.cmake") if (NOT ${CMAKE_FIND_PACKAGE_NAME}_both) - foreach (target IN ITEMS Halide Generator RunGenMain) + foreach (target IN ITEMS Halide Generator RunGenMain Adams2019 Li2018 Mullapudi2016) if (NOT TARGET Halide::${TYPE}::${target}) continue() endif () @@ -127,7 +127,7 @@ foreach (comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_comps) # ${comp} is either PNG or JPEG, and this works for both packages if (NOT TARGET ${comp}::${comp}) - unset(extraArgs) + set(extraArgs "") if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) list(APPEND extraArgs QUIET) endif () diff --git a/python_bindings/Makefile b/python_bindings/Makefile index 51e87794a385..590ac613eda8 100644 --- a/python_bindings/Makefile +++ b/python_bindings/Makefile @@ -26,7 +26,7 @@ USE_EXPORT_DYNAMIC= endif endif -LIBHALIDE ?= $(HALIDE_DISTRIB_PATH)/bin/libHalide.$(SHARED_EXT) +LIBHALIDE ?= $(HALIDE_DISTRIB_PATH)/lib/libHalide.$(SHARED_EXT) SUFFIX = $(shell $(PYTHON)-config --extension-suffix) @@ -46,9 +46,7 @@ CCFLAGS := $(filter-out -Wstrict-prototypes,$(CCFLAGS)) # DON'T link libpython* - leave those symbols to lazily resolve at load time # Cf. https://github.com/pybind/pybind11/blob/master/docs/compiling.rst#building-manually LDFLAGS += -lz $(USE_EXPORT_DYNAMIC) -ifeq ($(UNAME), Linux) - LDFLAGS += -Wl,-rpath=$(dir $(LIBHALIDE)) -endif +LDFLAGS += -Wl,-rpath,$(dir $(LIBHALIDE)) PY_SRCS=$(shell ls $(ROOT_DIR)/src/*.cpp) PY_OBJS=$(PY_SRCS:$(ROOT_DIR)/src/%.cpp=$(BIN)/src/%.o) diff --git a/src/AutoSchedule.h b/src/AutoSchedule.h deleted file mode 100644 index bf962eb560d1..000000000000 --- a/src/AutoSchedule.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef HALIDE_INTERNAL_AUTO_SCHEDULE_H -#define HALIDE_INTERNAL_AUTO_SCHEDULE_H - -/** \file - * - * Defines the method that does automatic scheduling of Funcs within a pipeline. - */ - -#include "Pipeline.h" -#include "Target.h" - -namespace Halide { -namespace Internal { - -class Function; - -/** Generate schedules for Funcs within a pipeline. The Funcs should not already - * have specializations or schedules as the current auto-scheduler does not take - * into account user-defined schedules or specializations. This applies the - * schedules and returns a string representation of the schedules. The target - * architecture is specified by 'target'. */ -std::string generate_schedules(const std::vector &outputs, - const Target &target, - const MachineParams &arch_params); - -} // namespace Internal -} // namespace Halide - -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ffa4bcae27ee..9b07b680b45c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,6 @@ set(HEADER_FILES AssociativeOpsTable.h Associativity.h AsyncProducers.h - AutoSchedule.h AutoScheduleUtils.h BoundaryConditions.h Bounds.h @@ -180,7 +179,6 @@ set(SOURCE_FILES AssociativeOpsTable.cpp Associativity.cpp AsyncProducers.cpp - AutoSchedule.cpp AutoScheduleUtils.cpp BoundaryConditions.cpp Bounds.cpp @@ -375,7 +373,10 @@ add_library(Halide::Halide ALIAS Halide) target_link_libraries(Halide PRIVATE Halide::LLVM) target_link_libraries(Halide PUBLIC Halide::LanguageOptions) -target_compile_definitions(Halide PRIVATE $<$>:Halide_STATIC_DEFINE>) +target_compile_definitions(Halide + PRIVATE + $<$,STATIC_LIBRARY>:Halide_STATIC_DEFINE> + $<$:WITH_INTROSPECTION>) set_target_properties(Halide PROPERTIES POSITION_INDEPENDENT_CODE ON @@ -396,30 +397,6 @@ endif () set(Halide_INCLUDE_PATH "$") target_include_directories(Halide INTERFACE ${Halide_INCLUDE_PATH}) -## -# Plugin interface for Halide on weak systems -## - -add_library(Halide_Plugin INTERFACE) -set_target_properties(Halide_Plugin PROPERTIES EXPORT_NAME Plugin) - -if (NOT BUILD_SHARED_LIBS) - if (MSVC) - message(STATUS "Notice: Halide plugins are not available when building statically with MSVC") - else () - target_link_libraries(Halide_Plugin INTERFACE Halide::LanguageOptions) - target_link_options(Halide_Plugin INTERFACE - $<$:-rdynamic> - $<$:-undefined dynamic_lookup>) - target_include_directories(Halide_Plugin INTERFACE ${Halide_INCLUDE_PATH}) - add_dependencies(Halide_Plugin Halide) - endif () -else () - target_link_libraries(Halide_Plugin INTERFACE Halide::Halide) -endif () - -add_library(Halide::Plugin ALIAS Halide_Plugin) - ## # Set compiler options for libHalide ## @@ -494,3 +471,14 @@ option(Halide_USE_CODEMODEL_LARGE "Use the Large LLVM codemodel" OFF) if (Halide_USE_CODEMODEL_LARGE) target_compile_definitions(Halide PRIVATE HALIDE_USE_CODEMODEL_LARGE) endif () + +## +# Add autoschedulers to the build. +## + +if (BUILD_SHARED_LIBS) + message(STATUS "Building autoschedulers enabled") + add_subdirectory(autoschedulers) +else () + message(STATUS "Building autoschedulers disabled (static Halide)") +endif () diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index 9cd14aacdeea..e4d24cf679a9 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -3,7 +3,6 @@ #include #include "Argument.h" -#include "AutoSchedule.h" #include "CodeGen_Internal.h" #include "FindCalls.h" #include "Func.h" @@ -179,33 +178,18 @@ vector Pipeline::outputs() const { return funcs; } -/* static */ -void Pipeline::auto_schedule_Mullapudi2016(const Pipeline &pipeline, const Target &target, - const MachineParams &arch_params, AutoSchedulerResults *outputs) { - AutoSchedulerResults results; - results.target = target; - results.machine_params_string = arch_params.to_string(); - - user_assert(target.arch == Target::X86 || target.arch == Target::ARM || - target.arch == Target::POWERPC || target.arch == Target::MIPS) - << "The Mullapudi2016 autoscheduler is not supported for the target: " << target; - results.scheduler_name = "Mullapudi2016"; - results.schedule_source = generate_schedules(pipeline.contents->outputs, target, arch_params); - // this autoscheduler has no featurization - - *outputs = results; -} - /* static */ std::map &Pipeline::get_autoscheduler_map() { - static std::map autoschedulers = { - {"Mullapudi2016", auto_schedule_Mullapudi2016}}; + static std::map autoschedulers = {}; return autoschedulers; } /* static */ std::string &Pipeline::get_default_autoscheduler_name() { - static std::string autoscheduler_name = "Mullapudi2016"; + static std::string autoscheduler_name = ""; + if (autoscheduler_name.empty() && !get_autoscheduler_map().empty()) { + autoscheduler_name = get_autoscheduler_map().begin()->first; + } return autoscheduler_name; } @@ -226,7 +210,9 @@ AutoSchedulerFn Pipeline::find_autoscheduler(const std::string &autoscheduler_na AutoSchedulerResults Pipeline::auto_schedule(const std::string &autoscheduler_name, const Target &target, const MachineParams &arch_params) { auto autoscheduler_fn = find_autoscheduler(autoscheduler_name); - internal_assert(autoscheduler_fn != nullptr); + user_assert(autoscheduler_fn) + << "Could not find autoscheduler named '" << autoscheduler_name << "'.\n" + << "Did you remember to load the plugin?"; AutoSchedulerResults results; results.target = target; diff --git a/src/Pipeline.h b/src/Pipeline.h index 3f8baecf50ae..40b32b33247d 100644 --- a/src/Pipeline.h +++ b/src/Pipeline.h @@ -148,9 +148,6 @@ class Pipeline { static std::vector make_externs_jit_module(const Target &target, std::map &externs_in_out); - static void auto_schedule_Mullapudi2016(const Pipeline &pipeline, const Target &target, - const MachineParams &arch_params, AutoSchedulerResults *outputs); - static std::map &get_autoscheduler_map(); static std::string &get_default_autoscheduler_name(); diff --git a/src/Util.h b/src/Util.h index dff866529333..fb8791df4687 100644 --- a/src/Util.h +++ b/src/Util.h @@ -22,8 +22,10 @@ #include "runtime/HalideRuntime.h" -#ifndef HALIDE_EXPORT -#if defined(_MSC_VER) && !defined(Halide_STATIC_DEFINE) +#ifdef Halide_STATIC_DEFINE +#define HALIDE_EXPORT +#else +#if defined(_MSC_VER) // Halide_EXPORTS is quietly defined by CMake when building a shared library #ifdef Halide_EXPORTS #define HALIDE_EXPORT __declspec(dllexport) @@ -31,7 +33,7 @@ #define HALIDE_EXPORT __declspec(dllimport) #endif #else -#define HALIDE_EXPORT +#define HALIDE_EXPORT __attribute__((visibility("default"))) #endif #endif diff --git a/src/autoschedulers/CMakeLists.txt b/src/autoschedulers/CMakeLists.txt new file mode 100644 index 000000000000..9b88f0a664a1 --- /dev/null +++ b/src/autoschedulers/CMakeLists.txt @@ -0,0 +1,29 @@ +# Ensure that plugins export only what is needed to load them. +# Everything else should be omitted to keep binary size low. +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + +function(add_autoscheduler) + set(options) + set(oneValueArgs NAME) + set(multiValueArgs SOURCES) + cmake_parse_arguments("arg" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + add_library(Halide_${arg_NAME} MODULE ${arg_SOURCES}) + add_library(Halide::${arg_NAME} ALIAS Halide_${arg_NAME}) + + target_compile_definitions(Halide_${arg_NAME} PRIVATE Halide_EXPORTS) + target_link_libraries(Halide_${arg_NAME} PRIVATE Halide::Plugin) + + string(TOLOWER "${arg_NAME}" name_lower) + set_target_properties(Halide_${arg_NAME} PROPERTIES + EXPORT_NAME ${arg_NAME} + OUTPUT_NAME autoschedule_${name_lower}) +endfunction() + +add_subdirectory(common) + +add_subdirectory(adams2019) +add_subdirectory(li2018) +add_subdirectory(mullapudi2016) diff --git a/apps/autoscheduler/ASLog.cpp b/src/autoschedulers/adams2019/ASLog.cpp similarity index 100% rename from apps/autoscheduler/ASLog.cpp rename to src/autoschedulers/adams2019/ASLog.cpp diff --git a/apps/autoscheduler/ASLog.h b/src/autoschedulers/adams2019/ASLog.h similarity index 100% rename from apps/autoscheduler/ASLog.h rename to src/autoschedulers/adams2019/ASLog.h diff --git a/apps/autoscheduler/AutoSchedule.cpp b/src/autoschedulers/adams2019/AutoSchedule.cpp similarity index 99% rename from apps/autoscheduler/AutoSchedule.cpp rename to src/autoschedulers/adams2019/AutoSchedule.cpp index 8d1da73f7aa5..12fd5ee9abeb 100644 --- a/apps/autoscheduler/AutoSchedule.cpp +++ b/src/autoschedulers/adams2019/AutoSchedule.cpp @@ -64,6 +64,8 @@ TODO: expose these settings by adding some means to pass args to generator plugins instead of environment vars. */ +#include "HalidePlugin.h" + #include #include #include @@ -1319,15 +1321,7 @@ void generate_schedule(const std::vector &outputs, } } -// Halide uses a plugin architecture for registering custom -// autoschedulers. We register our autoscheduler using a static -// constructor. -struct RegisterAutoscheduler { - RegisterAutoscheduler() { - aslog(1) << "Registering autoscheduler 'Adams2019'...\n"; - Pipeline::add_autoscheduler("Adams2019", *this); - } - +struct Adams2019 { void operator()(const Pipeline &p, const Target &target, const MachineParams ¶ms, AutoSchedulerResults *results) { std::vector outputs; for (Func f : p.outputs()) { @@ -1335,7 +1329,9 @@ struct RegisterAutoscheduler { } Autoscheduler::generate_schedule(outputs, target, params, results); } -} register_auto_scheduler; +}; + +REGISTER_AUTOSCHEDULER(Adams2019) // An alternative entrypoint for other uses void find_and_apply_schedule(FunctionDAG &dag, diff --git a/apps/autoscheduler/AutoSchedule.h b/src/autoschedulers/adams2019/AutoSchedule.h similarity index 100% rename from apps/autoscheduler/AutoSchedule.h rename to src/autoschedulers/adams2019/AutoSchedule.h diff --git a/apps/autoscheduler/CMakeLists.txt b/src/autoschedulers/adams2019/CMakeLists.txt similarity index 59% rename from apps/autoscheduler/CMakeLists.txt rename to src/autoschedulers/adams2019/CMakeLists.txt index 8e46956db40b..928d603ce572 100644 --- a/apps/autoscheduler/CMakeLists.txt +++ b/src/autoschedulers/adams2019/CMakeLists.txt @@ -1,18 +1,6 @@ -# ================================================================================ -# Halide autoscheduler plugins rely on weak linking to work with static libraries. -# This is not standard C++ and only works on Linux / macOS. Nothing special needs -# to be done when linking to a shared version of Halide, however. - -if (NOT BUILD_SHARED_LIBS) - if (MSVC) - message(WARNING "Autoscheduler plugins cannot be built against static Halide on Windows") - return() - endif () - - # Need to enable exports for the plugins to find Halide's symbols. - set(CMAKE_ENABLE_EXPORTS ON) -endif () - +## +# Resources for the autoscheduler library +## # weights set(WF_CPP baseline.cpp) @@ -26,8 +14,10 @@ add_custom_command(OUTPUT ${WF_CPP} add_executable(cost_model.generator cost_model_generator.cpp) target_link_libraries(cost_model.generator PRIVATE Halide::Generator) -add_halide_library(cost_model FROM cost_model.generator) +add_halide_library(cost_model FROM cost_model.generator + TARGETS cmake) add_halide_library(train_cost_model FROM cost_model.generator + TARGETS cmake USE_RUNTIME cost_model.runtime) # retrain_cost_model @@ -37,42 +27,36 @@ add_executable(retrain_cost_model Weights.cpp retrain_cost_model.cpp ${WF_CPP}) -target_include_directories(retrain_cost_model PRIVATE ${PROJECT_SOURCE_DIR}/apps/support) # TODO(#4053): relocate. just for cmdline.h -target_link_libraries(retrain_cost_model PRIVATE cost_model train_cost_model Halide::Halide) - -# libauto_schedule -# Note: must use MODULE here (not SHARED) to get .so (instead of .dylib) on OSX. -# This means that this can only be opened dynamically (not linked directly), but that's ok. -add_library(Halide_Adams2019 - MODULE - ASLog.cpp - AutoSchedule.cpp - DefaultCostModel.cpp - FunctionDAG.cpp - LoopNest.cpp - Weights.cpp - ${WF_CPP}) -add_library(Halide::Adams2019 ALIAS Halide_Adams2019) -set_target_properties(Halide_Adams2019 PROPERTIES - EXPORT_NAME Adams2019 - OUTPUT_NAME auto_schedule) - -target_link_libraries(Halide_Adams2019 PRIVATE cost_model train_cost_model Halide::Plugin) - -if (NOT Halide_ENABLE_RTTI) - target_compile_options(Halide_Adams2019 PRIVATE - $<$:/GR-> - $<$,$>>:-fno-rtti>) -endif () +target_link_libraries(retrain_cost_model PRIVATE cost_model train_cost_model Halide::Halide Halide::Plugin) + +## +# Main autoscheduler library +## + +add_autoscheduler(NAME Adams2019 + SOURCES + ASLog.cpp + AutoSchedule.cpp + DefaultCostModel.cpp + FunctionDAG.cpp + LoopNest.cpp + Weights.cpp + ${WF_CPP}) + +target_link_libraries(Halide_Adams2019 PRIVATE cost_model train_cost_model) + +## +# Tests and demos +# TODO(#4053): move these to a separate folder since they're tests. +## # ================================================================= -# TODO(#4053): move this to a separate folder since it's a demo/app add_executable(demo.generator demo_generator.cpp) target_link_libraries(demo.generator PRIVATE Halide::Generator) add_halide_library(demo FROM demo.generator - PARAMS auto_schedule=true + TARGETS cmake AUTOSCHEDULER Halide::Adams2019 REGISTRATION DEMO_REGISTRATION_FILE) @@ -88,17 +72,16 @@ set_tests_properties(demo_apps_autoscheduler ENVIRONMENT "HL_TARGET=${Halide_TARGET}") # ================================================================= -# TODO(#4053): move this to a separate folder since it's a demo/app add_executable(included_schedule_file.generator included_schedule_file_generator.cpp) target_link_libraries(included_schedule_file.generator PRIVATE Halide::Generator) add_halide_library(included_schedule_file FROM included_schedule_file.generator - PARAMS auto_schedule=true + TARGETS cmake AUTOSCHEDULER Halide::Adams2019 - REGISTRATION INCLUDED_SCHEDULE_FILE_REGISTRATION_FILE) + REGISTRATION included_schedule_reg) -add_executable(demo_included_schedule_file ${INCLUDED_SCHEDULE_FILE_REGISTRATION_FILE}) +add_executable(demo_included_schedule_file ${included_schedule_reg}) target_link_libraries(demo_included_schedule_file PRIVATE included_schedule_file Halide::RunGenMain) add_test(NAME demo_included_schedule_file @@ -122,18 +105,19 @@ add_executable(weightsdir_to_weightsfile weightsdir_to_weightsfile.cpp Weights.c target_link_libraries(weightsdir_to_weightsfile PRIVATE Halide::Runtime) # ================================================================= -# TODO(#4053): move these to a separate folder since they're tests. +# Smaller tests -add_executable(test_apps_autoscheduler test.cpp) -target_link_libraries(test_apps_autoscheduler PRIVATE Halide::Halide Halide::Tools ${CMAKE_DL_LIBS}) +if (BUILD_SHARED_LIBS) + add_executable(test_apps_autoscheduler test.cpp) + target_link_libraries(test_apps_autoscheduler PRIVATE Halide::Halide Halide::Tools ${CMAKE_DL_LIBS}) -add_test(NAME test_apps_autoscheduler - COMMAND test_apps_autoscheduler - WORKING_DIRECTORY $) + add_test(NAME test_apps_autoscheduler + COMMAND test_apps_autoscheduler $) -set_tests_properties(test_apps_autoscheduler PROPERTIES - LABELS Adams2019 - ENVIRONMENT "LD_LIBRARY_PATH=$;HL_TARGET=${Halide_TARGET}") + set_tests_properties(test_apps_autoscheduler PROPERTIES + LABELS Adams2019 + ENVIRONMENT "LD_LIBRARY_PATH=$;HL_TARGET=${Halide_TARGET}") +endif () ## @@ -148,7 +132,7 @@ set_tests_properties(test_perfect_hash_map ## add_executable(test_function_dag test_function_dag.cpp FunctionDAG.cpp ASLog.cpp) -target_link_libraries(test_function_dag PRIVATE Halide::Halide Halide::Tools) +target_link_libraries(test_function_dag PRIVATE Halide::Halide Halide::Tools Halide::Plugin) add_test(NAME test_function_dag COMMAND test_function_dag) set_tests_properties(test_function_dag diff --git a/apps/autoscheduler/CostModel.h b/src/autoschedulers/adams2019/CostModel.h similarity index 100% rename from apps/autoscheduler/CostModel.h rename to src/autoschedulers/adams2019/CostModel.h diff --git a/apps/autoscheduler/DefaultCostModel.cpp b/src/autoschedulers/adams2019/DefaultCostModel.cpp similarity index 100% rename from apps/autoscheduler/DefaultCostModel.cpp rename to src/autoschedulers/adams2019/DefaultCostModel.cpp diff --git a/apps/autoscheduler/DefaultCostModel.h b/src/autoschedulers/adams2019/DefaultCostModel.h similarity index 98% rename from apps/autoscheduler/DefaultCostModel.h rename to src/autoschedulers/adams2019/DefaultCostModel.h index 288b470091da..11dff14ef0dc 100644 --- a/apps/autoscheduler/DefaultCostModel.h +++ b/src/autoschedulers/adams2019/DefaultCostModel.h @@ -33,7 +33,7 @@ class DefaultCostModel : public CostModel { load_weights(); } - virtual ~DefaultCostModel() = default; + ~DefaultCostModel() override = default; // Configure the cost model for the algorithm to be scheduled. void set_pipeline_features(const Internal::Autoscheduler::FunctionDAG &dag, diff --git a/apps/autoscheduler/Featurization.h b/src/autoschedulers/adams2019/Featurization.h similarity index 100% rename from apps/autoscheduler/Featurization.h rename to src/autoschedulers/adams2019/Featurization.h diff --git a/apps/autoscheduler/FunctionDAG.cpp b/src/autoschedulers/adams2019/FunctionDAG.cpp similarity index 100% rename from apps/autoscheduler/FunctionDAG.cpp rename to src/autoschedulers/adams2019/FunctionDAG.cpp diff --git a/apps/autoscheduler/FunctionDAG.h b/src/autoschedulers/adams2019/FunctionDAG.h similarity index 100% rename from apps/autoscheduler/FunctionDAG.h rename to src/autoschedulers/adams2019/FunctionDAG.h diff --git a/apps/autoscheduler/LoopNest.cpp b/src/autoschedulers/adams2019/LoopNest.cpp similarity index 100% rename from apps/autoscheduler/LoopNest.cpp rename to src/autoschedulers/adams2019/LoopNest.cpp diff --git a/apps/autoscheduler/LoopNest.h b/src/autoschedulers/adams2019/LoopNest.h similarity index 100% rename from apps/autoscheduler/LoopNest.h rename to src/autoschedulers/adams2019/LoopNest.h diff --git a/src/autoschedulers/adams2019/Makefile b/src/autoschedulers/adams2019/Makefile new file mode 100644 index 000000000000..6e3d972f6258 --- /dev/null +++ b/src/autoschedulers/adams2019/Makefile @@ -0,0 +1,230 @@ +THIS_MAKEFILE = $(realpath $(filter %Makefile, $(MAKEFILE_LIST))) +SRC = $(strip $(shell dirname $(THIS_MAKEFILE))) +HALIDE_SRC_ROOT = $(realpath $(SRC)/../../../) +COMMON_DIR ?= $(realpath $(SRC)/../common/) + +HALIDE_DISTRIB_PATH ?= $(HALIDE_SRC_ROOT)/distrib + +$(info Looking for Halide distro at $(HALIDE_DISTRIB_PATH). If this is incorrect, set the make variable HALIDE_DISTRIB_PATH) + +# Don't include an autoscheduler in the generator deps +AUTOSCHEDULER= +include $(HALIDE_SRC_ROOT)/apps/support/Makefile.inc + +# Add the relative location of libHalide.so in the rpath in a distro +ifeq ($(UNAME), Darwin) +HALIDE_RPATH_FOR_BIN = '-Wl,-rpath,@executable_path/../lib' +HALIDE_RPATH_FOR_LIB = '-Wl,-rpath,@loader_path' +else +HALIDE_RPATH_FOR_BIN = '-Wl,-rpath,$$ORIGIN/../lib' +HALIDE_RPATH_FOR_LIB = '-Wl,-rpath,$$ORIGIN' +endif + +CXXFLAGS += -I$(COMMON_DIR) + +AUTOSCHED_WEIGHT_OBJECTS=$(BIN)/baseline_weights.o + +$(BIN)/binary2cpp: $(HALIDE_SRC_ROOT)/tools/binary2cpp.cpp + @mkdir -p $(@D) + $(CXX) $< -o $@ + +$(BIN)/baseline_weights.cpp: $(BIN)/binary2cpp $(SRC)/baseline.weights + @mkdir -p $(@D) + $(BIN)/binary2cpp baseline_weights < $(SRC)/baseline.weights > $@ + +$(BIN)/baseline_weights.o: $(BIN)/baseline_weights.cpp + $(CXX) -c $< -o $@ + +AUTOSCHED_COST_MODEL_LIBS=\ +$(BIN)/cost_model/cost_model.a \ +$(BIN)/cost_model/train_cost_model.a \ + +$(BIN)/cost_model.generator: $(SRC)/cost_model_generator.cpp \ + $(SRC)/cost_model_schedule.h \ + $(SRC)/NetworkSize.h \ + $(GENERATOR_DEPS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ $(USE_EXPORT_DYNAMIC) $(LIBHALIDE_LDFLAGS) + +$(BIN)/auto_schedule_runtime.a: $(BIN)/cost_model.generator + @mkdir -p $(@D) + $^ -r auto_schedule_runtime -o $(BIN) target=$(HL_TARGET) + +$(BIN)/cost_model/%.a: $(BIN)/cost_model.generator + @mkdir -p $(@D) + $^ -g $* -o $(BIN)/cost_model -f $* target=$(HL_TARGET)-no_runtime auto_schedule=false -e stmt,static_library,h,assembly + +# 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 +# undefined rather than dependent on libHalide.so. +$(BIN)/libautoschedule_adams2019.$(SHARED_EXT): $(SRC)/AutoSchedule.cpp \ + $(SRC)/ASLog.cpp \ + $(SRC)/DefaultCostModel.h \ + $(SRC)/DefaultCostModel.cpp \ + $(SRC)/Weights.h \ + $(SRC)/Weights.cpp \ + $(SRC)/FunctionDAG.h \ + $(SRC)/FunctionDAG.cpp \ + $(SRC)/LoopNest.h \ + $(SRC)/LoopNest.cpp \ + $(SRC)/Featurization.h \ + $(SRC)/CostModel.h \ + $(SRC)/PerfectHashMap.h \ + $(AUTOSCHED_WEIGHT_OBJECTS) \ + $(AUTOSCHED_COST_MODEL_LIBS) \ + $(GENERATOR_DEPS) \ + $(BIN)/auto_schedule_runtime.a + @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) + +$(BIN)/retrain_cost_model: $(SRC)/retrain_cost_model.cpp \ + $(SRC)/ASLog.cpp \ + $(SRC)/DefaultCostModel.h \ + $(SRC)/DefaultCostModel.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) + +$(BIN)/featurization_to_sample: $(SRC)/featurization_to_sample.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $< $(OPTIMIZE) -o $@ + +$(BIN)/get_host_target: $(SRC)/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: $(SRC)/weightsdir_to_weightsfile.cpp $(SRC)/Weights.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $^ $(OPTIMIZE) -o $@ + +# This is the value that machine_params defaults to if no custom value is specified; +# see MachineParams::generic() +HL_MACHINE_PARAMS ?= 32,25165824,160 + + +# A sample generator to autoschedule. Note that if it statically links +# to libHalide, then it must be build with $(USE_EXPORT_DYNAMIC), or the +# autoscheduler can't find the libHalide symbols that it needs. +$(GENERATOR_BIN)/demo.generator: $(SRC)/demo_generator.cpp $(GENERATOR_DEPS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS) + +# To use the autoscheduler, set a few environment variables and use the -p flag to the generator to load the autoscheduler as a plugin +$(BIN)/%/demo.a: $(GENERATOR_BIN)/demo.generator $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + @mkdir -p $(@D) + HL_WEIGHTS_DIR=$(SRC)/baseline.weights \ + $(GENERATOR_BIN)/demo.generator -g demo -o $(@D) -f demo target=$* auto_schedule=true -p $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) -s Adams2019 + +$(BIN)/%/demo.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/demo.registration.cpp $(BIN)/%/demo.a + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) + +# demonstrates single-shot use of the autoscheduler +demo: $(BIN)/$(HL_TARGET)/demo.rungen $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + $< --benchmarks=all --benchmark_min_time=1 --estimate_all + +# demonstrates an autotuning loop +# (using $(BIN) and $(SRC) here seems overkill, but makes copy-n-paste elsewhere easier) +autotune: $(GENERATOR_BIN)/demo.generator $(BIN)/featurization_to_sample $(BIN)/get_host_target $(BIN)/retrain_cost_model $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) $(SRC)/autotune_loop.sh + @mkdir -p $(@D) + bash $(SRC)/autotune_loop.sh \ + $(GENERATOR_BIN)/demo.generator \ + demo \ + "" \ + $(SRC)/baseline.weights \ + $(BIN) \ + $(HALIDE_DISTRIB_PATH) \ + $(BIN)/samples + +$(BIN)/test_perfect_hash_map: $(SRC)/test_perfect_hash_map.cpp $(SRC)/PerfectHashMap.h + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $< -o $@ + +$(BIN)/test_function_dag: $(SRC)/test_function_dag.cpp $(SRC)/FunctionDAG.h $(SRC)/FunctionDAG.cpp $(SRC)/ASLog.h $(SRC)/ASLog.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +# Simple jit-based test +$(BIN)/%/test: $(SRC)/test.cpp $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $^ -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +test_perfect_hash_map: $(BIN)/test_perfect_hash_map + $^ + +test_function_dag: $(BIN)/test_function_dag + $^ + +run_test: $(BIN)/$(HL_TARGET)/test + HL_WEIGHTS_DIR=$(SRC)/baseline.weights LD_LIBRARY_PATH=$(BIN) $< $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + +.PHONY: test clean + +# Note that 'make build' and 'make test' is used by Halide buildbots +# to spot-check changes, so it's important to try a little of each of +# the important paths here, including single-shot and autotune-loop +build: $(BIN)/$(HL_TARGET)/test \ + $(BIN)/test_perfect_hash_map \ + $(BIN)/test_function_dag \ + $(BIN)/$(HL_TARGET)/included_schedule_file.rungen \ + $(GENERATOR_BIN)/demo.generator \ + $(BIN)/featurization_to_sample \ + $(BIN)/get_host_target \ + $(BIN)/retrain_cost_model \ + $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + +test: run_test test_perfect_hash_map test_function_dag demo test_included_schedule_file autotune + +clean: + rm -rf $(BIN) + +# A sample generator to demonstrate including autogenerated .sample.h +# files for scheduling purposes; the catch here is that we'll need +# to be able to compile the Generator two different ways: +# +# - one that will be used to generate the .schedule.h +# - one that will consume the .schedule.h generated above +# +# We'll use the preprocessor (GENERATING_SCHEDULE) to distinguish between these two. + +$(GENERATOR_BIN)/included_schedule_file_none.generator: $(SRC)/included_schedule_file_generator.cpp $(GENERATOR_DEPS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -DGENERATING_SCHEDULE -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +# This is the target you build to (re)generate the schedule file. +# (Note that we only need the schedule output, so we pass `-e schedule` to +# the Generator so that it can skip producing other outputs.) +$(BIN)/%/included_schedule_file.schedule.h: $(GENERATOR_BIN)/included_schedule_file_none.generator $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) + @mkdir -p $(@D) + HL_WEIGHTS_DIR=$(SRC)/baseline.weights \ + $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$* auto_schedule=true -p $(BIN)/libautoschedule_adams2019.$(SHARED_EXT) -s Adams2019 -e schedule + +# Note that this depends on included_schedule_file.schedule.h rather than $(BIN)/%/included_schedule_file.schedule.h -- +# the former should be generated by something like +# +# make bin/host/included_schedule_file.schedule.h +# cp bin/host/included_schedule_file.schedule.h included_schedule_file.schedule.h +# +$(GENERATOR_BIN)/included_schedule_file.generator: $(SRC)/included_schedule_file_generator.cpp $(SRC)/included_schedule_file.schedule.h $(GENERATOR_DEPS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +# Note that this does not depend on libauto_schedule nor does it call +# the autoscheduler at build time; it includes the generated schedule (included_schedule_file.schedule.h), +# which has been added to our local source control. +$(BIN)/%/included_schedule_file.a: $(GENERATOR_BIN)/included_schedule_file.generator + @mkdir -p $(@D) + $< -g included_schedule_file -o $(@D) -f included_schedule_file target=$* + +$(BIN)/%/included_schedule_file.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/included_schedule_file.registration.cpp $(BIN)/%/included_schedule_file.a + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) + +test_included_schedule_file: $(BIN)/$(HL_TARGET)/included_schedule_file.rungen + $^ --benchmarks=all --benchmark_min_time=1 --estimate_all + diff --git a/apps/autoscheduler/NetworkSize.h b/src/autoschedulers/adams2019/NetworkSize.h similarity index 100% rename from apps/autoscheduler/NetworkSize.h rename to src/autoschedulers/adams2019/NetworkSize.h diff --git a/apps/autoscheduler/PerfectHashMap.h b/src/autoschedulers/adams2019/PerfectHashMap.h similarity index 100% rename from apps/autoscheduler/PerfectHashMap.h rename to src/autoschedulers/adams2019/PerfectHashMap.h diff --git a/apps/autoscheduler/Weights.cpp b/src/autoschedulers/adams2019/Weights.cpp similarity index 100% rename from apps/autoscheduler/Weights.cpp rename to src/autoschedulers/adams2019/Weights.cpp diff --git a/apps/autoscheduler/Weights.h b/src/autoschedulers/adams2019/Weights.h similarity index 100% rename from apps/autoscheduler/Weights.h rename to src/autoschedulers/adams2019/Weights.h diff --git a/apps/autoscheduler/autotune_loop.sh b/src/autoschedulers/adams2019/autotune_loop.sh similarity index 99% rename from apps/autoscheduler/autotune_loop.sh rename to src/autoschedulers/adams2019/autotune_loop.sh index e3760cac75f7..7f99692402fc 100755 --- a/apps/autoscheduler/autotune_loop.sh +++ b/src/autoschedulers/adams2019/autotune_loop.sh @@ -117,7 +117,7 @@ make_featurization() { target=${HL_TARGET} \ auto_schedule=true \ ${EXTRA_GENERATOR_ARGS} \ - -p ${AUTOSCHED_BIN}/libauto_schedule.so \ + -p ${AUTOSCHED_BIN}/libautoschedule_adams2019.so \ -s Adams2019 \ 2> ${D}/compile_log.txt || echo "Compilation failed or timed out for ${D}" diff --git a/apps/autoscheduler/baseline.weights b/src/autoschedulers/adams2019/baseline.weights similarity index 100% rename from apps/autoscheduler/baseline.weights rename to src/autoschedulers/adams2019/baseline.weights diff --git a/apps/autoscheduler/cost_model_generator.cpp b/src/autoschedulers/adams2019/cost_model_generator.cpp similarity index 100% rename from apps/autoscheduler/cost_model_generator.cpp rename to src/autoschedulers/adams2019/cost_model_generator.cpp diff --git a/apps/autoscheduler/cost_model_schedule.h b/src/autoschedulers/adams2019/cost_model_schedule.h similarity index 100% rename from apps/autoscheduler/cost_model_schedule.h rename to src/autoschedulers/adams2019/cost_model_schedule.h diff --git a/apps/autoscheduler/demo_generator.cpp b/src/autoschedulers/adams2019/demo_generator.cpp similarity index 100% rename from apps/autoscheduler/demo_generator.cpp rename to src/autoschedulers/adams2019/demo_generator.cpp diff --git a/apps/autoscheduler/featurization_to_sample.cpp b/src/autoschedulers/adams2019/featurization_to_sample.cpp similarity index 100% rename from apps/autoscheduler/featurization_to_sample.cpp rename to src/autoschedulers/adams2019/featurization_to_sample.cpp diff --git a/apps/autoscheduler/get_host_target.cpp b/src/autoschedulers/adams2019/get_host_target.cpp similarity index 100% rename from apps/autoscheduler/get_host_target.cpp rename to src/autoschedulers/adams2019/get_host_target.cpp diff --git a/apps/autoscheduler/included_schedule_file.schedule.h b/src/autoschedulers/adams2019/included_schedule_file.schedule.h similarity index 100% rename from apps/autoscheduler/included_schedule_file.schedule.h rename to src/autoschedulers/adams2019/included_schedule_file.schedule.h diff --git a/apps/autoscheduler/included_schedule_file_generator.cpp b/src/autoschedulers/adams2019/included_schedule_file_generator.cpp similarity index 100% rename from apps/autoscheduler/included_schedule_file_generator.cpp rename to src/autoschedulers/adams2019/included_schedule_file_generator.cpp diff --git a/apps/autoscheduler/retrain_cost_model.cpp b/src/autoschedulers/adams2019/retrain_cost_model.cpp similarity index 100% rename from apps/autoscheduler/retrain_cost_model.cpp rename to src/autoschedulers/adams2019/retrain_cost_model.cpp diff --git a/apps/autoscheduler/test.cpp b/src/autoschedulers/adams2019/test.cpp similarity index 98% rename from apps/autoscheduler/test.cpp rename to src/autoschedulers/adams2019/test.cpp index 7e62e479ba36..c710871c6185 100644 --- a/apps/autoscheduler/test.cpp +++ b/src/autoschedulers/adams2019/test.cpp @@ -3,10 +3,12 @@ using namespace Halide; int main(int argc, char **argv) { - // Loads lib auto_schedule.so (or auto_schedule.dll), - // which is presumed to be in current library search path - load_plugin("auto_schedule"); - Pipeline::set_default_autoscheduler_name("Adams2019"); + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); MachineParams params(32, 16000000, 40); // Use a fixed target for the analysis to get consistent results from this test. diff --git a/apps/autoscheduler/test_function_dag.cpp b/src/autoschedulers/adams2019/test_function_dag.cpp similarity index 100% rename from apps/autoscheduler/test_function_dag.cpp rename to src/autoschedulers/adams2019/test_function_dag.cpp diff --git a/apps/autoscheduler/test_perfect_hash_map.cpp b/src/autoschedulers/adams2019/test_perfect_hash_map.cpp similarity index 100% rename from apps/autoscheduler/test_perfect_hash_map.cpp rename to src/autoschedulers/adams2019/test_perfect_hash_map.cpp diff --git a/apps/autoscheduler/weightsdir_to_weightsfile.cpp b/src/autoschedulers/adams2019/weightsdir_to_weightsfile.cpp similarity index 100% rename from apps/autoscheduler/weightsdir_to_weightsfile.cpp rename to src/autoschedulers/adams2019/weightsdir_to_weightsfile.cpp diff --git a/src/autoschedulers/common/CMakeLists.txt b/src/autoschedulers/common/CMakeLists.txt new file mode 100644 index 000000000000..90693889928b --- /dev/null +++ b/src/autoschedulers/common/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(Halide_Plugin INTERFACE) +add_library(Halide::Plugin ALIAS Halide_Plugin) +target_include_directories(Halide_Plugin INTERFACE $) +target_link_libraries(Halide_Plugin INTERFACE Halide::Halide) diff --git a/apps/autoscheduler/Errors.h b/src/autoschedulers/common/Errors.h similarity index 100% rename from apps/autoscheduler/Errors.h rename to src/autoschedulers/common/Errors.h diff --git a/src/autoschedulers/common/HalidePlugin.h b/src/autoschedulers/common/HalidePlugin.h new file mode 100644 index 000000000000..7e6636bb09c0 --- /dev/null +++ b/src/autoschedulers/common/HalidePlugin.h @@ -0,0 +1,14 @@ +#ifndef HALIDE_HALIDEPLUGIN_H +#define HALIDE_HALIDEPLUGIN_H + +#include "Errors.h" + +#define REGISTER_AUTOSCHEDULER(NAME) \ + struct HALIDE_EXPORT Register##NAME { \ + Register##NAME() { \ + debug(1) << "Registering autoscheduler '" #NAME "'...\n"; \ + Pipeline::add_autoscheduler(#NAME, NAME()); \ + } \ + } register_##NAME; + +#endif //HALIDE_HALIDEPLUGIN_H diff --git a/apps/support/cmdline.h b/src/autoschedulers/common/cmdline.h similarity index 100% rename from apps/support/cmdline.h rename to src/autoschedulers/common/cmdline.h diff --git a/src/autoschedulers/li2018/CMakeLists.txt b/src/autoschedulers/li2018/CMakeLists.txt new file mode 100644 index 000000000000..809689012b35 --- /dev/null +++ b/src/autoschedulers/li2018/CMakeLists.txt @@ -0,0 +1,61 @@ +add_autoscheduler(NAME Li2018 SOURCES GradientAutoscheduler.cpp) + +# ========================================================== +# TODO(#4053): move these to a separate folder since they're tests. + +add_executable(demo_gradient.generator demo_generator.cpp) +target_link_libraries(demo_gradient.generator PRIVATE Halide::Generator) + +add_halide_library(demo_gradient FROM demo_gradient.generator + TARGETS cmake + GENERATOR demo + FUNCTION_NAME demo + AUTOSCHEDULER Halide::Li2018 + REGISTRATION DEMO_REGISTRATION_FILE) + +add_executable(demo_gradient_autoscheduler ${DEMO_REGISTRATION_FILE}) +target_link_libraries(demo_gradient_autoscheduler PRIVATE demo_gradient Halide::RunGenMain) + +add_test(NAME demo_gradient_autoscheduler + COMMAND demo_gradient_autoscheduler --benchmarks=all --benchmark_min_time=1 --estimate_all) + +set_tests_properties(demo_gradient_autoscheduler PROPERTIES LABELS Li2018) + +## + +if (BUILD_SHARED_LIBS) + add_executable(gradient_autoscheduler_test_cpp test.cpp) + target_link_libraries(gradient_autoscheduler_test_cpp PRIVATE Halide::Halide) + + add_test(NAME gradient_autoscheduler_test_cpp + COMMAND gradient_autoscheduler_test_cpp $) + + set_tests_properties(gradient_autoscheduler_test_cpp PROPERTIES LABELS Li2018) +endif () + +## + +if (WITH_PYTHON_BINDINGS) + # TODO(#4053): rework this as an app under python_bindings. + # TODO(#4876): Disabled due to issue #4876 + if (FALSE) + find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + + add_test(NAME gradient_autoscheduler_test_py + COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/test.py") + + set(PYTHONPATH "$>") + + if (WIN32) + set(SEP "\\$") + else () + set(SEP ":") + endif () + + set(_PATH "$>;$>;$ENV{PATH}") + string(REPLACE ";" "${SEP}" _PATH "${_PATH}") + set_tests_properties(gradient_autoscheduler_test_py PROPERTIES + LABELS Li2018 + ENVIRONMENT "PYTHONPATH=${PYTHONPATH};PATH=${_PATH}") + endif () +endif () diff --git a/apps/gradient_autoscheduler/GradientAutoscheduler.cpp b/src/autoschedulers/li2018/GradientAutoscheduler.cpp similarity index 98% rename from apps/gradient_autoscheduler/GradientAutoscheduler.cpp rename to src/autoschedulers/li2018/GradientAutoscheduler.cpp index 486789bd32ab..538534b90d10 100644 --- a/apps/gradient_autoscheduler/GradientAutoscheduler.cpp +++ b/src/autoschedulers/li2018/GradientAutoscheduler.cpp @@ -1,6 +1,6 @@ -#include "ASLog.h" #include "Errors.h" #include "Halide.h" +#include "HalidePlugin.h" namespace Halide { namespace Internal { @@ -910,7 +910,7 @@ void generate_schedule(const std::vector &outputs, // Traverse from the consumers to the producers for (auto it = order.rbegin(); it != order.rend(); it++) { Func func(env[*it]); - aslog(1) << "[gradient_autoscheduler] Processing function:" << *it << "\n"; + debug(1) << "[gradient_autoscheduler] Processing function:" << *it << "\n"; // Get the bounds in integer constant by substitute all the parameters' estimates. Box bounds = func_bounds[*it]; std::vector int_bounds = get_int_bounds(bounds); @@ -925,18 +925,10 @@ void generate_schedule(const std::vector &outputs, auto_scheduler_results->scheduler_name = "Li2018"; auto_scheduler_results->schedule_source = schedule_source.str(); - aslog(1) << schedule_source.str() << "\n"; + debug(1) << schedule_source.str() << "\n"; } -// Halide uses a plugin architecture for registering custom -// autoschedulers. We register our autoscheduler using a static -// constructor. -struct RegisterGradientAutoscheduler { - RegisterGradientAutoscheduler() { - aslog(1) << "Registering autoscheduler 'Li2018'...\n"; - Pipeline::add_autoscheduler("Li2018", *this); - } - +struct Li2018 { void operator()(const Pipeline &p, const Target &target, const MachineParams ¶ms, AutoSchedulerResults *results) { std::vector outputs; for (Func f : p.outputs()) { @@ -944,7 +936,9 @@ struct RegisterGradientAutoscheduler { } generate_schedule(outputs, target, params, results); } -} register_auto_scheduler; +}; + +REGISTER_AUTOSCHEDULER(Li2018) } // namespace Autoscheduler } // namespace Internal diff --git a/src/autoschedulers/li2018/Makefile b/src/autoschedulers/li2018/Makefile new file mode 100644 index 000000000000..db11cd90768e --- /dev/null +++ b/src/autoschedulers/li2018/Makefile @@ -0,0 +1,63 @@ +THIS_MAKEFILE = $(realpath $(filter %Makefile, $(MAKEFILE_LIST))) +SRC = $(strip $(shell dirname $(THIS_MAKEFILE))) +HALIDE_SRC_ROOT = $(realpath $(SRC)/../../../) +COMMON_DIR = $(realpath $(SRC)/../common/) + +# Assume an in-tree build of a halide distro exists. Most uses of this +# Makefile should probably set this variable explicitly. +HALIDE_DISTRIB_PATH ?= $(HALIDE_SRC_ROOT)/distrib + +# The example uses a generator, though the autoscheduler itself does not require one +include $(HALIDE_SRC_ROOT)/apps/support/Makefile.inc + +CXXFLAGS += -I$(COMMON_DIR) + +ifeq ($(UNAME), Darwin) +HALIDE_RPATH_FOR_LIB += '-Wl,-rpath,@loader_path' +else +HALIDE_RPATH_FOR_LIB += '-Wl,-rpath,$$ORIGIN' +endif + +$(BIN)/libautoschedule_li2018.$(SHARED_EXT): $(SRC)/GradientAutoscheduler.cpp $(LIB_HALIDE) + @mkdir -p $(@D) + $(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(HALIDE_RPATH_FOR_LIB) + +# Demonstrate a JIT-based use of gradient autoscheuler +$(BIN)/test: $(SRC)/test.cpp $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) $(SRC)/test.cpp -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +# Demonstrate a generator-based use of gradient autoscheuler +$(GENERATOR_BIN)/demo.generator: $(SRC)/demo_generator.cpp $(GENERATOR_DEPS) + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) $(USE_EXPORT_DYNAMIC) -g $(filter-out %.h,$^) -o $@ $(LIBHALIDE_LDFLAGS) $(HALIDE_SYSTEM_LIBS) + +# Use the -p flag to the generator to load the autoscheduler as a plugin +$(BIN)/%/demo.a: $(GENERATOR_BIN)/demo.generator $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + @mkdir -p $(@D) + $(GENERATOR_BIN)/demo.generator -g demo -o $(@D) -f demo target=$* auto_schedule=true -p $(BIN)/libautoschedule_li2018.$(SHARED_EXT) -s Li2018 + +$(BIN)/%/demo.rungen: $(BIN)/%/RunGenMain.o $(BIN)/%/demo.registration.cpp $(BIN)/%/demo.a + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -I$(BIN)/$* $^ -o $@ $(HALIDE_SYSTEM_LIBS) $(IMAGE_IO_FLAGS) + +.PHONY: build test clean run_test_cpp run_test_py test_generator + +# demonstrates single-shot use of the autoscheduler +test_generator: $(BIN)/$(HL_TARGET)/demo.rungen $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + $< --benchmarks=all --benchmark_min_time=1 --estimate_all + +run_test_cpp: $(BIN)/test + LD_LIBRARY_PATH=$(BIN) $< $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + +run_test_py: $(SRC)/test.py $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + PYTHONPATH=$(BIN):$(HALIDE_PYTHON_BINDINGS_PATH):$(HALIDE_DISTRIB_PATH)/bin:$$PYTHONPATH \ + LD_LIBRARY_PATH=$(BIN):$(HALIDE_PYTHON_BINDINGS_PATH):$(HALIDE_DISTRIB_PATH)/bin \ + $(PYTHON) $(SRC)/test.py + +\build: $(BIN)/test $(BIN)/$(HL_TARGET)/demo.rungen $(BIN)/libautoschedule_li2018.$(SHARED_EXT) + +test: run_test_cpp run_test_py test_generator + +clean: + rm -rf $(BIN) diff --git a/apps/gradient_autoscheduler/README.md b/src/autoschedulers/li2018/README.md similarity index 100% rename from apps/gradient_autoscheduler/README.md rename to src/autoschedulers/li2018/README.md diff --git a/apps/gradient_autoscheduler/demo_generator.cpp b/src/autoschedulers/li2018/demo_generator.cpp similarity index 100% rename from apps/gradient_autoscheduler/demo_generator.cpp rename to src/autoschedulers/li2018/demo_generator.cpp diff --git a/apps/gradient_autoscheduler/test.cpp b/src/autoschedulers/li2018/test.cpp similarity index 94% rename from apps/gradient_autoscheduler/test.cpp rename to src/autoschedulers/li2018/test.cpp index d07d3866c13b..6518cda38960 100644 --- a/apps/gradient_autoscheduler/test.cpp +++ b/src/autoschedulers/li2018/test.cpp @@ -3,10 +3,12 @@ using namespace Halide; int main(int argc, char **argv) { - // Loads libgradient_autoscheduler.so (or gradient_autoscheduler.dll), - // which is presumed to be in current library search path - load_plugin("gradient_autoscheduler"); - Pipeline::set_default_autoscheduler_name("Li2018"); + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); MachineParams params(32, 16000000, 40); Target target; diff --git a/apps/gradient_autoscheduler/test.py b/src/autoschedulers/li2018/test.py similarity index 94% rename from apps/gradient_autoscheduler/test.py rename to src/autoschedulers/li2018/test.py index a7483460eaef..438f28fb0547 100644 --- a/apps/gradient_autoscheduler/test.py +++ b/src/autoschedulers/li2018/test.py @@ -1,7 +1,7 @@ import halide as hl def main(): - hl.load_plugin("gradient_autoscheduler") + hl.load_plugin("autoschedule_li2018") x = hl.Var('x') f_in = hl.Func('in') diff --git a/src/AutoSchedule.cpp b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp similarity index 99% rename from src/AutoSchedule.cpp rename to src/autoschedulers/mullapudi2016/AutoSchedule.cpp index 04d2a0967f5d..497a31f97f09 100644 --- a/src/AutoSchedule.cpp +++ b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp @@ -1,20 +1,12 @@ +#include "HalidePlugin.h" + #include +#include #include +#include #include -#include "AutoSchedule.h" -#include "AutoScheduleUtils.h" -#include "ExprUsesVar.h" -#include "FindCalls.h" -#include "Func.h" -#include "IREquality.h" -#include "Inline.h" -#include "ParallelRVar.h" -#include "RealizationOrder.h" -#include "RegionCosts.h" -#include "Scope.h" -#include "Simplify.h" -#include "Util.h" +#include "Halide.h" namespace Halide { namespace Internal { @@ -3377,6 +3369,29 @@ string generate_schedules(const vector &outputs, const Target &target, return sched_string; } +struct Mullapudi2016 { + void operator()(const Pipeline &pipeline, const Target &target, const MachineParams &arch_params, AutoSchedulerResults *outputs) { + AutoSchedulerResults results; + results.target = target; + results.machine_params_string = arch_params.to_string(); + + user_assert(target.arch == Target::X86 || target.arch == Target::ARM || + target.arch == Target::POWERPC || target.arch == Target::MIPS) + << "The Mullapudi2016 autoscheduler is not supported for the target: " << target.to_string(); + results.scheduler_name = "Mullapudi2016"; + std::vector pipeline_outputs; + for (Func f : pipeline.outputs()) { + pipeline_outputs.push_back(f.function()); + } + results.schedule_source = generate_schedules(pipeline_outputs, target, arch_params); + // this autoscheduler has no featurization + + *outputs = results; + } +}; + +REGISTER_AUTOSCHEDULER(Mullapudi2016) + } // namespace Internal } // namespace Halide diff --git a/src/autoschedulers/mullapudi2016/CMakeLists.txt b/src/autoschedulers/mullapudi2016/CMakeLists.txt new file mode 100644 index 000000000000..41a21ab1b086 --- /dev/null +++ b/src/autoschedulers/mullapudi2016/CMakeLists.txt @@ -0,0 +1 @@ +add_autoscheduler(NAME Mullapudi2016 SOURCES AutoSchedule.cpp) diff --git a/src/autoschedulers/mullapudi2016/Makefile b/src/autoschedulers/mullapudi2016/Makefile new file mode 100644 index 000000000000..14eddc0e1128 --- /dev/null +++ b/src/autoschedulers/mullapudi2016/Makefile @@ -0,0 +1,20 @@ +THIS_MAKEFILE = $(realpath $(filter %Makefile, $(MAKEFILE_LIST))) +SRC = $(strip $(shell dirname $(THIS_MAKEFILE))) +HALIDE_ROOT = $(realpath $(SRC)/../../../) +COMMON_DIR = $(realpath $(SRC)/../common/) + +HALIDE_DISTRIB_PATH ?= $(HALIDE_SRC_ROOT)/distrib +include $(HALIDE_ROOT)/apps/support/Makefile.inc + +# Add the relative location of libHalide.so in the rpath in a distro so that the autoscheduler library can find libHalide +ifeq ($(UNAME), Darwin) +HALIDE_RPATH_FOR_LIB += '-Wl,-rpath,@loader_path' +else +HALIDE_RPATH_FOR_LIB += '-Wl,-rpath,$$ORIGIN' +endif + +CXXFLAGS += -I$(COMMON_DIR) + +$(BIN)/libautoschedule_mullapudi2016.$(SHARED_EXT): $(SRC)/AutoSchedule.cpp $(LIB_HALIDE) + @mkdir -p $(@D) + $(CXX) -shared $(USE_EXPORT_DYNAMIC) -fPIC -fvisibility=hidden -fvisibility-inlines-hidden $(CXXFLAGS) $(OPTIMIZE) $^ -o $@ $(HALIDE_RPATH_FOR_LIB) diff --git a/test/auto_schedule/CMakeLists.txt b/test/auto_schedule/CMakeLists.txt index 0222c5d6e737..668175d51ab5 100644 --- a/test/auto_schedule/CMakeLists.txt +++ b/test/auto_schedule/CMakeLists.txt @@ -1,18 +1,23 @@ -tests(GROUPS auto_schedule - SOURCES - cost_function.cpp - data_dependent.cpp - extern.cpp - fibonacci.cpp - histogram.cpp - large_window.cpp - mat_mul.cpp - max_filter.cpp - multi_output.cpp - overlap.cpp - param.cpp - reorder.cpp - tile_vs_inline.cpp - unused_func.cpp - vectorize_var_in_update.cpp - ) +if (TARGET Halide::Mullapudi2016) + tests(GROUPS auto_schedule + SOURCES + cost_function.cpp + data_dependent.cpp + extern.cpp + fibonacci.cpp + histogram.cpp + large_window.cpp + mat_mul.cpp + max_filter.cpp + multi_output.cpp + overlap.cpp + param.cpp + reorder.cpp + small_pure_update.cpp + tile_vs_inline.cpp + unused_func.cpp + vectorize_var_in_update.cpp + ARGS $) +else () + message(STATUS "Disabling autoscheduler tests for static Halide") +endif () diff --git a/test/auto_schedule/cost_function.cpp b/test/auto_schedule/cost_function.cpp index d1d4a07a9a18..4cdf4ea10377 100644 --- a/test/auto_schedule/cost_function.cpp +++ b/test/auto_schedule/cost_function.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + int W = 6400; int H = 4800; Buffer input(W, H); diff --git a/test/auto_schedule/data_dependent.cpp b/test/auto_schedule/data_dependent.cpp index 8cda0e0758c4..d42a8f75eafe 100644 --- a/test/auto_schedule/data_dependent.cpp +++ b/test/auto_schedule/data_dependent.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + int W = 800; int H = 800; Buffer input(W, H); diff --git a/test/auto_schedule/extern.cpp b/test/auto_schedule/extern.cpp index 581f7d4b9c92..e442d8aca902 100644 --- a/test/auto_schedule/extern.cpp +++ b/test/auto_schedule/extern.cpp @@ -128,10 +128,17 @@ void test_case_3() { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + test_case_1(); test_case_2(); test_case_3(); diff --git a/test/auto_schedule/fibonacci.cpp b/test/auto_schedule/fibonacci.cpp index 19cec9c1cbef..a394af50a921 100644 --- a/test/auto_schedule/fibonacci.cpp +++ b/test/auto_schedule/fibonacci.cpp @@ -39,10 +39,17 @@ double run_test(bool auto_schedule) { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + double manual_time = run_test(false); double auto_time = run_test(true); diff --git a/test/auto_schedule/histogram.cpp b/test/auto_schedule/histogram.cpp index f74d3b4d6713..c51cac7436b4 100644 --- a/test/auto_schedule/histogram.cpp +++ b/test/auto_schedule/histogram.cpp @@ -120,10 +120,17 @@ double run_test(bool auto_schedule) { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + double manual_time = run_test(false); double auto_time = run_test(true); diff --git a/test/auto_schedule/large_window.cpp b/test/auto_schedule/large_window.cpp index 7d7431a2f24a..923a8470c1ab 100644 --- a/test/auto_schedule/large_window.cpp +++ b/test/auto_schedule/large_window.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + int W = 800; int H = 1200; diff --git a/test/auto_schedule/mat_mul.cpp b/test/auto_schedule/mat_mul.cpp index a35ee0a53f29..07e5fefce2ca 100644 --- a/test/auto_schedule/mat_mul.cpp +++ b/test/auto_schedule/mat_mul.cpp @@ -123,10 +123,17 @@ double run_test(bool auto_schedule) { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + double manual_time = run_test(false); double auto_time = run_test(true); diff --git a/test/auto_schedule/max_filter.cpp b/test/auto_schedule/max_filter.cpp index 08740d3f92ea..fa9b72706d5d 100644 --- a/test/auto_schedule/max_filter.cpp +++ b/test/auto_schedule/max_filter.cpp @@ -123,10 +123,17 @@ double run_test(bool auto_schedule) { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + double manual_time = run_test(false); double auto_time = run_test(true); diff --git a/test/auto_schedule/multi_output.cpp b/test/auto_schedule/multi_output.cpp index 30042bb801fb..f00f4ee09fa3 100644 --- a/test/auto_schedule/multi_output.cpp +++ b/test/auto_schedule/multi_output.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + int W = 1000; int H = 1000; Buffer input(W, H); diff --git a/test/auto_schedule/overlap.cpp b/test/auto_schedule/overlap.cpp index b37a3a7c6337..d9e7fdf14232 100644 --- a/test/auto_schedule/overlap.cpp +++ b/test/auto_schedule/overlap.cpp @@ -5,10 +5,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + Var x("x"), y("y"), xi("xi"), yi("yi"); Buffer input = lambda(x, y, sin(x) + cos(y) + 1.0f).realize(2200, 2200); diff --git a/test/auto_schedule/param.cpp b/test/auto_schedule/param.cpp index ca50d9032a9a..1db0458d0e2f 100644 --- a/test/auto_schedule/param.cpp +++ b/test/auto_schedule/param.cpp @@ -115,10 +115,17 @@ void run_test_4() { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + std::cout << "Test 1:\n"; run_test_1(); std::cout << "Test 2:\n"; diff --git a/test/auto_schedule/reorder.cpp b/test/auto_schedule/reorder.cpp index 5149fdfe18fe..24c4893051f7 100644 --- a/test/auto_schedule/reorder.cpp +++ b/test/auto_schedule/reorder.cpp @@ -138,10 +138,17 @@ double run_test_3(bool auto_schedule) { int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + const double slowdown_factor = 6.0; { diff --git a/test/correctness/autoschedule_small_pure_update.cpp b/test/auto_schedule/small_pure_update.cpp similarity index 66% rename from test/correctness/autoschedule_small_pure_update.cpp rename to test/auto_schedule/small_pure_update.cpp index a59564b0597e..6d3fe2d2219b 100644 --- a/test/correctness/autoschedule_small_pure_update.cpp +++ b/test/auto_schedule/small_pure_update.cpp @@ -1,8 +1,19 @@ #include "Halide.h" - using namespace Halide; int main(int argc, char **argv) { + if (get_jit_target_from_environment().arch == Target::WebAssembly) { + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); + return 0; + } + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + Buffer in(13, 17); ImageParam in_param(Float(32), 2); diff --git a/test/auto_schedule/tile_vs_inline.cpp b/test/auto_schedule/tile_vs_inline.cpp index 5dce5a306ab3..1df108ac4a67 100644 --- a/test/auto_schedule/tile_vs_inline.cpp +++ b/test/auto_schedule/tile_vs_inline.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + int W = 1024; int H = 1024; diff --git a/test/auto_schedule/unused_func.cpp b/test/auto_schedule/unused_func.cpp index 8d084c12d975..24f1d33feb2c 100644 --- a/test/auto_schedule/unused_func.cpp +++ b/test/auto_schedule/unused_func.cpp @@ -4,10 +4,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + Var x("x"), y("y"); Func f("f"), g("g"), h("h"); diff --git a/test/auto_schedule/vectorize_var_in_update.cpp b/test/auto_schedule/vectorize_var_in_update.cpp index a8db91e90b0d..a00f24e88c78 100644 --- a/test/auto_schedule/vectorize_var_in_update.cpp +++ b/test/auto_schedule/vectorize_var_in_update.cpp @@ -5,10 +5,17 @@ using namespace Halide; int main(int argc, char **argv) { if (get_jit_target_from_environment().arch == Target::WebAssembly) { - printf("[SKIP] Mullapudi2016 autoscheduler does not support WebAssembly.\n"); + printf("[SKIP] Autoschedulers do not support WebAssembly.\n"); return 0; } + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + load_plugin(argv[1]); + // This test is making sure that the auto-scheduler picks the appropriate // tail strategy when splitting the var of an update definition. // The default tail strategy for this case (i.e. RoundUp) will cause diff --git a/test/correctness/CMakeLists.txt b/test/correctness/CMakeLists.txt index f82c777170fa..8c3c5d4638bf 100644 --- a/test/correctness/CMakeLists.txt +++ b/test/correctness/CMakeLists.txt @@ -14,7 +14,6 @@ tests(GROUPS correctness atomic_tuples.cpp atomics.cpp autodiff.cpp - autoschedule_small_pure_update.cpp autotune_bug.cpp autotune_bug_2.cpp autotune_bug_3.cpp diff --git a/test/generator/CMakeLists.txt b/test/generator/CMakeLists.txt index 342659232b3e..ccb1a0abf96d 100644 --- a/test/generator/CMakeLists.txt +++ b/test/generator/CMakeLists.txt @@ -153,15 +153,13 @@ halide_define_aot_test(async_parallel # autograd_aottest.cpp # autograd_generator.cpp -halide_define_aot_test(autograd - # Requires Mullapudi2016 autoscheduler, which doesn't support wasm - ENABLE_IF NOT ${USING_WASM}) +halide_define_aot_test(autograd ENABLE_IF TARGET Halide::Mullapudi2016 AND NOT ${USING_WASM}) if (TARGET generator_aot_autograd) add_halide_library(autograd_grad GRADIENT_DESCENT FROM autograd.generator GENERATOR autograd - PARAMS "auto_schedule=true") + AUTOSCHEDULER Halide::Mullapudi2016) target_link_libraries(generator_aot_autograd PRIVATE autograd_grad) endif () diff --git a/tools/build_halide_h.cpp b/tools/build_halide_h.cpp index ac2eba7ce98c..a170547e870f 100644 --- a/tools/build_halide_h.cpp +++ b/tools/build_halide_h.cpp @@ -88,7 +88,6 @@ int main(int argc, char **files) { "#undef internal_error\n" "#undef internal_assert\n" "#undef halide_runtime_error\n" - "#undef HALIDE_EXPORT\n\n" "#endif // HALIDE_H\n"); return 0; diff --git a/tools/mex_halide.m b/tools/mex_halide.m index 9d9d1d0f5e91..b1dba967c5a0 100644 --- a/tools/mex_halide.m +++ b/tools/mex_halide.m @@ -61,9 +61,9 @@ function mex_halide( generator_filename, varargin ) halide_distrib_path = getenv('HALIDE_DISTRIB_PATH'); if ismac - libhalide = fullfile(halide_distrib_path, 'bin', 'libHalide.dylib'); + libhalide = fullfile(halide_distrib_path, 'lib', 'libHalide.dylib'); else - libhalide = fullfile(halide_distrib_path, 'bin', 'libHalide.so'); + libhalide = fullfile(halide_distrib_path, 'lib', 'libHalide.so'); end halide_include = fullfile(halide_distrib_path, 'include'); @@ -73,7 +73,7 @@ function mex_halide( generator_filename, varargin ) end halide_cxx = getenv('HALIDE_CXX'); - ld_library_path = fullfile(halide_distrib_path, 'bin'); + ld_library_path = fullfile(halide_distrib_path, 'lib'); % Build the command to build the generator. gen_bin = fullfile(temp, [function_name, '.generator']); diff --git a/tools/package-unix.sh b/tools/package-unix.sh index d2e33de91059..ee351454ba38 100755 --- a/tools/package-unix.sh +++ b/tools/package-unix.sh @@ -24,6 +24,7 @@ cmake -G Ninja \ -DWITH_DOCS=YES \ -DWITH_UTILS=NO \ -DWITH_PYTHON_BINDINGS=NO \ + -DCMAKE_INSTALL_DATADIR="share/Halide" \ -S "$halide_source" \ -B "$halide_build_root/shared-Release" @@ -40,6 +41,7 @@ cmake -G Ninja \ -DWITH_DOCS=YES \ -DWITH_UTILS=NO \ -DWITH_PYTHON_BINDINGS=NO \ + -DCMAKE_INSTALL_DATADIR="share/Halide" \ -S "$halide_source" \ -B "$halide_build_root/static-Release" diff --git a/tools/package-windows.bat b/tools/package-windows.bat index bbab5fd2e849..51154acacb0a 100644 --- a/tools/package-windows.bat +++ b/tools/package-windows.bat @@ -57,6 +57,7 @@ cmake -G "Visual Studio 16 2019" -Thost=x64 -A "%halide_arch%" ^ "-DCMAKE_INSTALL_BINDIR=bin/$" ^ "-DCMAKE_INSTALL_LIBDIR=lib/$" ^ "-DHALIDE_INSTALL_CMAKEDIR=lib" ^ + "-DHALIDE_INSTALL_DATADIR=share/Halide" ^ -S "%halide_source%" ^ -B "%halide_build_root%" if ERRORLEVEL 1 goto error diff --git a/tutorial/CMakeLists.txt b/tutorial/CMakeLists.txt index 1ee71b060a58..cff1c8d1ff7b 100644 --- a/tutorial/CMakeLists.txt +++ b/tutorial/CMakeLists.txt @@ -101,7 +101,7 @@ target_link_libraries(lesson_15_generate PRIVATE Halide::Generator) ## Hack to build the libraries add_custom_target(lesson_15_targets) -unset(LESSON_15_EXPECTED_FILES) +set(LESSON_15_EXPECTED_FILES "") ## add_halide_library(my_first_generator_win32 FROM lesson_15_generate @@ -188,17 +188,17 @@ add_tutorial(lesson_19_wrapper_funcs.cpp) add_tutorial(lesson_20_cloning_funcs.cpp) # Lesson 21 -if (TARGET_WEBASSEMBLY AND Halide_TARGET MATCHES "wasm") - # TODO: Requires custom build rules to work under wasm - message(WARNING "Not all tutorials build under WASM.") -else () +if (TARGET Halide::Mullapudi2016) add_executable(lesson_21_auto_scheduler_generate lesson_21_auto_scheduler_generate.cpp) target_link_libraries(lesson_21_auto_scheduler_generate PRIVATE Halide::Generator) add_halide_library(auto_schedule_false FROM lesson_21_auto_scheduler_generate + TARGETS cmake GENERATOR auto_schedule_gen PARAMS auto_schedule=false) add_halide_library(auto_schedule_true FROM lesson_21_auto_scheduler_generate - GENERATOR auto_schedule_gen PARAMS auto_schedule=true machine_params=32,16777216,40) + TARGETS cmake + AUTOSCHEDULER Halide::Mullapudi2016 + GENERATOR auto_schedule_gen PARAMS machine_params=32,16777216,40) add_executable(lesson_21_auto_scheduler_run lesson_21_auto_scheduler_run.cpp) target_link_libraries(lesson_21_auto_scheduler_run PRIVATE diff --git a/tutorial/figures/generate_figures_17.sh b/tutorial/figures/generate_figures_17.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_figures_18.sh b/tutorial/figures/generate_figures_18.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_figures_19.sh b/tutorial/figures/generate_figures_19.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_figures_5.sh b/tutorial/figures/generate_figures_5.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_figures_8.sh b/tutorial/figures/generate_figures_8.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_figures_9.sh b/tutorial/figures/generate_figures_9.sh old mode 100644 new mode 100755 diff --git a/tutorial/figures/generate_output_snippets.sh b/tutorial/figures/generate_output_snippets.sh old mode 100644 new mode 100755 diff --git a/tutorial/lesson_01_basics.cpp b/tutorial/lesson_01_basics.cpp index 793e6200256e..38d949c4cd62 100644 --- a/tutorial/lesson_01_basics.cpp +++ b/tutorial/lesson_01_basics.cpp @@ -3,12 +3,12 @@ // This lesson demonstrates basic usage of Halide as a JIT compiler for imaging. // On linux, you can compile and run it like so: -// g++ lesson_01*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_01 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_01 +// g++ lesson_01*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_01 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_01 // On os x: -// g++ lesson_01*.cpp -g -I ../include -L ../bin -lHalide -o lesson_01 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_01 +// g++ lesson_01*.cpp -g -I -L -lHalide -o lesson_01 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_01 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_02_input_image.cpp b/tutorial/lesson_02_input_image.cpp index 45b49b1df14e..20f9485cfc63 100644 --- a/tutorial/lesson_02_input_image.cpp +++ b/tutorial/lesson_02_input_image.cpp @@ -4,12 +4,12 @@ // them. // On linux, you can compile and run it like so: -// g++ lesson_02*.cpp -g -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_02 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_02 +// g++ lesson_02*.cpp -g -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_02 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_02 // On os x: -// g++ lesson_02*.cpp -g -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_02 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_02 +// g++ lesson_02*.cpp -g -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_02 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_02 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_03_debugging_1.cpp b/tutorial/lesson_03_debugging_1.cpp index 2aa1fd1209dd..11f7a4211ecc 100644 --- a/tutorial/lesson_03_debugging_1.cpp +++ b/tutorial/lesson_03_debugging_1.cpp @@ -3,12 +3,12 @@ // This lesson demonstrates how to inspect what the Halide compiler is producing. // On linux, you can compile and run it like so: -// g++ lesson_03*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_03 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_03 +// g++ lesson_03*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_03 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_03 // On os x: -// g++ lesson_03*.cpp -g -I ../include -L ../bin -lHalide -o lesson_03 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_03 +// g++ lesson_03*.cpp -g -I -L -lHalide -o lesson_03 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_03 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_04_debugging_2.cpp b/tutorial/lesson_04_debugging_2.cpp index f46f2eb90df5..49cd17df0a9b 100644 --- a/tutorial/lesson_04_debugging_2.cpp +++ b/tutorial/lesson_04_debugging_2.cpp @@ -3,12 +3,12 @@ // This lesson demonstrates how to follow what Halide is doing at runtime. // On linux, you can compile and run it like so: -// g++ lesson_04*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_04 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_04 +// g++ lesson_04*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_04 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_04 // On os x: -// g++ lesson_04*.cpp -g -I ../include -L ../bin -lHalide -o lesson_04 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_04 +// g++ lesson_04*.cpp -g -I -L -lHalide -o lesson_04 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_04 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_05_scheduling_1.cpp b/tutorial/lesson_05_scheduling_1.cpp index 09736064b32b..2ac3930a1306 100644 --- a/tutorial/lesson_05_scheduling_1.cpp +++ b/tutorial/lesson_05_scheduling_1.cpp @@ -5,12 +5,12 @@ // parallelization, unrolling, and tiling. // On linux, you can compile and run it like so: -// g++ lesson_05*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_05 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_05 +// g++ lesson_05*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_05 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_05 // On os x: -// g++ lesson_05*.cpp -g -I ../include -L ../bin -lHalide -o lesson_05 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_05 +// g++ lesson_05*.cpp -g -I -L -lHalide -o lesson_05 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_05 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_06_realizing_over_shifted_domains.cpp b/tutorial/lesson_06_realizing_over_shifted_domains.cpp index 52df9c5465e9..283df77365ab 100644 --- a/tutorial/lesson_06_realizing_over_shifted_domains.cpp +++ b/tutorial/lesson_06_realizing_over_shifted_domains.cpp @@ -4,12 +4,12 @@ // does not start at (0, 0). // On linux, you can compile and run it like so: -// g++ lesson_06*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_06 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_06 +// g++ lesson_06*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_06 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_06 // On os x: -// g++ lesson_06*.cpp -g -I ../include -L ../bin -lHalide -o lesson_06 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_06 +// g++ lesson_06*.cpp -g -I -L -lHalide -o lesson_06 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_06 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_07_multi_stage_pipelines.cpp b/tutorial/lesson_07_multi_stage_pipelines.cpp index 68a5869eb775..49df7a804675 100644 --- a/tutorial/lesson_07_multi_stage_pipelines.cpp +++ b/tutorial/lesson_07_multi_stage_pipelines.cpp @@ -1,12 +1,12 @@ // Halide tutorial lesson 7: Multi-stage pipelines // On linux, you can compile and run it like so: -// g++ lesson_07*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_07 -// LD_LIBRARY_PATH=../bin ./lesson_07 +// g++ lesson_07*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_07 +// LD_LIBRARY_PATH= ./lesson_07 // On os x: -// g++ lesson_07*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_07 -// DYLD_LIBRARY_PATH=../bin ./lesson_07 +// g++ lesson_07*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_07 +// DYLD_LIBRARY_PATH= ./lesson_07 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_08_scheduling_2.cpp b/tutorial/lesson_08_scheduling_2.cpp index 32ea325f7510..80db19489b7e 100644 --- a/tutorial/lesson_08_scheduling_2.cpp +++ b/tutorial/lesson_08_scheduling_2.cpp @@ -1,12 +1,12 @@ // Halide tutorial lesson 8: Scheduling multi-stage pipelines // On linux, you can compile and run it like so: -// g++ lesson_08*.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_08 -// LD_LIBRARY_PATH=../bin ./lesson_08 +// g++ lesson_08*.cpp -g -std=c++11 -I -L -lHalide -lpthread -ldl -o lesson_08 +// LD_LIBRARY_PATH= ./lesson_08 // On os x: -// g++ lesson_08*.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -o lesson_08 -// DYLD_LIBRARY_PATH=../bin ./lesson_08 +// g++ lesson_08*.cpp -g -std=c++11 -I -L -lHalide -o lesson_08 +// DYLD_LIBRARY_PATH= ./lesson_08 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_09_update_definitions.cpp b/tutorial/lesson_09_update_definitions.cpp index 799cb4ef152a..f48480b3c2fc 100644 --- a/tutorial/lesson_09_update_definitions.cpp +++ b/tutorial/lesson_09_update_definitions.cpp @@ -1,12 +1,12 @@ // Halide tutorial lesson 9: Multi-pass Funcs, update definitions, and reductions // On linux, you can compile and run it like so: -// g++ lesson_09*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -fopenmp -o lesson_09 -// LD_LIBRARY_PATH=../bin ./lesson_09 +// g++ lesson_09*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -fopenmp -o lesson_09 +// LD_LIBRARY_PATH= ./lesson_09 // On os x (will only work if you actually have g++, not Apple's pretend g++ which is actually clang): -// g++ lesson_09*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -fopenmp -o lesson_09 -// DYLD_LIBRARY_PATH=../bin ./lesson_09 +// g++ lesson_09*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -fopenmp -o lesson_09 +// DYLD_LIBRARY_PATH= ./lesson_09 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_10_aot_compilation_generate.cpp b/tutorial/lesson_10_aot_compilation_generate.cpp index 9ead4ded78f1..989dff124bfa 100644 --- a/tutorial/lesson_10_aot_compilation_generate.cpp +++ b/tutorial/lesson_10_aot_compilation_generate.cpp @@ -10,15 +10,15 @@ // compiling this code is a multi-step process. // On linux, you can compile and run it like so: -// g++ lesson_10*generate.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_10_generate -// LD_LIBRARY_PATH=../bin ./lesson_10_generate -// g++ lesson_10*run.cpp lesson_10_halide.a -std=c++11 -I ../include -lpthread -ldl -o lesson_10_run +// g++ lesson_10*generate.cpp -g -std=c++11 -I -L -lHalide -lpthread -ldl -o lesson_10_generate +// LD_LIBRARY_PATH= ./lesson_10_generate +// g++ lesson_10*run.cpp lesson_10_halide.a -std=c++11 -I -lpthread -ldl -o lesson_10_run // ./lesson_10_run // On os x: -// g++ lesson_10*generate.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -o lesson_10_generate -// DYLD_LIBRARY_PATH=../bin ./lesson_10_generate -// g++ lesson_10*run.cpp lesson_10_halide.a -o lesson_10_run -I ../include +// g++ lesson_10*generate.cpp -g -std=c++11 -I -L -lHalide -o lesson_10_generate +// DYLD_LIBRARY_PATH= ./lesson_10_generate +// g++ lesson_10*run.cpp lesson_10_halide.a -o lesson_10_run -I // ./lesson_10_run // The benefits of this approach are that the final program: diff --git a/tutorial/lesson_11_cross_compilation.cpp b/tutorial/lesson_11_cross_compilation.cpp index 6b479cdea942..617dbeb5a210 100644 --- a/tutorial/lesson_11_cross_compilation.cpp +++ b/tutorial/lesson_11_cross_compilation.cpp @@ -4,12 +4,12 @@ // generate code for any platform from any platform. // On linux, you can compile and run it like so: -// g++ lesson_11*.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_11 -// LD_LIBRARY_PATH=../bin ./lesson_11 +// g++ lesson_11*.cpp -g -std=c++11 -I -L -lHalide -lpthread -ldl -o lesson_11 +// LD_LIBRARY_PATH= ./lesson_11 // On os x: -// g++ lesson_11*.cpp -g -std=c++11 -I ../include -L ../bin -lHalide -o lesson_11 -// DYLD_LIBRARY_PATH=../bin ./lesson_11 +// g++ lesson_11*.cpp -g -std=c++11 -I -L -lHalide -o lesson_11 +// DYLD_LIBRARY_PATH= ./lesson_11 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_12_using_the_gpu.cpp b/tutorial/lesson_12_using_the_gpu.cpp index a6ed49ccfb37..682a7ff81410 100644 --- a/tutorial/lesson_12_using_the_gpu.cpp +++ b/tutorial/lesson_12_using_the_gpu.cpp @@ -3,12 +3,12 @@ // This lesson demonstrates how to use Halide to run code on a GPU using OpenCL. // On linux, you can compile and run it like so: -// g++ lesson_12*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_12 -// LD_LIBRARY_PATH=../bin ./lesson_12 +// g++ lesson_12*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_12 +// LD_LIBRARY_PATH= ./lesson_12 // On os x: -// g++ lesson_12*.cpp -g -std=c++11 -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_12 -// DYLD_LIBRARY_PATH=../bin ./lesson_12 +// g++ lesson_12*.cpp -g -std=c++11 -I -I -L -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_12 +// DYLD_LIBRARY_PATH= ./lesson_12 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_13_tuples.cpp b/tutorial/lesson_13_tuples.cpp index 03d717e166cc..5218cb01e652 100644 --- a/tutorial/lesson_13_tuples.cpp +++ b/tutorial/lesson_13_tuples.cpp @@ -4,12 +4,12 @@ // values. // On linux, you can compile and run it like so: -// g++ lesson_13*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_13 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_13 +// g++ lesson_13*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_13 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_13 // On os x: -// g++ lesson_13*.cpp -g -I ../include -L ../bin -lHalide -o lesson_13 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_13 +// g++ lesson_13*.cpp -g -I -L -lHalide -o lesson_13 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_13 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_14_types.cpp b/tutorial/lesson_14_types.cpp index abde0858896f..8a370c1084f2 100644 --- a/tutorial/lesson_14_types.cpp +++ b/tutorial/lesson_14_types.cpp @@ -3,12 +3,12 @@ // This lesson more precisely describes Halide's type system. // On linux, you can compile and run it like so: -// g++ lesson_14*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_14 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_14 +// g++ lesson_14*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_14 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_14 // On os x: -// g++ lesson_14*.cpp -g -I ../include -L ../bin -lHalide -o lesson_14 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_14 +// g++ lesson_14*.cpp -g -I -L -lHalide -o lesson_14 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_14 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_15_generators.cpp b/tutorial/lesson_15_generators.cpp index 7451aeeae312..2f194248f79d 100644 --- a/tutorial/lesson_15_generators.cpp +++ b/tutorial/lesson_15_generators.cpp @@ -4,11 +4,11 @@ // reusable components called generators. // On linux, you can compile and run it like so: -// g++ lesson_15*.cpp ../tools/GenGen.cpp -g -std=c++11 -fno-rtti -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_15_generate +// g++ lesson_15*.cpp /GenGen.cpp -g -std=c++11 -fno-rtti -I -L -lHalide -lpthread -ldl -o lesson_15_generate // bash lesson_15_generators_usage.sh // On os x: -// g++ lesson_15*.cpp ../tools/GenGen.cpp -g -std=c++11 -fno-rtti -I ../include -L ../bin -lHalide -o lesson_15_generate +// g++ lesson_15*.cpp /GenGen.cpp -g -std=c++11 -fno-rtti -I -L -lHalide -o lesson_15_generate // bash lesson_15_generators_usage.sh // If you have the entire Halide source tree, you can also build it by diff --git a/tutorial/lesson_15_generators_usage.sh b/tutorial/lesson_15_generators_usage.sh old mode 100644 new mode 100755 index 7ddf2a360361..f8bf34eebbdf --- a/tutorial/lesson_15_generators_usage.sh +++ b/tutorial/lesson_15_generators_usage.sh @@ -37,8 +37,8 @@ check_symbol() #set -e # Set up LD_LIBRARY_PATH so that we can find libHalide.so -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../bin -export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:../bin +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../lib +export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:../lib ######################### # Basic generator usage # diff --git a/tutorial/lesson_16_rgb_generate.cpp b/tutorial/lesson_16_rgb_generate.cpp index 53db6242cf38..5b57548994f3 100644 --- a/tutorial/lesson_16_rgb_generate.cpp +++ b/tutorial/lesson_16_rgb_generate.cpp @@ -6,9 +6,9 @@ // On linux or os x, you can compile and run it like so: -// g++ lesson_16_rgb_generate.cpp ../tools/GenGen.cpp -g -std=c++11 -fno-rtti -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_16_generate -// export LD_LIBRARY_PATH=../bin # For linux -// export DYLD_LIBRARY_PATH=../bin # For OS X +// g++ lesson_16_rgb_generate.cpp /GenGen.cpp -g -std=c++11 -fno-rtti -I -L -lHalide -lpthread -ldl -o lesson_16_generate +// export LD_LIBRARY_PATH= # For linux +// export DYLD_LIBRARY_PATH= # For OS X // ./lesson_16_generate -g brighten -o . -f brighten_planar target=host layout=planar // ./lesson_16_generate -g brighten -o . -f brighten_interleaved target=host layout=interleaved // ./lesson_16_generate -g brighten -o . -f brighten_either target=host layout=either diff --git a/tutorial/lesson_17_predicated_rdom.cpp b/tutorial/lesson_17_predicated_rdom.cpp index 39a4d4f42c1b..a781fe2bc038 100644 --- a/tutorial/lesson_17_predicated_rdom.cpp +++ b/tutorial/lesson_17_predicated_rdom.cpp @@ -4,12 +4,12 @@ // subsets of a reduction domain using predicates. // On linux, you can compile and run it like so: -// g++ lesson_17*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_17 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_17 +// g++ lesson_17*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_17 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_17 // On os x: -// g++ lesson_17*.cpp -g -I ../include -L ../bin -lHalide -o lesson_17 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_17 +// g++ lesson_17*.cpp -g -I -L -lHalide -o lesson_17 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_17 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_18_parallel_associative_reductions.cpp b/tutorial/lesson_18_parallel_associative_reductions.cpp index 321be8bc43d8..db628a662f90 100644 --- a/tutorial/lesson_18_parallel_associative_reductions.cpp +++ b/tutorial/lesson_18_parallel_associative_reductions.cpp @@ -4,12 +4,12 @@ // reduction using the scheduling directive 'rfactor'. // On linux, you can compile and run it like so: -// g++ lesson_18*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_18 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_18 +// g++ lesson_18*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_18 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_18 // On os x: -// g++ lesson_18*.cpp -g -I ../include -L ../bin -lHalide -o lesson_18 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_18 +// g++ lesson_18*.cpp -g -I -L -lHalide -o lesson_18 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_18 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_19_wrapper_funcs.cpp b/tutorial/lesson_19_wrapper_funcs.cpp index dad723a988ac..47daa4831968 100644 --- a/tutorial/lesson_19_wrapper_funcs.cpp +++ b/tutorial/lesson_19_wrapper_funcs.cpp @@ -5,12 +5,12 @@ // from a Func or an ImageParam. // On linux, you can compile and run it like so: -// g++ lesson_19*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_19 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_19 +// g++ lesson_19*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_19 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_19 // On os x: -// g++ lesson_19*.cpp -g -I ../include -L ../bin -lHalide -o lesson_19 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_19 +// g++ lesson_19*.cpp -g -I -L -lHalide -o lesson_19 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_19 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_20_cloning_funcs.cpp b/tutorial/lesson_20_cloning_funcs.cpp index 23f3fb4f040d..452977272762 100644 --- a/tutorial/lesson_20_cloning_funcs.cpp +++ b/tutorial/lesson_20_cloning_funcs.cpp @@ -4,12 +4,12 @@ // a Func. // On linux, you can compile and run it like so: -// g++ lesson_20*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_20 -std=c++11 -// LD_LIBRARY_PATH=../bin ./lesson_20 +// g++ lesson_20*.cpp -g -I -L -lHalide -lpthread -ldl -o lesson_20 -std=c++11 +// LD_LIBRARY_PATH= ./lesson_20 // On os x: -// g++ lesson_20*.cpp -g -I ../include -L ../bin -lHalide -o lesson_20 -std=c++11 -// DYLD_LIBRARY_PATH=../bin ./lesson_20 +// g++ lesson_20*.cpp -g -I -L -lHalide -o lesson_20 -std=c++11 +// DYLD_LIBRARY_PATH= ./lesson_20 // If you have the entire Halide source tree, you can also build it by // running: diff --git a/tutorial/lesson_21_auto_scheduler_generate.cpp b/tutorial/lesson_21_auto_scheduler_generate.cpp index 732d1b6c4e87..652637e89858 100644 --- a/tutorial/lesson_21_auto_scheduler_generate.cpp +++ b/tutorial/lesson_21_auto_scheduler_generate.cpp @@ -7,12 +7,12 @@ // On linux or os x, you can compile and run it like so: -// g++ lesson_21_auto_scheduler_generate.cpp ../tools/GenGen.cpp -g -std=c++11 -fno-rtti -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_21_generate -// export LD_LIBRARY_PATH=../bin # For linux -// export DYLD_LIBRARY_PATH=../bin # For OS X +// g++ lesson_21_auto_scheduler_generate.cpp /GenGen.cpp -g -std=c++11 -fno-rtti -I -L -lHalide -lpthread -ldl -o lesson_21_generate +// export LD_LIBRARY_PATH= # For linux +// export DYLD_LIBRARY_PATH= # For OS X // ./lesson_21_generate -o . -g auto_schedule_gen -f auto_schedule_false -e static_library,h,schedule target=host auto_schedule=false -// ./lesson_21_generate -o . -g auto_schedule_gen -f auto_schedule_true -e static_library,h,schedule target=host auto_schedule=true machine_params=32,16777216,40 -// g++ lesson_21_auto_scheduler_run.cpp -std=c++11 -I ../include -I ../tools auto_schedule_false.a auto_schedule_true.a -ldl -lpthread -o lesson_21_run +// ./lesson_21_generate -o . -g auto_schedule_gen -f auto_schedule_true -e static_library,h,schedule -p -S Mullapudi2016 target=host auto_schedule=true machine_params=32,16777216,40 +// g++ lesson_21_auto_scheduler_run.cpp -std=c++11 -I -I auto_schedule_false.a auto_schedule_true.a -ldl -lpthread -o lesson_21_run // ./lesson_21_run // If you have the entire Halide source tree, you can also build it by