Skip to content

Commit

Permalink
Cherry-picks for release 1.8.1 - Round3 (#8195)
Browse files Browse the repository at this point in the history
* Revert the cuda algo finding change as this causes a significant memory bloat. (#8181)

* Revert the cuda algo finding change as this causes a significant memory bloat.

* Address PR comment

* Make pipelines to support torch1.8.1 and torch1.9.0 (#8084)

* Add post-install command to build PyTorch CPP extensions from within onnxruntime package (#8027)

ORTModule requires two PyTorch CPP extensions that are currently JIT compiled. The runtime compilation can cause issues in some environments without all build requirements or in environments with multiple instances of ORTModule running in parallel

This PR creates a custom command to compile such extensions that must be manually executed before ORTModule is executed for the first time. When users try to use ORTModule before the extensions are compiled, an error with instructions are raised

PyTorch CPP Extensions for ORTModule can be compiled by running:
python -m onnxruntime.training.ortmodule.torch_cpp_extensions.install

Full build environment is needed for this

* Patch orttraining-ortmodule pipeline with latest fix on master

* add cuda version to build config

* [rel-1.8.1][Objective-C API] Cherry-pick Objective-C API updates (#8197)

* [Objective-C API] Add ORTSession methods to get input, overridable initializer, and output names. (#7837)

* [Objective-C API] Fixes from package testing and clean up (#7866)

* [Objective-C API] Enable CoreML EP (#7914)

Enable CoreML EP in Objective-C API.

* [Objective-C API] Add script to assemble pod package files. (#7958)

Add a helper script for creating the Objective-C API pod package. It puts the necessary files and generates a podspec in a staging directory.

* [Objective-C API] Add support for documentation generation (#7999)

Adding support for generating API documentation with the Jazzy tool.
It's a manual process now, but we can eventually make it a part of the release pipeline.

Co-authored-by: Pranav Sharma <prs@microsoft.com>
Co-authored-by: liqunfu <liqfu@microsoft.com>
Co-authored-by: Thiago Crepaldi <thiago.crepaldi@microsoft.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
  • Loading branch information
6 people authored Jun 30, 2021
1 parent 2e55002 commit 8d6825b
Show file tree
Hide file tree
Showing 80 changed files with 1,330 additions and 715 deletions.
54 changes: 29 additions & 25 deletions cmake/onnxruntime_objectivec.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

if(${CMAKE_VERSION} VERSION_LESS "3.18")
message(FATAL_ERROR "CMake 3.18+ is required when building the Objective-C API.")
if(NOT APPLE)
message(FATAL_ERROR "The Objective-C API must be built on an Apple platform.")
endif()

set(ONNXRUNTIME_OBJC_MIN_CMAKE_VERSION "3.18")

if(CMAKE_VERSION VERSION_LESS ONNXRUNTIME_OBJC_MIN_CMAKE_VERSION)
message(FATAL_ERROR "The Objective-C API requires CMake ${ONNXRUNTIME_OBJC_MIN_CMAKE_VERSION}+.")
endif()

if(NOT onnxruntime_BUILD_SHARED_LIB)
message(FATAL_ERROR "The Objective-C API requires onnxruntime_BUILD_SHARED_LIB to be enabled.")
endif()

check_language(OBJC)
Expand Down Expand Up @@ -34,41 +44,35 @@ set(OBJC_ARC_COMPILE_OPTIONS "-fobjc-arc" "-fobjc-arc-exceptions")
# onnxruntime_objc target

# these headers are the public interface
# explicitly list them here so it is easy to see what is included
set(onnxruntime_objc_headers
"${OBJC_ROOT}/include/onnxruntime.h"
"${OBJC_ROOT}/include/ort_enums.h"
"${OBJC_ROOT}/include/ort_env.h"
"${OBJC_ROOT}/include/ort_session.h"
"${OBJC_ROOT}/include/ort_value.h"
)
file(GLOB onnxruntime_objc_headers CONFIGURE_DEPENDS
"${OBJC_ROOT}/include/*.h")

file(GLOB onnxruntime_objc_srcs
file(GLOB onnxruntime_objc_srcs CONFIGURE_DEPENDS
"${OBJC_ROOT}/src/*.h"
"${OBJC_ROOT}/src/*.m"
"${OBJC_ROOT}/src/*.mm")

# files common to implementation and test targets
set(onnxruntime_objc_common_srcs
"${OBJC_ROOT}/common/assert_arc_enabled.mm")

source_group(TREE "${OBJC_ROOT}" FILES
${onnxruntime_objc_headers}
${onnxruntime_objc_srcs}
${onnxruntime_objc_common_srcs})
${onnxruntime_objc_srcs})

add_library(onnxruntime_objc SHARED
${onnxruntime_objc_headers}
${onnxruntime_objc_srcs}
${onnxruntime_objc_common_srcs})
${onnxruntime_objc_srcs})

target_include_directories(onnxruntime_objc
PUBLIC
"${OBJC_ROOT}/include"
PRIVATE
"${ONNXRUNTIME_ROOT}"
"${ONNXRUNTIME_INCLUDE_DIR}/core/session"
"${OBJC_ROOT}")

if(onnxruntime_USE_COREML)
target_include_directories(onnxruntime_objc
PRIVATE
"${ONNXRUNTIME_INCLUDE_DIR}/core/providers/coreml")
endif()

find_library(FOUNDATION_LIB Foundation REQUIRED)

target_link_libraries(onnxruntime_objc
Expand Down Expand Up @@ -110,7 +114,7 @@ if(onnxruntime_BUILD_UNIT_TESTS)

# onnxruntime_objc_test target

file(GLOB onnxruntime_objc_test_srcs
file(GLOB onnxruntime_objc_test_srcs CONFIGURE_DEPENDS
"${OBJC_ROOT}/test/*.h"
"${OBJC_ROOT}/test/*.m"
"${OBJC_ROOT}/test/*.mm")
Expand All @@ -119,8 +123,7 @@ if(onnxruntime_BUILD_UNIT_TESTS)

xctest_add_bundle(onnxruntime_objc_test onnxruntime_objc
${onnxruntime_objc_headers}
${onnxruntime_objc_test_srcs}
${onnxruntime_objc_common_srcs})
${onnxruntime_objc_test_srcs})

target_include_directories(onnxruntime_objc_test
PRIVATE
Expand All @@ -129,12 +132,13 @@ if(onnxruntime_BUILD_UNIT_TESTS)
target_compile_options(onnxruntime_objc_test PRIVATE ${OBJC_ARC_COMPILE_OPTIONS})

set_target_properties(onnxruntime_objc_test PROPERTIES
FOLDER "ONNXRuntimeTest")
FOLDER "ONNXRuntimeTest"
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")

add_custom_command(TARGET onnxruntime_objc_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${OBJC_ROOT}/test/testdata"
"$<TARGET_BUNDLE_CONTENT_DIR:onnxruntime_objc_test>/Resources/testdata")
"$<TARGET_BUNDLE_CONTENT_DIR:onnxruntime_objc_test>/Resources")

xctest_add_test(XCTest.onnxruntime_objc_test onnxruntime_objc_test)

Expand Down
21 changes: 21 additions & 0 deletions cmake/onnxruntime_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ if (onnxruntime_ENABLE_TRAINING)
file(GLOB onnxruntime_python_ortmodule_srcs CONFIGURE_DEPENDS
"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/*.py"
)
file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_srcs CONFIGURE_DEPENDS
"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/*.py"
)
file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_aten_op_executor_srcs CONFIGURE_DEPENDS
"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/aten_op_executor/*"
)
file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_torch_gpu_allocator_srcs CONFIGURE_DEPENDS
"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/torch_gpu_allocator/*"
)
file(GLOB onnxruntime_python_train_tools_srcs CONFIGURE_DEPENDS
"${REPO_ROOT}/tools/python/register_custom_ops_pytorch_exporter.py"
)
Expand Down Expand Up @@ -406,6 +415,9 @@ if (onnxruntime_ENABLE_TRAINING)
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/amp
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/optim
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/aten_op_executor
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/torch_gpu_allocator
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_capi_training_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/training/
Expand All @@ -421,6 +433,15 @@ if (onnxruntime_ENABLE_TRAINING)
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_ortmodule_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_ortmodule_torch_cpp_ext_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_ortmodule_torch_cpp_ext_aten_op_executor_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/aten_op_executor/
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_ortmodule_torch_cpp_ext_torch_gpu_allocator_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/torch_gpu_allocator/
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_python_train_tools_srcs}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "onnxruntime_c_api.h"

// COREMLFlags are bool options we want to set for CoreML EP
// This enum is defined as bit flats, and cannot have negative value
// This enum is defined as bit flags, and cannot have negative value
// To generate an uint32_t coreml_flags for using with OrtSessionOptionsAppendExecutionProvider_CoreML below,
// uint32_t coreml_flags = 0;
// coreml_flags |= COREML_FLAG_USE_CPU_ONLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "onnxruntime_c_api.h"

// NNAPIFlags are bool options we want to set for NNAPI EP
// This enum is defined as bit flats, and cannot have negative value
// This enum is defined as bit flags, and cannot have negative value
// To generate an uint32_t nnapi_flags for using with OrtSessionOptionsAppendExecutionProvider_Nnapi below,
// uint32_t nnapi_flags = 0;
// nnapi_flags |= NNAPI_FLAG_USE_FP16;
Expand Down
3 changes: 2 additions & 1 deletion include/onnxruntime/core/session/onnxruntime_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ struct OrtApi {
_Outptr_ OrtTypeInfo** type_info);

/**
* \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.
* \param value is set to a null terminated UTF-8 encoded string allocated using 'allocator'.
* The caller is responsible for freeing it.
*/
ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* sess, size_t index, _Inout_ OrtAllocator* allocator,
_Outptr_ char** value);
Expand Down
5 changes: 5 additions & 0 deletions objectivec/docs/docs.readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ONNX Runtime Objective-C API

ONNX Runtime provides an Objective-C API.

It can be used from Objective-C/C++ or Swift with a bridging header.
13 changes: 13 additions & 0 deletions objectivec/docs/jazzy_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module: ONNX Runtime Objective-C API
author: ONNX Runtime Authors
author_url: https://www.onnxruntime.ai
github_url: https://github.com/microsoft/onnxruntime

objc: true
umbrella_header: ../include/onnxruntime.h
framework_root: ..

readme: ./docs.readme.md

hide_documentation_coverage: true
undocumented_text: ""
17 changes: 17 additions & 0 deletions objectivec/docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Objective-C API Documentation

The API should be documented with comments in the [public header files](../include).

## Documentation Generation

The [Jazzy](https://github.com/realm/jazzy) tool is used to generate documentation from the code.

For example, to generate documentation for a release version, from the repo root, run:

```bash
jazzy --config objectivec/docs/jazzy_config.yaml --output <output directory> --module-version $(cat VERSION_NUMBER)
```

The generated documentation website files will be in `<output directory>`.

[docs.readme.md](./docs.readme.md) contains content for the main page of the generated documentation website.
1 change: 0 additions & 1 deletion objectivec/format_objc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

clang-format -i $(find ${SCRIPT_DIR} -name "*.h" -o -name "*.m" -o -name "*.mm")

1 change: 1 addition & 0 deletions objectivec/include/onnxruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// this header contains the entire ONNX Runtime Objective-C API
// the headers below can also be imported individually

#import "ort_coreml_execution_provider.h"
#import "ort_enums.h"
#import "ort_env.h"
#import "ort_session.h"
Expand Down
54 changes: 54 additions & 0 deletions objectivec/include/ort_coreml_execution_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#import <Foundation/Foundation.h>

#import "ort_session.h"

NS_ASSUME_NONNULL_BEGIN

/**
* Gets whether the CoreML execution provider is available.
*/
BOOL ORTIsCoreMLExecutionProviderAvailable(void);

/**
* Options for configuring the CoreML execution provider.
*/
@interface ORTCoreMLExecutionProviderOptions : NSObject

/**
* Whether the CoreML execution provider should run on CPU only.
*/
@property BOOL useCPUOnly;

/**
* Whether the CoreML execution provider is enabled on subgraphs.
*/
@property BOOL enableOnSubgraphs;

/**
* Whether the CoreML execution provider is only enabled for devices with Apple
* Neural Engine (ANE).
*/
@property BOOL onlyEnableForDevicesWithANE;

@end

@interface ORTSessionOptions (ORTSessionOptionsCoreMLEP)

/**
* Enables the CoreML execution provider in the session configuration options.
* It is appended to the execution provider list which is ordered by
* decreasing priority.
*
* @param options The CoreML execution provider configuration options.
* @param error Optional error information set if an error occurs.
* @return Whether the provider was enabled successfully.
*/
- (BOOL)appendCoreMLExecutionProviderWithOptions:(ORTCoreMLExecutionProviderOptions*)options
error:(NSError**)error;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion objectivec/include/ort_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
* Creates an ORT Environment.
*
* @param loggingLevel The environment logging level.
* @param[out] error Optional error information set if an error occurs.
* @param error Optional error information set if an error occurs.
* @return The instance, or nil if an error occurs.
*/
- (nullable instancetype)initWithLoggingLevel:(ORTLoggingLevel)loggingLevel
Expand Down
Loading

0 comments on commit 8d6825b

Please sign in to comment.