Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add special build for testing serialization via a serialization roundtrip in JIT compilation and fix serialization leaks #7763

Merged
merged 36 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c0cf44d
add back JIT testing, enclosed in #ifdef blocks
TH3CHARLie Aug 15, 2023
d674662
fix typo
TH3CHARLie Aug 15, 2023
3a2de83
nits
TH3CHARLie Aug 16, 2023
de155f1
WITH_SERIALIZATION_JIT->WITH_SERIALIZATION_JIT_ROUNDTRIP_TESTING
steven-johnson Aug 23, 2023
01fc657
Merge branch 'main' into pr/7763
steven-johnson Aug 23, 2023
bad7fb0
Merge branch 'main' into pr/7763
steven-johnson Aug 23, 2023
7260cd9
fix self-reference leaks: now uses weak function ptr in reverse funct…
TH3CHARLie Aug 25, 2023
7559e3b
Merge branch 'main' into pr/7763
steven-johnson Aug 28, 2023
951c714
Merge branch 'xuanda/serialization-testing' of https://github.com/TH3…
steven-johnson Aug 28, 2023
ee10d4c
Move clang-tidy checks back to Linux
steven-johnson Aug 28, 2023
20cf471
bogus
steven-johnson Aug 28, 2023
b4fff91
Update Generator.cpp
steven-johnson Aug 29, 2023
8c5f3ac
Merge branch 'srj/tidy-revert' into pr/7763
steven-johnson Aug 29, 2023
9b812b8
Update Generator.cpp
steven-johnson Aug 29, 2023
6c4ef67
Merge branch 'srj/tidy-revert' into pr/7763
steven-johnson Aug 29, 2023
67de0ad
Merge branch 'main' into pr/7763
steven-johnson Aug 30, 2023
0748868
Merge branch 'main' into pr/7763
steven-johnson Aug 30, 2023
e1fb1c3
Merge branch 'main' into pr/7763
steven-johnson Sep 13, 2023
4bd7179
call copy_to_host before serializing buffers
TH3CHARLie Sep 14, 2023
0986319
throw an error if we serialize on-device buffer
TH3CHARLie Sep 14, 2023
f2977c7
Merge branch 'main' into pr/7763
steven-johnson Sep 15, 2023
48f479f
Skip specialize_to_gpu
steven-johnson Sep 15, 2023
50cfc54
Merge branch 'main' into pr/7763
steven-johnson Sep 18, 2023
955a6d7
Merge branch 'main' into pr/7763
steven-johnson Sep 18, 2023
8c98d59
Update Pipeline.cpp
steven-johnson Sep 18, 2023
feacc37
Merge branch 'main' into pr/7763
steven-johnson Sep 19, 2023
004b8ee
Skip two more tests
steven-johnson Sep 25, 2023
de8818d
Merge remote-tracking branch 'origin/main' into xuanda/serialization-…
TH3CHARLie Sep 28, 2023
d488510
use serialize to memory during jit testing
TH3CHARLie Sep 28, 2023
ca33de5
makefile update
TH3CHARLie Sep 29, 2023
1d273d3
makefile fix
TH3CHARLie Sep 29, 2023
0428ad1
skip the tutorial if flatc is not there
TH3CHARLie Oct 2, 2023
441bce4
fix
TH3CHARLie Oct 2, 2023
a538bc0
fix signature
TH3CHARLie Oct 5, 2023
ef7e91b
fix makefile
TH3CHARLie Oct 5, 2023
12583c0
trigger buildbot
TH3CHARLie Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
# This is used only for special builds made specifically for testing, and must be disabled by default.
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_ROUNDTRIP_TESTING)
endif ()
endif ()

add_library(Halide::Halide ALIAS Halide)

target_link_libraries(Halide PRIVATE Halide::LLVM)
Expand Down
24 changes: 24 additions & 0 deletions src/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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<std::string, Internal::Parameter> external_params;
serialize_pipeline(*this, filename, external_params);
Pipeline deserialized_pipe = deserialize_pipeline(filename, external_params);
std::vector<Function> 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 that reschedule/reorder storage can be properly handled.
std::vector<Function> origin_outputs = contents->outputs;
std::vector<Internal::Stmt> origin_requirements = contents->requirements;
contents->outputs = outputs;
contents->requirements = deserialized_pipe.requirements();
#endif

// Infer an arguments vector
infer_arguments();

Expand All @@ -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<std::string, JITExtern> 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_ROUNDTRIP_TESTING
// Restore the original outputs and requirements.
contents->outputs = origin_outputs;
contents->requirements = origin_requirements;
#endif
}

Callable Pipeline::compile_to_callable(const std::vector<Argument> &args_in, const Target &target_arg) {
Expand Down