mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
[Apple framework] Fix minimal build with training enabled. (#19858)
Fix some linker errors that come up when integrating the onnxruntime-training-c pod into another Xcode project. The problematic configuration is a minimal build with training APIs enabled. - training_op_defs.o had some unresolved references to ONNX functions. It should not be included at all in a minimal build. - tree_ensemble_helper.o also had unresolved references to ONNX ParseData. The containing function is unused in a minimal build. Added a test to cover this configuration.
This commit is contained in:
parent
00c3cd497e
commit
860eb762c2
6 changed files with 100 additions and 26 deletions
|
|
@ -7,8 +7,26 @@ file(GLOB_RECURSE onnxruntime_graph_src CONFIGURE_DEPENDS
|
|||
"${ONNXRUNTIME_ROOT}/core/graph/*.cc"
|
||||
)
|
||||
|
||||
# create empty list for any excludes
|
||||
# start with empty training srcs list
|
||||
set(orttraining_graph_src)
|
||||
|
||||
if (onnxruntime_ENABLE_TRAINING_OPS AND NOT onnxruntime_ENABLE_TRAINING)
|
||||
set(orttraining_graph_src
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (onnxruntime_ENABLE_TRAINING)
|
||||
file(GLOB_RECURSE orttraining_graph_src CONFIGURE_DEPENDS
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.h"
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.cc"
|
||||
)
|
||||
endif()
|
||||
|
||||
# create empty lists for any excludes
|
||||
set(onnxruntime_graph_src_exclude_patterns)
|
||||
set(orttraining_graph_src_exclude_patterns)
|
||||
|
||||
if (onnxruntime_MINIMAL_BUILD)
|
||||
# remove schema registration support
|
||||
|
|
@ -22,11 +40,18 @@ if (onnxruntime_MINIMAL_BUILD)
|
|||
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.cc"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.h"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.cc"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.h"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.cc"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/function_template.h"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/function_utils.h"
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/function_utils.cc"
|
||||
)
|
||||
|
||||
list(APPEND orttraining_graph_src_exclude_patterns
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
|
||||
)
|
||||
|
||||
# no Function support initially
|
||||
list(APPEND onnxruntime_graph_src_exclude_patterns
|
||||
"${ONNXRUNTIME_ROOT}/core/graph/function*"
|
||||
|
|
@ -64,30 +89,12 @@ endif()
|
|||
file(GLOB onnxruntime_graph_src_exclude ${onnxruntime_graph_src_exclude_patterns})
|
||||
list(REMOVE_ITEM onnxruntime_graph_src ${onnxruntime_graph_src_exclude})
|
||||
|
||||
file(GLOB_RECURSE onnxruntime_ir_defs_src CONFIGURE_DEPENDS
|
||||
"${ONNXRUNTIME_ROOT}/core/defs/*.cc"
|
||||
)
|
||||
|
||||
if (onnxruntime_ENABLE_TRAINING_OPS AND NOT onnxruntime_ENABLE_TRAINING)
|
||||
set(orttraining_graph_src
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (onnxruntime_ENABLE_TRAINING)
|
||||
file(GLOB_RECURSE orttraining_graph_src CONFIGURE_DEPENDS
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.h"
|
||||
"${ORTTRAINING_SOURCE_DIR}/core/graph/*.cc"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(onnxruntime_graph_lib_src ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
|
||||
if (onnxruntime_ENABLE_TRAINING_OPS)
|
||||
list(APPEND onnxruntime_graph_lib_src ${orttraining_graph_src})
|
||||
file(GLOB orttraining_graph_src_exclude ${orttraining_graph_src_exclude_patterns})
|
||||
list(REMOVE_ITEM orttraining_graph_src ${orttraining_graph_src_exclude})
|
||||
endif()
|
||||
|
||||
onnxruntime_add_static_library(onnxruntime_graph ${onnxruntime_graph_lib_src})
|
||||
onnxruntime_add_static_library(onnxruntime_graph ${onnxruntime_graph_src} ${orttraining_graph_src})
|
||||
add_dependencies(onnxruntime_graph onnx_proto flatbuffers::flatbuffers)
|
||||
onnxruntime_add_include_to_target(onnxruntime_graph onnxruntime_common ${WIL_TARGET} onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers safeint_interface Boost::mp11)
|
||||
|
||||
|
|
@ -120,7 +127,7 @@ endif()
|
|||
|
||||
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
|
||||
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
|
||||
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src} ${onnxruntime_ir_defs_src})
|
||||
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src})
|
||||
if (onnxruntime_ENABLE_TRAINING_OPS)
|
||||
source_group(TREE ${ORTTRAINING_ROOT} FILES ${orttraining_graph_src})
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#if !defined(ORT_MINIMAL_BUILD)
|
||||
|
||||
#include "core/providers/cpu/ml/tree_ensemble_helper.h"
|
||||
#include "core/common/common.h"
|
||||
#include "onnx/defs/tensor_proto_util.h"
|
||||
|
|
@ -64,3 +66,5 @@ Status GetVectorAttrsOrDefault(const OpKernelInfo& info, const std::string& name
|
|||
|
||||
} // namespace ml
|
||||
} // namespace onnxruntime
|
||||
|
||||
#endif // !defined(ORT_MINIMAL_BUILD)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(ORT_MINIMAL_BUILD)
|
||||
|
||||
#include "core/common/common.h"
|
||||
#include "core/framework/op_kernel.h"
|
||||
|
||||
|
|
@ -13,3 +16,5 @@ Status GetVectorAttrsOrDefault(const OpKernelInfo& info, const std::string& name
|
|||
|
||||
} // namespace ml
|
||||
} // namespace onnxruntime
|
||||
|
||||
#endif // !defined(ORT_MINIMAL_BUILD)
|
||||
|
|
|
|||
|
|
@ -240,12 +240,10 @@ Status Environment::Initialize(std::unique_ptr<logging::LoggingManager> logging_
|
|||
// Register contributed schemas.
|
||||
// The corresponding kernels are registered inside the appropriate execution provider.
|
||||
#ifndef DISABLE_CONTRIB_OPS
|
||||
#ifndef ORT_MINIMAL_BUILD
|
||||
RegisterOpSetSchema<contrib::OpSet_Microsoft_ver1>();
|
||||
RegisterOpSetSchema<contrib::OpSet_ONNX_Deprecated>();
|
||||
// internal opset that has NHWC versions of ONNX operators
|
||||
RegisterOpSetSchema<internal_nhwc_onnx::OpSet_Internal_NHWC_ONNX>();
|
||||
#endif
|
||||
contrib::RegisterContribSchemas();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"build_osx_archs": {
|
||||
"iphonesimulator": [
|
||||
"x86_64"
|
||||
]
|
||||
},
|
||||
"build_params": {
|
||||
"base": [
|
||||
"--parallel",
|
||||
"--use_xcode",
|
||||
"--build_apple_framework",
|
||||
"--minimal_build=extended",
|
||||
"--enable_training_apis",
|
||||
"--skip_tests",
|
||||
"--cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF"
|
||||
],
|
||||
"iphonesimulator": [
|
||||
"--ios",
|
||||
"--apple_deploy_target=12.0"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -417,6 +417,7 @@ stages:
|
|||
- template: templates/use-xcode-version.yml
|
||||
parameters:
|
||||
xcodeVersion: 14.3
|
||||
|
||||
- script: |
|
||||
pip install -r tools/ci_build/github/apple/ios_packaging.requirements.txt
|
||||
displayName: "Install Python requirements"
|
||||
|
|
@ -433,4 +434,41 @@ stages:
|
|||
--framework_info_file "$(Build.BinariesDirectory)/ios_framework/xcframework_info.json" \
|
||||
--c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \
|
||||
--variant Mobile
|
||||
displayName: "Test pod with iOS dynamic framework"
|
||||
displayName: "Test pod with iOS framework"
|
||||
|
||||
- stage: IosMinimalTrainingBuild
|
||||
dependsOn: []
|
||||
jobs:
|
||||
- job: IosMinimalTrainingBuild
|
||||
timeoutInMinutes: 120
|
||||
pool:
|
||||
vmImage: "macOS-13"
|
||||
|
||||
steps:
|
||||
- task: UsePythonVersion@0
|
||||
inputs:
|
||||
versionSpec: "3.9"
|
||||
addToPath: true
|
||||
architecture: "x64"
|
||||
|
||||
- template: templates/use-xcode-version.yml
|
||||
parameters:
|
||||
xcodeVersion: 14.3
|
||||
|
||||
- script: |
|
||||
pip install -r tools/ci_build/github/apple/ios_packaging.requirements.txt
|
||||
displayName: "Install Python requirements"
|
||||
|
||||
- script: |
|
||||
python tools/ci_build/github/apple/build_apple_framework.py \
|
||||
--build_dir "$(Build.BinariesDirectory)/ios_framework" \
|
||||
tools/ci_build/github/apple/test_minimal_training_ios_simulator_framework_build_settings.json
|
||||
displayName: "Build iOS framework with minimal build and training enabled"
|
||||
|
||||
- script: |
|
||||
python tools/ci_build/github/apple/test_apple_packages.py \
|
||||
--framework_info_file "$(Build.BinariesDirectory)/ios_framework/xcframework_info.json" \
|
||||
--c_framework_dir "$(Build.BinariesDirectory)/ios_framework/framework_out" \
|
||||
--variant Training \
|
||||
--skip_macos_test
|
||||
displayName: "Test pod with iOS framework"
|
||||
|
|
|
|||
Loading…
Reference in a new issue