From c0cf44d494ae7d2d18ca4782a87d177725c5aba1 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Tue, 15 Aug 2023 14:02:48 -0700 Subject: [PATCH 01/22] add back JIT testing, enclosed in #ifdef blocks --- src/CMakeLists.txt | 9 +++++++++ src/Pipeline.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47e90864de40..246f953fbf3f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -508,6 +508,15 @@ if (WITH_SERIALIZATION) target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION) endif () +# Enable serialization testing by intercepting JIT compilation with a serialization roundtrip, +# it is for a special build that is only useful for testing serialization, disabled by default +option(WITH_SERIALZATION_JIT "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) +if (WITH_SERIALZATION_JIT) + if (WITH_SERIALIZATION) + target_compile_definitions(Halide PRIVATE WITH_SERIALZATION_JIT) + endif () +endif () + add_library(Halide::Halide ALIAS Halide) target_link_libraries(Halide PRIVATE Halide::LLVM) diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index a3cdcd342639..27c6e01ebddc 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -582,6 +582,25 @@ void Pipeline::compile_jit(const Target &target_arg) { // Clear all cached info in case there is an error. contents->invalidate_cache(); +#ifdef WITH_SERIALZATION_JIT + // TODO: replace file serialization with in-memory serialization + std::string filename = generate_function_name() + ".hlpipe"; + std::map external_params; + serialize_pipeline(*this, filename, external_params); + Pipeline deserialized_pipe = deserialize_pipeline(filename, external_params); + std::vector outputs; + for (const Func &f : deserialized_pipe.outputs()) { + outputs.push_back(f.function()); + } + // we save the original output functions and requirements + // and restore them once all lowering is done + // so reschedule/reorder storage can be properly handled + std::vector origin_outputs = contents->outputs; + std::vector origin_requirements = contents->requirements; + contents->outputs = outputs; + contents->requirements = deserialized_pipe.requirements(); +#endif + // Infer an arguments vector infer_arguments(); @@ -597,6 +616,11 @@ void Pipeline::compile_jit(const Target &target_arg) { Module module = compile_to_module(args, generate_function_name(), target).resolve_submodules(); std::map lowered_externs = contents->jit_externs; contents->jit_cache = compile_jit_cache(module, std::move(args), contents->outputs, contents->jit_externs, target); +#ifdef WITH_SERIALZATION_JIT + // restore the original outputs and requirements + contents->outputs = origin_outputs; + contents->requirements = origin_requirements; +#endif } Callable Pipeline::compile_to_callable(const std::vector &args_in, const Target &target_arg) { From d67466237b9403783c94a330283b03bc1ff80371 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Tue, 15 Aug 2023 14:11:01 -0700 Subject: [PATCH 02/22] fix typo --- src/CMakeLists.txt | 6 +++--- src/Pipeline.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 246f953fbf3f..5c9db0e4a9c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -510,10 +510,10 @@ endif () # Enable serialization testing by intercepting JIT compilation with a serialization roundtrip, # it is for a special build that is only useful for testing serialization, disabled by default -option(WITH_SERIALZATION_JIT "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) -if (WITH_SERIALZATION_JIT) +option(WITH_SERIALIZATION_JIT "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) +if (WITH_SERIALIZATION_JIT) if (WITH_SERIALIZATION) - target_compile_definitions(Halide PRIVATE WITH_SERIALZATION_JIT) + target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION_JIT) endif () endif () diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index 27c6e01ebddc..d2c2771248f1 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -582,7 +582,7 @@ void Pipeline::compile_jit(const Target &target_arg) { // Clear all cached info in case there is an error. contents->invalidate_cache(); -#ifdef WITH_SERIALZATION_JIT +#ifdef WITH_SERIALIZATION_JIT // TODO: replace file serialization with in-memory serialization std::string filename = generate_function_name() + ".hlpipe"; std::map external_params; @@ -616,7 +616,7 @@ void Pipeline::compile_jit(const Target &target_arg) { Module module = compile_to_module(args, generate_function_name(), target).resolve_submodules(); std::map lowered_externs = contents->jit_externs; contents->jit_cache = compile_jit_cache(module, std::move(args), contents->outputs, contents->jit_externs, target); -#ifdef WITH_SERIALZATION_JIT +#ifdef WITH_SERIALIZATION_JIT // restore the original outputs and requirements contents->outputs = origin_outputs; contents->requirements = origin_requirements; From 3a2de83fc656de6bae645d0a9588e2c9ff83a8b7 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Wed, 16 Aug 2023 11:53:58 -0700 Subject: [PATCH 03/22] nits --- src/CMakeLists.txt | 4 ++-- src/Pipeline.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c9db0e4a9c3..05cb20d0533f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -508,8 +508,8 @@ if (WITH_SERIALIZATION) target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION) endif () -# Enable serialization testing by intercepting JIT compilation with a serialization roundtrip, -# it is for a special build that is only useful for testing serialization, disabled by default +# Enable serialization testing by intercepting JIT compilation with a serialization roundtrip; +# This is used only for special builds made specifically for testing, and must be disabled by default. option(WITH_SERIALIZATION_JIT "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) if (WITH_SERIALIZATION_JIT) if (WITH_SERIALIZATION) diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index d2c2771248f1..7085eb88514c 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -583,7 +583,7 @@ void Pipeline::compile_jit(const Target &target_arg) { contents->invalidate_cache(); #ifdef WITH_SERIALIZATION_JIT - // TODO: replace file serialization with in-memory serialization + // TODO(https://github.com/halide/Halide/pull/7760): replace file serialization with in-memory serialization std::string filename = generate_function_name() + ".hlpipe"; std::map external_params; serialize_pipeline(*this, filename, external_params); @@ -592,9 +592,9 @@ void Pipeline::compile_jit(const Target &target_arg) { for (const Func &f : deserialized_pipe.outputs()) { outputs.push_back(f.function()); } - // we save the original output functions and requirements - // and restore them once all lowering is done - // so reschedule/reorder storage can be properly handled + // We save the original output functions and requirements, + // and restore them once all lowering is done, + // so that reschedule/reorder storage can be properly handled. std::vector origin_outputs = contents->outputs; std::vector origin_requirements = contents->requirements; contents->outputs = outputs; @@ -617,7 +617,7 @@ void Pipeline::compile_jit(const Target &target_arg) { std::map lowered_externs = contents->jit_externs; contents->jit_cache = compile_jit_cache(module, std::move(args), contents->outputs, contents->jit_externs, target); #ifdef WITH_SERIALIZATION_JIT - // restore the original outputs and requirements + // Restore the original outputs and requirements. contents->outputs = origin_outputs; contents->requirements = origin_requirements; #endif From de155f1a13b97373a0b46bbf297c0f068ad30a1f Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 23 Aug 2023 09:32:17 -0700 Subject: [PATCH 04/22] WITH_SERIALIZATION_JIT->WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING --- src/CMakeLists.txt | 6 +++--- src/Pipeline.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 05cb20d0533f..d003254405a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -510,10 +510,10 @@ endif () # Enable serialization testing by intercepting JIT compilation with a serialization roundtrip; # This is used only for special builds made specifically for testing, and must be disabled by default. -option(WITH_SERIALIZATION_JIT "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) -if (WITH_SERIALIZATION_JIT) +option(WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING "Intercepting JIT compilation with a serialization roundtrip, for test only" OFF) +if (WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING) if (WITH_SERIALIZATION) - target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION_JIT) + target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING) endif () endif () diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index 7085eb88514c..65f14e019499 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -582,7 +582,7 @@ void Pipeline::compile_jit(const Target &target_arg) { // Clear all cached info in case there is an error. contents->invalidate_cache(); -#ifdef WITH_SERIALIZATION_JIT +#ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING // TODO(https://github.com/halide/Halide/pull/7760): replace file serialization with in-memory serialization std::string filename = generate_function_name() + ".hlpipe"; std::map external_params; @@ -616,7 +616,7 @@ void Pipeline::compile_jit(const Target &target_arg) { Module module = compile_to_module(args, generate_function_name(), target).resolve_submodules(); std::map lowered_externs = contents->jit_externs; contents->jit_cache = compile_jit_cache(module, std::move(args), contents->outputs, contents->jit_externs, target); -#ifdef WITH_SERIALIZATION_JIT +#ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING // Restore the original outputs and requirements. contents->outputs = origin_outputs; contents->requirements = origin_requirements; From 7260cd925f2dc2678ef34f9d3c6d578525ef280a Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Fri, 25 Aug 2023 16:46:45 -0700 Subject: [PATCH 05/22] fix self-reference leaks: now uses weak function ptr in reverse function mappings --- src/Deserialization.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Deserialization.cpp b/src/Deserialization.cpp index d40c3d746893..350d6ca4c095 100644 --- a/src/Deserialization.cpp +++ b/src/Deserialization.cpp @@ -1267,7 +1267,12 @@ void Deserializer::build_reverse_function_mappings(const std::vector & } int count = 0; for (const auto &f : functions) { - this->reverse_function_mappings[count++] = f.get_contents(); + // The reverse function mappings are used in places where only weak references are needed. + FunctionPtr ptr; + ptr.strong = nullptr; + ptr.weak = f.get_contents().group(); + ptr.idx = f.get_contents().idx; + this->reverse_function_mappings[count++] = ptr; } } From ee10d4ce8c64f64528587f014d91d2595fc5d458 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 28 Aug 2023 16:56:51 -0700 Subject: [PATCH 06/22] Move clang-tidy checks back to Linux Recent changes in the GHA runners for macOS don't play well with clang-tidy; rather than sink any more time into debugging it, I'm going to revert the relevant parts of #7746 so that it runs on the less-finicky Linux runners instead. --- .github/workflows/presubmit.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index d94eba3e4b2e..bebe3280fb5a 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -28,26 +28,22 @@ jobs: # a bit of a sluggard check_clang_tidy: name: Check clang-tidy - runs-on: macos-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - # Workaround for https://github.com/actions/setup-python/issues/577 - - name: Clean up python binaries - run: | - rm -f /usr/local/bin/2to3*; - rm -f /usr/local/bin/idle3*; - rm -f /usr/local/bin/pydoc3*; - rm -f /usr/local/bin/python3*; - rm -f /usr/local/bin/python3*-config; - name: Install clang-tidy run: | - brew update - brew install llvm@16 ninja coreutils flatbuffers + # from apt.llvm.org + # wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421 + sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-16 main" + sudo apt-get update + sudo apt-get install llvm-16 clang-16 liblld-16-dev libclang-16-dev clang-tidy-16 ninja-build - name: Run clang-tidy run: | - export CC=/usr/local/opt/llvm/bin/clang - export CXX=/usr/local/opt/llvm/bin/clang++ - export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/local/opt/llvm + export CC=clang-16 + export CXX=clang++-16 + export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-16 export CMAKE_GENERATOR=Ninja ./run-clang-tidy.sh check_cmake_file_lists: From 20cf4714e58cc909e10d5cd429e5834d195cbc5b Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 28 Aug 2023 16:58:51 -0700 Subject: [PATCH 07/22] bogus --- src/Generator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Generator.cpp b/src/Generator.cpp index 67a132a4d4d9..6fe0e80a5b39 100644 --- a/src/Generator.cpp +++ b/src/Generator.cpp @@ -639,6 +639,9 @@ int generate_filter_main_inner(int argc, const GeneratorFactoryProvider &generator_factory_provider) { static const char kUsage[] = R"INLINE_CODE( gengen + +FOO + [-g GENERATOR_NAME] [-f FUNCTION_NAME] [-o OUTPUT_DIR] [-r RUNTIME_NAME] [-d 1|0] [-e EMIT_OPTIONS] [-n FILE_BASE_NAME] [-p PLUGIN_NAME] [-s AUTOSCHEDULER_NAME] [-t TIMEOUT] From b4fff910671994088e915d003b52420e1602a793 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 28 Aug 2023 17:20:13 -0700 Subject: [PATCH 08/22] Update Generator.cpp --- src/Generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator.cpp b/src/Generator.cpp index 6fe0e80a5b39..93215c926795 100644 --- a/src/Generator.cpp +++ b/src/Generator.cpp @@ -640,7 +640,7 @@ int generate_filter_main_inner(int argc, static const char kUsage[] = R"INLINE_CODE( gengen -FOO +FOOz [-g GENERATOR_NAME] [-f FUNCTION_NAME] [-o OUTPUT_DIR] [-r RUNTIME_NAME] [-d 1|0] [-e EMIT_OPTIONS] [-n FILE_BASE_NAME] [-p PLUGIN_NAME] From 9b812b8b43ef462f4d0b3985ae814e310d206d9f Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Tue, 29 Aug 2023 08:50:07 -0700 Subject: [PATCH 09/22] Update Generator.cpp --- src/Generator.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Generator.cpp b/src/Generator.cpp index 93215c926795..67a132a4d4d9 100644 --- a/src/Generator.cpp +++ b/src/Generator.cpp @@ -639,9 +639,6 @@ int generate_filter_main_inner(int argc, const GeneratorFactoryProvider &generator_factory_provider) { static const char kUsage[] = R"INLINE_CODE( gengen - -FOOz - [-g GENERATOR_NAME] [-f FUNCTION_NAME] [-o OUTPUT_DIR] [-r RUNTIME_NAME] [-d 1|0] [-e EMIT_OPTIONS] [-n FILE_BASE_NAME] [-p PLUGIN_NAME] [-s AUTOSCHEDULER_NAME] [-t TIMEOUT] From 4bd717995572a1d299dd982d4f3dae9776209801 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Wed, 13 Sep 2023 17:28:25 -0700 Subject: [PATCH 10/22] call copy_to_host before serializing buffers --- src/Serialization.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Serialization.cpp b/src/Serialization.cpp index c2cde6818884..4e1aa212b34a 100644 --- a/src/Serialization.cpp +++ b/src/Serialization.cpp @@ -123,7 +123,7 @@ class Serializer { Offset serialize_extern_func_argument(FlatBufferBuilder &builder, const ExternFuncArgument &extern_func_argument); - Offset serialize_buffer(FlatBufferBuilder &builder, const Buffer<> &buffer); + Offset serialize_buffer(FlatBufferBuilder &builder, Buffer<> &buffer); std::vector> serialize_wrapper_refs(FlatBufferBuilder &builder, const std::map &wrappers); @@ -1342,10 +1342,11 @@ Offset Serializer::serialize_extern_func_argument } } -Offset Serializer::serialize_buffer(FlatBufferBuilder &builder, const Buffer<> &buffer) { +Offset Serializer::serialize_buffer(FlatBufferBuilder &builder, Buffer<> &buffer) { if (!buffer.defined()) { return Serialize::CreateBuffer(builder, false); } + buffer.copy_to_host(); const auto name_serialized = serialize_string(builder, buffer.name()); const auto type_serialized = serialize_type(builder, buffer.type()); const int32_t dimensions = buffer.dimensions(); @@ -1437,7 +1438,7 @@ void Serializer::serialize(const Pipeline &pipeline, const std::string &filename std::vector> buffers_serialized; buffers_serialized.reserve(buffers_in_pipeline.size()); - for (const auto &buffer : buffers_in_pipeline) { + for (auto &buffer : buffers_in_pipeline) { buffers_serialized.push_back(serialize_buffer(builder, buffer.second)); } From 09863195af0c053adcc74c5f82eb8d7d6be04867 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Thu, 14 Sep 2023 13:46:31 -0700 Subject: [PATCH 11/22] throw an error if we serialize on-device buffer --- src/Serialization.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Serialization.cpp b/src/Serialization.cpp index 4e1aa212b34a..fd3afa1d414d 100644 --- a/src/Serialization.cpp +++ b/src/Serialization.cpp @@ -1346,6 +1346,9 @@ Offset Serializer::serialize_buffer(FlatBufferBuilder &builde if (!buffer.defined()) { return Serialize::CreateBuffer(builder, false); } + if (buffer.device_dirty()) { + user_error << "Cannot serialize on-device buffer: " << buffer.name() << "\n"; + } buffer.copy_to_host(); const auto name_serialized = serialize_string(builder, buffer.name()); const auto type_serialized = serialize_type(builder, buffer.type()); From 48f479fc96c4a77fdb579edf6171948d5615f921 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 15 Sep 2023 09:51:16 -0700 Subject: [PATCH 12/22] Skip specialize_to_gpu --- cmake/HalideTestHelpers.cmake | 7 +++++++ test/correctness/specialize_to_gpu.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/cmake/HalideTestHelpers.cmake b/cmake/HalideTestHelpers.cmake index c23aba75fea6..e938d11d53ec 100644 --- a/cmake/HalideTestHelpers.cmake +++ b/cmake/HalideTestHelpers.cmake @@ -77,6 +77,13 @@ function(add_halide_test TARGET) CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN TRUE) + + if (WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING) + if (WITH_SERIALIZATION) + target_compile_definitions(${TARGET} PRIVATE WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING) + endif () + endif () + # Add a meta-target for each group, to allow us to build by group easily foreach (GROUP IN LISTS args_GROUPS) set(META_TARGET build_${GROUP}) diff --git a/test/correctness/specialize_to_gpu.cpp b/test/correctness/specialize_to_gpu.cpp index 0890e2ad6eae..8e9644114c6f 100644 --- a/test/correctness/specialize_to_gpu.cpp +++ b/test/correctness/specialize_to_gpu.cpp @@ -4,6 +4,11 @@ using namespace Halide; int main(int argc, char **argv) { +#ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING + printf("[SKIP] Serialization won't preserve GPU buffers, skipping.\n"); + return 0; +#endif + if (!get_jit_target_from_environment().has_gpu_feature()) { printf("[SKIP] No GPU target enabled.\n"); return 0; From 8c98d5983065f8b6a1559a0cfbac67fd6091fae7 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 18 Sep 2023 11:54:00 -0700 Subject: [PATCH 13/22] Update Pipeline.cpp --- src/Pipeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index e2fe9822fbae..edbaadeccc26 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -584,7 +584,7 @@ void Pipeline::compile_jit(const Target &target_arg) { #ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING // TODO(https://github.com/halide/Halide/pull/7760): replace file serialization with in-memory serialization std::string filename = generate_function_name() + ".hlpipe"; - std::map external_params; + std::map external_params; serialize_pipeline(*this, filename, external_params); Pipeline deserialized_pipe = deserialize_pipeline(filename, external_params); std::vector outputs; From 004b8eecee9706ecba4d439800192cd791742229 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 25 Sep 2023 15:35:27 -0700 Subject: [PATCH 14/22] Skip two more tests --- .../gpu_give_input_buffers_device_allocations.cpp | 5 +++++ test/correctness/leak_device_memory.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/test/correctness/gpu_give_input_buffers_device_allocations.cpp b/test/correctness/gpu_give_input_buffers_device_allocations.cpp index a2f4d9618f63..666ce86d9b3f 100644 --- a/test/correctness/gpu_give_input_buffers_device_allocations.cpp +++ b/test/correctness/gpu_give_input_buffers_device_allocations.cpp @@ -4,6 +4,11 @@ using namespace Halide; int main(int argc, char **argv) { +#ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING + printf("[SKIP] Serialization won't preserve GPU buffers, skipping.\n"); + return 0; +#endif + Target t(get_jit_target_from_environment()); if (!t.has_gpu_feature()) { printf("[SKIP] No GPU target enabled.\n"); diff --git a/test/correctness/leak_device_memory.cpp b/test/correctness/leak_device_memory.cpp index 086bb1cd5810..567aeddb5fd8 100644 --- a/test/correctness/leak_device_memory.cpp +++ b/test/correctness/leak_device_memory.cpp @@ -14,6 +14,10 @@ void halide_print(JITUserContext *user_context, const char *str) { } int main(int argc, char **argv) { +#ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING + printf("[SKIP] Serialization won't preserve GPU buffers, skipping.\n"); + return 0; +#endif Target target = get_jit_target_from_environment(); From d488510a08a495225f1010315e2d6bf7a3fa2278 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Thu, 28 Sep 2023 14:50:58 -0700 Subject: [PATCH 15/22] use serialize to memory during jit testing --- src/Pipeline.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index 759a6178a715..c605d2038248 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -582,11 +582,10 @@ void Pipeline::compile_jit(const Target &target_arg) { contents->invalidate_cache(); #ifdef WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING - // TODO(https://github.com/halide/Halide/pull/7760): replace file serialization with in-memory serialization - std::string filename = generate_function_name() + ".hlpipe"; std::map external_params; - serialize_pipeline(*this, filename, external_params); - Pipeline deserialized_pipe = deserialize_pipeline(filename, external_params); + std::vector data; + serialize_pipeline(*this, data, external_params); + Pipeline deserialized_pipe = deserialize_pipeline(data, external_params); std::vector outputs; for (const Func &f : deserialized_pipe.outputs()) { outputs.push_back(f.function()); From ca33de52b8e31270a145cde3f79c922270731680 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Fri, 29 Sep 2023 15:28:46 -0700 Subject: [PATCH 16/22] makefile update --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 244fcc00d4e5..f6da8df9cdfd 100644 --- a/Makefile +++ b/Makefile @@ -288,6 +288,9 @@ LLVM_SHARED_LIBS = -Wl,-rpath=$(LLVM_LIBDIR) -L $(LLVM_LIBDIR) -lLLVM LLVM_LIBS_FOR_SHARED_LIBHALIDE=$(if $(WITH_LLVM_INSIDE_SHARED_LIBHALIDE),$(LLVM_STATIC_LIBS),$(LLVM_SHARED_LIBS)) TUTORIAL_CXX_FLAGS ?= -std=c++17 -g -fno-omit-frame-pointer $(RTTI_CXX_FLAGS) -I $(ROOT_DIR)/tools $(SANITIZER_FLAGS) $(LLVM_CXX_FLAGS_LIBCPP) ++ ifneq (,$(shell which flatc)) ++ TUTORIAL_CXX_FLAGS += -DWITH_SERIALIZATION -I $(BUILD_DIR) -I $(shell which flatc | sed 's/bin.flatc/include/') ++ endif # The tutorials contain example code with warnings that we don't want # to be flagged as errors, so the test flags are the tutorial flags # plus our warning flags. From 1d273d3df57e43908bb9632c90011e78c43a9024 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Fri, 29 Sep 2023 16:14:28 -0700 Subject: [PATCH 17/22] makefile fix --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f6da8df9cdfd..aad80166d383 100644 --- a/Makefile +++ b/Makefile @@ -288,9 +288,9 @@ LLVM_SHARED_LIBS = -Wl,-rpath=$(LLVM_LIBDIR) -L $(LLVM_LIBDIR) -lLLVM LLVM_LIBS_FOR_SHARED_LIBHALIDE=$(if $(WITH_LLVM_INSIDE_SHARED_LIBHALIDE),$(LLVM_STATIC_LIBS),$(LLVM_SHARED_LIBS)) TUTORIAL_CXX_FLAGS ?= -std=c++17 -g -fno-omit-frame-pointer $(RTTI_CXX_FLAGS) -I $(ROOT_DIR)/tools $(SANITIZER_FLAGS) $(LLVM_CXX_FLAGS_LIBCPP) -+ ifneq (,$(shell which flatc)) -+ TUTORIAL_CXX_FLAGS += -DWITH_SERIALIZATION -I $(BUILD_DIR) -I $(shell which flatc | sed 's/bin.flatc/include/') -+ endif +ifneq (,$(shell which flatc)) +TUTORIAL_CXX_FLAGS += -DWITH_SERIALIZATION -I $(BUILD_DIR) -I $(shell which flatc | sed 's/bin.flatc/include/') +endif # The tutorials contain example code with warnings that we don't want # to be flagged as errors, so the test flags are the tutorial flags # plus our warning flags. From 0428ad1fdc172c96df3b676047547797fd428e93 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Mon, 2 Oct 2023 14:10:47 -0700 Subject: [PATCH 18/22] skip the tutorial if flatc is not there --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index aad80166d383..8259d4443658 100644 --- a/Makefile +++ b/Makefile @@ -2086,6 +2086,12 @@ tutorial_%: $(BIN_DIR)/tutorial_% $(TMP_DIR)/images/rgb.png $(TMP_DIR)/images/gr cd $(TMP_DIR) ; $(CURDIR)/$< @-echo +# Skip the serialization tutorial, if we didn't build -DWITH_SERIALIZATION +ifeq (,$(shell which flatc)) +tutorial_lesson_23_serialization: + @echo "Skipping tutorial lesson 23 (serialization not enabled) ..."\ +endif + test_mullapudi2016: $(MULLAPUDI2016_TESTS:$(ROOT_DIR)/test/autoschedulers/mullapudi2016/%.cpp=mullapudi2016_%) mullapudi2016_%: $(BIN_DIR)/mullapudi2016_% $(BIN_MULLAPUDI2016) From 441bce4a50ce0b3e445a93d851208880d21ce1cb Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Mon, 2 Oct 2023 14:24:44 -0700 Subject: [PATCH 19/22] fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8259d4443658..3d6aab28a0ec 100644 --- a/Makefile +++ b/Makefile @@ -2089,7 +2089,7 @@ tutorial_%: $(BIN_DIR)/tutorial_% $(TMP_DIR)/images/rgb.png $(TMP_DIR)/images/gr # Skip the serialization tutorial, if we didn't build -DWITH_SERIALIZATION ifeq (,$(shell which flatc)) tutorial_lesson_23_serialization: - @echo "Skipping tutorial lesson 23 (serialization not enabled) ..."\ + @echo "Skipping tutorial lesson 23 (serialization not enabled) ..." endif test_mullapudi2016: $(MULLAPUDI2016_TESTS:$(ROOT_DIR)/test/autoschedulers/mullapudi2016/%.cpp=mullapudi2016_%) From a538bc0cc686711fc27e0b9737fd4a3b5b830ae9 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Thu, 5 Oct 2023 10:40:21 -0700 Subject: [PATCH 20/22] fix signature --- src/Serialization.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serialization.cpp b/src/Serialization.cpp index 323a671c8791..28f86c2cedfd 100644 --- a/src/Serialization.cpp +++ b/src/Serialization.cpp @@ -127,7 +127,7 @@ class Serializer { Offset serialize_extern_func_argument(FlatBufferBuilder &builder, const ExternFuncArgument &extern_func_argument); - Offset serialize_buffer(FlatBufferBuilder &builder, Buffer<> &buffer); + Offset serialize_buffer(FlatBufferBuilder &builder, Buffer<> buffer); std::vector> serialize_wrapper_refs(FlatBufferBuilder &builder, const std::map &wrappers); @@ -1352,7 +1352,7 @@ Offset Serializer::serialize_extern_func_argument } } -Offset Serializer::serialize_buffer(FlatBufferBuilder &builder, Buffer<> &buffer) { +Offset Serializer::serialize_buffer(FlatBufferBuilder &builder, Buffer<> buffer) { if (!buffer.defined()) { return Serialize::CreateBuffer(builder, false); } From ef7e91bcfef65ba4e14a1ca09174bbe6c77fd7ee Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Thu, 5 Oct 2023 11:42:13 -0700 Subject: [PATCH 21/22] fix makefile --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 3d6aab28a0ec..3abd1ab3639a 100644 --- a/Makefile +++ b/Makefile @@ -288,9 +288,6 @@ LLVM_SHARED_LIBS = -Wl,-rpath=$(LLVM_LIBDIR) -L $(LLVM_LIBDIR) -lLLVM LLVM_LIBS_FOR_SHARED_LIBHALIDE=$(if $(WITH_LLVM_INSIDE_SHARED_LIBHALIDE),$(LLVM_STATIC_LIBS),$(LLVM_SHARED_LIBS)) TUTORIAL_CXX_FLAGS ?= -std=c++17 -g -fno-omit-frame-pointer $(RTTI_CXX_FLAGS) -I $(ROOT_DIR)/tools $(SANITIZER_FLAGS) $(LLVM_CXX_FLAGS_LIBCPP) -ifneq (,$(shell which flatc)) -TUTORIAL_CXX_FLAGS += -DWITH_SERIALIZATION -I $(BUILD_DIR) -I $(shell which flatc | sed 's/bin.flatc/include/') -endif # The tutorials contain example code with warnings that we don't want # to be flagged as errors, so the test flags are the tutorial flags # plus our warning flags. From 12583c0ad15c7b8c1f49fbb2f010daab2b5df898 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Mon, 6 Nov 2023 12:48:52 -0800 Subject: [PATCH 22/22] trigger buildbot