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

[serialization] Add Halide version and serialization version in serialization format #7905

Merged
merged 9 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ CXX_FLAGS += $(WEBASSEMBLY_CXX_FLAGS)
# On ubuntu, this requires packages flatbuffers-compiler and libflatbuffers-dev
ifneq (,$(shell which flatc))
CXX_FLAGS += -DWITH_SERIALIZATION -I $(BUILD_DIR) -I $(shell which flatc | sed 's/bin.flatc/include/')
HALIDE_SERIALIZATION_VERSION_MAJOR ?= 0
HALIDE_SERIALIZATION_VERSION_MINOR ?= 1
HALIDE_SERIALIZATION_VERSION_PATCH ?= 0
HALIDE_SERIALIZATION_VERSION=$(HALIDE_SERIALIZATION_VERSION_MAJOR).$(HALIDE_SERIALIZATION_VERSION_MINOR).$(HALIDE_SERIALIZATION_VERSION_PATCH)
endif

# This is required on some hosts like powerpc64le-linux-gnu because we may build
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ if (WITH_SERIALIZATION)
target_include_directories(Halide PRIVATE "$<BUILD_INTERFACE:${fb_dir}>")
target_link_libraries(Halide PRIVATE Halide_flatbuffers)
target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION)
target_compile_definitions(Halide PUBLIC
HALIDE_SERIALIZATION_VERSION_MAJOR=0
HALIDE_SERIALIZATION_VERSION_MINOR=1
HALIDE_SERIALIZATION_VERSION_PATCH=0
)
endif ()

# Enable serialization testing by intercepting JIT compilation with a serialization roundtrip;
Expand Down
19 changes: 19 additions & 0 deletions src/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,25 @@ Pipeline Deserializer::deserialize(const std::vector<uint8_t> &data) {
user_warning << "deserialized pipeline is empty\n";
return Pipeline();
}

std::string deserialized_halide_version = deserialize_string(pipeline_obj->halide_version());
std::string halide_version = std::to_string(HALIDE_VERSION_MAJOR) + "." +
std::to_string(HALIDE_VERSION_MINOR) + "." +
std::to_string(HALIDE_VERSION_PATCH);
if (deserialized_halide_version != halide_version) {
user_warning << "deserialized pipeline is built with Halide version " << deserialized_halide_version
<< ", but current Halide version is " << halide_version << "\n";
}

std::string deserialized_serialization_version = deserialize_string(pipeline_obj->serialization_version());
std::string serialization_version = std::to_string(HALIDE_SERIALIZATION_VERSION_MAJOR) + "." +
std::to_string(HALIDE_SERIALIZATION_VERSION_MINOR) + "." +
std::to_string(HALIDE_SERIALIZATION_VERSION_PATCH);
if (deserialized_serialization_version != serialization_version) {
user_error << "deserialized pipeline is built with Halide serialization version " << deserialized_serialization_version
<< ", but current Halide serialization version is " << serialization_version << "\n";
}

const std::vector<std::string> func_names_in_order =
deserialize_vector<flatbuffers::String, std::string>(pipeline_obj->func_names_in_order(),
&Deserializer::deserialize_string);
Expand Down
12 changes: 11 additions & 1 deletion src/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,14 @@ void Serializer::serialize(const Pipeline &pipeline, std::vector<uint8_t> &resul
buffers_serialized.push_back(serialize_buffer(builder, buffer.second));
}

std::string halide_version = std::to_string(HALIDE_VERSION_MAJOR) + "." +
std::to_string(HALIDE_VERSION_MINOR) + "." +
std::to_string(HALIDE_VERSION_PATCH);

std::string serialization_version = std::to_string(HALIDE_SERIALIZATION_VERSION_MAJOR) + "." +
std::to_string(HALIDE_SERIALIZATION_VERSION_MINOR) + "." +
std::to_string(HALIDE_SERIALIZATION_VERSION_PATCH);

auto pipeline_obj = Serialize::CreatePipeline(builder,
builder.CreateVector(funcs_serialized),
builder.CreateVector(output_names_serialized),
Expand All @@ -1509,7 +1517,9 @@ void Serializer::serialize(const Pipeline &pipeline, std::vector<uint8_t> &resul
builder.CreateVector(func_names_in_order_serialized),
builder.CreateVector(parameters_serialized),
builder.CreateVector(external_parameters_serialized),
builder.CreateVector(buffers_serialized));
builder.CreateVector(buffers_serialized),
serialize_string(builder, halide_version),
serialize_string(builder, serialization_version));
builder.Finish(pipeline_obj);

uint8_t *buf = builder.GetBufferPointer();
Expand Down
6 changes: 4 additions & 2 deletions src/halide_ir.fbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Halide.Serialize;

// This corresponds to the corresponding Halide version.
file_identifier "HL17";
// This identifies the serialized data being a Halide pipeline. Should be exactly 4 bytes.
file_identifier "HLDE";

// File extension of any written files. "hlpipe" stands for Halide Pipeline.
file_extension "hlpipe";
Expand Down Expand Up @@ -710,6 +710,8 @@ table Pipeline {
parameters: [Parameter];
external_parameters: [ExternalParameter];
buffers: [Buffer];
halide_version: string;
serialization_version: string;
}

root_type Pipeline;