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

[Apple framework] Fix minimal build with training enabled. #19858

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 30 additions & 23 deletions cmake/onnxruntime_graph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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*"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/cpu/ml/tree_ensemble_helper.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -64,3 +66,5 @@ Status GetVectorAttrsOrDefault(const OpKernelInfo& info, const std::string& name

} // namespace ml
} // namespace onnxruntime

#endif // !defined(ORT_MINIMAL_BUILD)
5 changes: 5 additions & 0 deletions onnxruntime/core/providers/cpu/ml/tree_ensemble_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Licensed under the MIT License.

#pragma once

#if !defined(ORT_MINIMAL_BUILD)
edgchen1 marked this conversation as resolved.
Show resolved Hide resolved

#include "core/common/common.h"
#include "core/framework/op_kernel.h"

Expand All @@ -13,3 +16,5 @@ Status GetVectorAttrsOrDefault(const OpKernelInfo& info, const std::string& name

} // namespace ml
} // namespace onnxruntime

#endif // !defined(ORT_MINIMAL_BUILD)
2 changes: 0 additions & 2 deletions onnxruntime/core/session/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
40 changes: 39 additions & 1 deletion tools/ci_build/github/azure-pipelines/post-merge-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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