-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Experimental serializer #7594
Experimental serializer #7594
Changes from all commits
7bafefc
10fce24
acd6223
937cb48
256c36d
7804953
dd6d9fc
e3a55c5
4c19481
dfff1a9
6838258
d6b0b00
609705d
4b86347
35296ff
fe79618
478970e
4140ae1
df3620b
b416d26
db47e2c
63ac57a
ca4ac94
097ec2e
88f4a5d
491b596
b7292b7
271f4c8
9632e5b
49644e9
c574e46
f86b390
5b49664
c6686cc
60aa622
599859c
882b38d
958432e
46a40f5
2d2564d
21a7c3d
3c284df
62bb5df
1e4e0c5
770a30e
ad6eb06
ad54aeb
42af1ad
6c24ce6
87d3be4
303e7bb
e1a79aa
b47317c
efa5be4
df87b3f
027de4f
19217ac
fac998c
c2f152a
d9834b4
46467ac
5a5da05
66db495
dff37e0
74f4b39
4bbc072
0e3f8a0
f175c84
ede205a
fcdd799
f72598b
fd31ae6
e2dccc1
7d16695
86fd169
e34c02f
8733128
118a391
3f586c9
5b0ab8d
7d4b7ce
9a64e12
c6e8f5b
017c0bb
bb181d1
a634150
2b73e94
f2cee65
991c3c8
1cc413a
f66f430
898d074
7ab29b6
fc9d1b3
a7c67e3
e384b93
1981584
28dbeb8
9d2aea1
43efbba
3eb37b4
c5fa85a
1396434
17dfcd1
cc81e1f
654c8eb
625ad4e
363a5b6
23c4907
15ba956
639ee8f
2eb4f9a
ebc900b
418dfb0
d9cf85d
85311ed
e0399e2
7b07c39
1ad585d
3caf020
84a36d1
83c7a25
ae2cfd8
5d912c6
7ddc210
066d6f7
7936657
a02f6d5
b2673f5
934e3f9
4f2c6e4
568a740
8bf2d67
df0addd
e9fd2aa
1f9cf57
3ff9fd3
cc1eec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ set(HEADER_FILES | |
Deinterleave.h | ||
Derivative.h | ||
DerivativeUtils.h | ||
Deserialization.h | ||
DeviceAPI.h | ||
DeviceArgument.h | ||
DeviceInterface.h | ||
|
@@ -140,6 +141,7 @@ set(HEADER_FILES | |
ScheduleFunctions.h | ||
Scope.h | ||
SelectGPUAPI.h | ||
Serialization.h | ||
Simplify.h | ||
SimplifyCorrelatedDifferences.h | ||
SimplifySpecializations.h | ||
|
@@ -221,6 +223,7 @@ set(SOURCE_FILES | |
Deinterleave.cpp | ||
Derivative.cpp | ||
DerivativeUtils.cpp | ||
Deserialization.cpp | ||
DeviceArgument.cpp | ||
DeviceInterface.cpp | ||
Dimension.cpp | ||
|
@@ -299,6 +302,7 @@ set(SOURCE_FILES | |
Schedule.cpp | ||
ScheduleFunctions.cpp | ||
SelectGPUAPI.cpp | ||
Serialization.cpp | ||
Simplify.cpp | ||
Simplify_Add.cpp | ||
Simplify_And.cpp | ||
|
@@ -394,6 +398,7 @@ foreach (f IN LISTS HTML_TEMPLATE_FILES) | |
target_sources(Halide_c_templates PRIVATE ${DST}) | ||
endforeach () | ||
|
||
|
||
## | ||
# Build the Halide mono-header. | ||
## | ||
|
@@ -418,6 +423,91 @@ add_library(Halide | |
# Including these as sources works around the need to "install" Halide_initmod | ||
$<TARGET_OBJECTS:Halide_initmod> | ||
$<TARGET_OBJECTS:Halide_c_templates>) | ||
|
||
## | ||
# Flatbuffers and Serialization dependencies. | ||
## | ||
|
||
# Build serialization, enabled by default | ||
option(WITH_SERIALIZATION "Include experimental Serialization/Deserialization code" ON) | ||
|
||
# flatbuffers is small and compiles quickly, but if you want/need to use | ||
# a local version (via find_package), configure with FLATBUFFERS_USE_FETCHCONTENT=OFF | ||
option(FLATBUFFERS_USE_FETCHCONTENT "Enable to download the Flatbuffers library via FetchContent" ON) | ||
set(FLATBUFFERS_VER 23.5.26 CACHE STRING "The Flatbuffers version to use (or download)") | ||
|
||
if (WITH_SERIALIZATION) | ||
if (FLATBUFFERS_USE_FETCHCONTENT) | ||
include(FetchContent) | ||
message(STATUS "Fetching flatbuffers ${FLATBUFFERS_VER}...") | ||
FetchContent_Declare( | ||
flatbuffers | ||
GIT_REPOSITORY https://github.com/google/flatbuffers.git | ||
GIT_TAG v${FLATBUFFERS_VER} | ||
GIT_SHALLOW TRUE | ||
) | ||
# configuration for flatbuffers | ||
set(FLATBUFFERS_BUILD_TESTS OFF) | ||
set(FLATBUFFERS_INSTALL OFF) | ||
FetchContent_MakeAvailable(flatbuffers) | ||
set_target_properties(flatbuffers PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
|
||
add_library(Halide_flatbuffers INTERFACE) | ||
target_sources(Halide_flatbuffers INTERFACE $<BUILD_INTERFACE:$<TARGET_OBJECTS:flatbuffers>>) | ||
target_include_directories(Halide_flatbuffers | ||
SYSTEM # Use -isystem instead of -I; this is a trick so that clang-tidy won't analyze these includes | ||
INTERFACE | ||
$<BUILD_INTERFACE:${flatbuffers_SOURCE_DIR}>/include | ||
$<BUILD_INTERFACE:${flatbuffers_BINARY_DIR}>/include) | ||
set_target_properties(Halide_flatbuffers PROPERTIES EXPORT_NAME flatbuffers) | ||
|
||
add_executable(flatbuffers::flatc ALIAS flatc) | ||
message(STATUS "Using fetched-and-built flatbuffers, version ${FLATBUFFERS_VER}") | ||
else () | ||
# Sadly, there seem to be at least three variations of the Flatbuffer package | ||
# in terms of the case of the relevant CMake files; if we guess wrong, we | ||
# fail on case-sensitive file systems. We'll try this as a hack workaround: | ||
# just try all three. (Note that the internal CMake library name appears to be | ||
# `flatbuffers` in all cases.) | ||
set(FB_NAME "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered using the NAMES argument to find_package? That would simplify this considerably There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...because I didn't know about it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, sometimes I forget the abyss stared back into me |
||
foreach (N IN ITEMS flatbuffers Flatbuffers FlatBuffers) | ||
# TODO: should we check the version here? | ||
find_package(${N} QUIET) | ||
if (${N}_FOUND) | ||
set(FB_NAME ${N}) | ||
message(STATUS "Using installed flatbuffers, version ${${N}_VERSION}") | ||
break() | ||
endif () | ||
endforeach () | ||
|
||
if (NOT FB_NAME) | ||
message(FATAL_ERROR "WITH_SERIALIZATION is ON and FLATBUFFERS_USE_FETCHCONTENT is OFF, " | ||
"but could not find flatbuffers installed locally. " | ||
"Either install flatbuffers or build with WITH_SERIALIZATION=OFF.") | ||
endif () | ||
|
||
add_library(Halide_flatbuffers ALIAS flatbuffers::flatbuffers) | ||
endif () | ||
|
||
set(fb_dir "${Halide_BINARY_DIR}/flatc/include") | ||
|
||
set(fb_def "${CMAKE_CURRENT_SOURCE_DIR}/halide_ir.fbs") | ||
set(fb_header "${fb_dir}/halide_ir_generated.h") | ||
add_custom_command( | ||
OUTPUT "${fb_header}" | ||
COMMAND flatbuffers::flatc --cpp -o "${fb_dir}" "${fb_def}" | ||
DEPENDS "${fb_def}" | ||
VERBATIM | ||
) | ||
add_custom_target(generate_fb_header DEPENDS "${fb_header}") | ||
set_source_files_properties("${fb_header}" PROPERTIES GENERATED TRUE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? Add custom command sets it automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize that. |
||
|
||
add_dependencies(Halide generate_fb_header) | ||
target_include_directories(Halide PRIVATE "$<BUILD_INTERFACE:${fb_dir}>") | ||
target_link_libraries(Halide PRIVATE Halide_flatbuffers) | ||
target_compile_definitions(Halide PRIVATE WITH_SERIALIZATION) | ||
endif () | ||
|
||
add_library(Halide::Halide ALIAS Halide) | ||
|
||
target_link_libraries(Halide PRIVATE Halide::LLVM) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole FetchContent thing makes me sad. We'll (I'll) be able to do much better with CMake 3.24+ and its tighter integration between the two methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, an upgrade would give us so much leverage that I think we should poll our users to see if they can tolerate an early upgrade to 3.24.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM