-
Notifications
You must be signed in to change notification settings - Fork 571
Add cmake support for flat tensor #8349
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# Please this file formatted by running: | ||
# ~~~ | ||
# cmake-format -i CMakeLists.txt | ||
# ~~~ | ||
|
||
cmake_minimum_required(VERSION 3.19) | ||
|
||
# Source root directory for executorch. | ||
if(NOT EXECUTORCH_ROOT) | ||
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) | ||
endif() | ||
|
||
list(TRANSFORM _extension_flat_tensor__srcs PREPEND "${EXECUTORCH_ROOT}/") | ||
add_library(extension_flat_tensor ${_extension_flat_tensor__srcs}) | ||
target_link_libraries(extension_flat_tensor executorch extension_data_loader) | ||
target_include_directories(extension_flat_tensor PUBLIC | ||
${EXECUTORCH_ROOT}/.. | ||
"${CMAKE_BINARY_DIR}/extension/flat_tensor/include" | ||
"${EXECUTORCH_ROOT}/third-party/flatbuffers/include" | ||
${_common_include_directories}) | ||
target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options}) | ||
|
||
# Install libraries | ||
install( | ||
TARGETS extension_flat_tensor | ||
DESTINATION lib | ||
INCLUDES | ||
DESTINATION ${_common_include_directories} | ||
) | ||
|
||
if(BUILD_TESTING) | ||
add_subdirectory(test) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# Flatbuffer schema header lib. Please this file formatted by running: | ||
# ~~~ | ||
# cmake-format -i CMakeLists.txt | ||
# ~~~ | ||
|
||
if(NOT FLATC_EXECUTABLE) | ||
set(FLATC_EXECUTABLE flatc) | ||
endif() | ||
|
||
# The include directory that will contain the generated schema headers. | ||
set(_flat_tensor_schema__include_dir "${CMAKE_BINARY_DIR}/extension/flat_tensor/include") | ||
set(_flat_tensor_schema__output_dir "${_flat_tensor_schema__include_dir}/executorch/extension/flat_tensor/serialize") | ||
# Source root directory for executorch. | ||
if(NOT EXECUTORCH_ROOT) | ||
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) | ||
endif() | ||
|
||
function(generate_flat_tensor_schema _schema_srcs _schema_name) | ||
set(_schema_outputs) | ||
foreach(fbs_file ${_schema_srcs}) | ||
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}") | ||
list(APPEND _schema_outputs | ||
"${_flat_tensor_schema__output_dir}/${generated}" | ||
) | ||
endforeach() | ||
|
||
# Generate the headers from the .fbs files. | ||
add_custom_command( | ||
OUTPUT ${_schema_outputs} | ||
COMMAND | ||
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o | ||
"${_flat_tensor_schema__output_dir}" ${_schema_srcs} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
DEPENDS ${FLATC_EXECUTABLE} ${_schema_srcs} | ||
COMMENT "Generating ${_schema_name} headers" | ||
VERBATIM | ||
) | ||
|
||
add_library(${_schema_name} INTERFACE ${_schema_outputs}) | ||
set_target_properties(${_schema_name} PROPERTIES LINKER_LANGUAGE CXX) | ||
|
||
# exir lets users set the alignment of tensor data embedded in the flatbuffer, | ||
# and some users need an alignment larger than the default, which is typically | ||
# 32. | ||
target_compile_definitions( | ||
${_schema_name} INTERFACE FLATBUFFERS_MAX_ALIGNMENT=1024 | ||
) | ||
|
||
target_include_directories( | ||
${_schema_name} | ||
INTERFACE ${_flat_tensor_schema__include_dir} | ||
${EXECUTORCH_ROOT}/third-party/flatbuffers/include | ||
) | ||
endfunction() | ||
|
||
# Generate common schema | ||
set(scalar_type_schema_srcs scalar_type.fbs) | ||
generate_flat_tensor_schema("${scalar_type_schema_srcs}" "scalar_type_schema") | ||
|
||
# For the other schemas | ||
set(flat_tensor_schema_srcs flat_tensor.fbs) | ||
generate_flat_tensor_schema("${flat_tensor_schema_srcs}" "flat_tensor_schema") | ||
add_dependencies(flat_tensor_schema scalar_type_schema) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# @generated by test/utils/generate_gtest_cmakelists.py | ||
# | ||
# This file should be formatted with | ||
# ~~~ | ||
# cmake-format -i CMakeLists.txt | ||
# ~~~ | ||
# It should also be cmake-lint clean. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.19) | ||
|
||
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) | ||
|
||
include(${EXECUTORCH_ROOT}/build/Test.cmake) | ||
|
||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte" | ||
"${CMAKE_CURRENT_BINARY_DIR}/_default_external_constant.ptd" | ||
|
||
COMMAND | ||
python -m test.models.export_program --modules "ModuleLinear" --external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null | ||
|
||
WORKING_DIRECTORY ${EXECUTORCH_ROOT} | ||
) | ||
|
||
add_custom_target( | ||
program_data_files | ||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte" | ||
"${CMAKE_CURRENT_BINARY_DIR}/_default_external_constant.ptd" | ||
) | ||
|
||
set(test_env_ | ||
"ET_MODULE_LINEAR_PROGRAM_PATH=${CMAKE_CURRENT_BINARY_DIR}/ModuleLinearProgram.pte" | ||
"ET_MODULE_LINEAR_DATA_PATH=${CMAKE_CURRENT_BINARY_DIR}/_default_external_constant.ptd" | ||
) | ||
|
||
set(_test_srcs flat_tensor_data_map_test.cpp flat_tensor_header_test.cpp) | ||
|
||
et_cxx_test(extension_flat_tensor_test SOURCES ${_test_srcs} EXTRA_LIBS extension_flat_tensor extension_data_loader) | ||
|
||
add_dependencies(extension_flat_tensor_test program_data_files) | ||
set_property(TEST extension_flat_tensor_test PROPERTY ENVIRONMENT ${test_env_}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
stuff in this file seems to get clobbered if I rerun python test/utils/generate_gtest_cmakelists.py
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.
Oh I guess she manually wrote it instead of having it generated @lucylq can you take a look, or if its faster we can just black list this dir in the script
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.
shouldn't need to be blocklisted, just drop it from the config
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.
Ah, I generated it and then edited it to create the example pte files. I'll remove it from OSSTestConfig.json.
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.
#8472