Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/microsoft/onnxruntime int…
Browse files Browse the repository at this point in the history
…o optrf
  • Loading branch information
sdpython committed Dec 1, 2020
2 parents c4c7ecb + 2d9dcc4 commit ad600af
Show file tree
Hide file tree
Showing 52 changed files with 360 additions and 357 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cmake-build-debug
gen
*~
.vs
.DS_Store
TestResults/
.idea/
onnxruntime.egg-info
Expand Down
14 changes: 7 additions & 7 deletions cgmanifests/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"component": {
"type": "git",
"git": {
"commitHash": "f97fd8664fa824e5d081d776cf4a811dbf09bca4",
"commitHash": "bc8ce45b35ade9b8f08d88d4d9fdfd12b4f6f310",
"repositoryUrl": "https://github.com/pypa/manylinux"
},
"comments": "For building our CI build docker image"
Expand All @@ -363,20 +363,20 @@
"component": {
"type": "git",
"git": {
"commitHash": "439c93d51f45c50541fc755b597725168ecd939a",
"commitHash": "9cf6752276e6fcfd0c23fdb064ad27f448aaaf75",
"repositoryUrl": "https://github.com/python/cpython"
},
"comments": "Python 3.9.0rc1"
"comments": "Python 3.9.0"
}
},
{
"component": {
"type": "git",
"git": {
"commitHash": "580fbb018fd0844806119614d752b41fc69660f9",
"commitHash": "db455296be5f792b8c12b7cd7f3962b52e4f44ee",
"repositoryUrl": "https://github.com/python/cpython"
},
"comments": "Python 3.8.5"
"comments": "Python 3.8.6"
}
},
{
Expand All @@ -403,10 +403,10 @@
"component": {
"type": "git",
"git": {
"commitHash": "e5f6aba872e66bfd86eb592214696a519cded197",
"commitHash": "426b022776672fdf3d71ddd98d89af341c88080f",
"repositoryUrl": "https://github.com/python/cpython"
},
"comments": "Python 3.5.9"
"comments": "Python 3.5.10"
}
},
{
Expand Down
44 changes: 44 additions & 0 deletions cgmanifests/submodules/cgmanifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
{
"Version": 1,
"Registrations": [
{
"Component": {
"Type": "other",
"other": {
"Name": "automake",
"Version": "1.16.2",
"DownloadUrl": "http://ftp.gnu.org/gnu/automake/automake-1.16.2.tar.gz"
},
"comments": "manylinux dependency"
}
},
{
"Component": {
"Type": "other",
"other": {
"Name": "libtool",
"Version": "2.4.6",
"DownloadUrl": "http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz"
},
"comments": "manylinux dependency"
}
},
{
"Component": {
"Type": "other",
"other": {
"Name": "sqlite",
"Version": "3330000",
"DownloadUrl": "https://www.sqlite.org/2020/sqlite-autoconf-3330000.tar.gz"
},
"comments": "manylinux dependency"
}
},
{
"Component": {
"Type": "other",
"other": {
"Name": "git",
"Version": "2.29.1",
"DownloadUrl": "https://www.kernel.org/pub/software/scm/git/git-2.29.1.tar.gz"
},
"comments": "manylinux dependency"
}
},
{
"component": {
"type": "git",
Expand Down
46 changes: 45 additions & 1 deletion cgmanifests/submodules/generate_submodule_cgmanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,54 @@
import os
import subprocess
import sys
import re

SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", ".."))

package_name = None
package_filename = None
package_url = None

registrations = []

with open(os.path.join(REPO_DIR,'tools','ci_build','github','linux','docker','manylinux2014_build_scripts','build_env.sh'), "r") as f:
for line in f:
if not line.strip():
package_name = None
package_filename = None
package_url = None
if package_filename is None:
m = re.match("(.+?)_ROOT=(.*)$",line)
if m != None:
package_name = m.group(1)
package_filename = m.group(2)
else:
m = re.match("(.+?)_AUTOCONF_VERSION=(.*)$",line)
if m != None:
package_name = m.group(1)
package_filename = m.group(2)
elif package_url is None:
m = re.match("(.+?)_DOWNLOAD_URL=(.+)$",line)
if m != None:
package_url = m.group(2) + "/" + package_filename + ".tar.gz"
registration = {
"Component": {
"Type": "other",
"other": {
"Name": package_name.lower(),
"Version": package_filename.split("-")[-1],
"DownloadUrl": package_url,
},
"comments": "manylinux dependency"
}
}
registrations.append(registration)
package_name = None
package_filename = None
package_url = None


proc = subprocess.run(
["git", "submodule", "foreach", "--quiet", "--recursive", "{} {} $toplevel/$sm_path".format(
sys.executable, os.path.join(SCRIPT_DIR, "print_submodule_info.py"))],
Expand All @@ -17,7 +61,7 @@
stderr=subprocess.PIPE,
universal_newlines=True)

registrations = []

submodule_lines = proc.stdout.splitlines()
for submodule_line in submodule_lines:
(absolute_path, url, commit) = submodule_line.split(" ")
Expand Down
4 changes: 2 additions & 2 deletions cmake/external/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if(NOT TARGET pybind11::module)

set(pybind11_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/pybind11/src/pybind11/include)
set(pybind11_URL https://github.com/pybind/pybind11.git)
set(pybind11_TAG v2.4.0)
set(pybind11_TAG v2.6.1)

ExternalProject_Add(pybind11
PREFIX pybind11
Expand All @@ -21,4 +21,4 @@ if(NOT TARGET pybind11::module)
set(pybind11_dep pybind11)
else()
set(pybind11_lib pybind11::module)
endif()
endif()
18 changes: 9 additions & 9 deletions cmake/onnxruntime_mlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ if(MSVC)
)
endif()
else()
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(ARM64 TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm")
set(ARM TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
set(X86_64 TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "i386")
set(X86 TRUE)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
if (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
set(ARM TRUE)
Expand All @@ -136,15 +145,6 @@ else()
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "iOSCross")
set(IOS TRUE)
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(ARM64 TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "arm")
set(ARM TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
set(X86_64 TRUE)
elseif (CMAKE_OSX_ARCHITECTURES STREQUAL "i386")
set(X86 TRUE)
endif()
else()
execute_process(
COMMAND ${CMAKE_C_COMPILER} -dumpmachine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ docker run --gpus all --rm \
-e "PackageName=$PackageName" \
-e "RunTestCsharp=$RunTestCsharp" \
-e "RunTestNative=$RunTestNative" \
onnxruntimebuildcache.azurecr.io/internal/azureml/onnxruntimecentosgpubuild:ch4 \
onnxruntimebuildcache.azurecr.io/internal/azureml/onnxruntimegpubuild:ch4 \
/bin/bash /onnxruntime_src/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh \
/home/onnxruntimedev/$NUGET_REPO_DIRNAME /onnxruntime_src /home/onnxruntimedev $CurrentOnnxRuntimeVersion
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ docker run --rm \
-e "DisableMlOps=$DISABLEMLOPS" \
-e "RunTestCsharp=$RunTestCsharp" \
-e "RunTestNative=$RunTestNative" \
onnxruntimebuildcache.azurecr.io/internal/azureml/onnxruntimecentoscpubuild:ch3 \
onnxruntimebuildcache.azurecr.io/internal/azureml/onnxruntimecentoscpubuild:chr \
/bin/bash /onnxruntime_src/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh \
/home/onnxruntimedev/$NUGET_REPO_DIRNAME /onnxruntime_src /home/onnxruntimedev $CurrentOnnxRuntimeVersion
2 changes: 1 addition & 1 deletion include/onnxruntime/core/session/onnxruntime_cxx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ struct Session : Base<OrtSession> {
// Run that will allocate the output values
std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
const char* const* output_names, size_t output_count);
// Run for when there is a list of prealloated outputs
// Run for when there is a list of preallocated outputs
void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,
const char* const* output_names, Value* output_values, size_t output_count);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// Created by daquexian on 8/3/18.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <iostream>
#include <string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by daquexian on 5/21/18.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,10 @@ Status ConcatOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const
class SqueezeOpBuilder : public BaseOpBuilder {
public:
void AddInitializersToSkip(ModelBuilder& model_builder, const Node& node) const override;
static Status AddSqueezeOp(ModelBuilder& model_builder,
const std::string& node_name,
const std::string& input, const std::string& output,
vector<int32_t> axes) ORT_MUST_USE_RESULT;

private:
Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node) const override ORT_MUST_USE_RESULT;
Expand All @@ -1779,6 +1783,49 @@ void SqueezeOpBuilder::AddInitializersToSkip(ModelBuilder& model_builder, const
}
}

/* static */ Status SqueezeOpBuilder::AddSqueezeOp(ModelBuilder& model_builder,
const std::string& node_name,
const std::string& input, const std::string& output,
vector<int32_t> axes) {
auto& shaper(model_builder.GetShaper());
const auto& operand_indices(model_builder.GetOperandIndices());
const auto& operand_types(model_builder.GetOperandTypes());

const auto& input_shape(shaper[input]);
auto input_dims = input_shape.size();
for (auto& axis : axes) {
axis = static_cast<int32_t>(HandleNegativeAxis(axis, input_dims));
}

// Despite the spec of ANEURALNETWORKS_SQUEEZE at
// https://developer.android.com/ndk/reference/group/neural-networks
// states, that the axes (input 1 of ANEURALNETWORKS_SQUEEZE) is optional.
//
// The actual code of NNAPI requires the axes to be provided
// https://android.googlesource.com/platform/frameworks/ml/+/master/nn/common/operations/Squeeze.cpp#31
if (axes.empty()) { // Squeeze all
for (size_t i = 0; i < input_dims; i++) {
if (input_shape[i] == 1)
axes.push_back(i);
}
}

const auto axes_name = model_builder.GetUniqueName(node_name + input + "_axes");
Shape axes_dimen = {static_cast<uint32_t>(axes.size())};
const OperandType axes_operand_type(Type::TENSOR_INT32, axes_dimen);
ORT_RETURN_IF_ERROR(model_builder.AddOperandFromPersistMemoryBuffer(axes_name, axes.data(), axes_operand_type));

std::vector<uint32_t> input_indices;
input_indices.push_back(operand_indices.at(input)); // input
input_indices.push_back(operand_indices.at(axes_name)); // axes

ORT_RETURN_IF_ERROR(shaper.Squeeze(input, axes, output));
const OperandType output_operand_type(operand_types.at(input).type, shaper[output]);
ORT_RETURN_IF_ERROR(model_builder.AddOperation(ANEURALNETWORKS_SQUEEZE, input_indices,
{output}, {output_operand_type}, {false}));
return Status::OK();
}

/* static */ vector<int32_t> SqueezeOpBuilder::GetAxes(ModelBuilder& model_builder, const Node& node) {
vector<int32_t> axes;
// Squeeze opset 13 use input as axes
Expand All @@ -1804,47 +1851,13 @@ void SqueezeOpBuilder::AddInitializersToSkip(ModelBuilder& model_builder, const
}

Status SqueezeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node) const {
auto& shaper(model_builder.GetShaper());
const auto& operand_indices(model_builder.GetOperandIndices());
const auto& operand_types(model_builder.GetOperandTypes());

auto input = node.InputDefs()[0]->Name();
if (model_builder.IsOperandNHWC(input)) {
// We want to transpose nhwc operand back to nchw before squeeze
ORT_RETURN_IF_ERROR(GetNCHWInput(model_builder, node, 0, input));
}

NodeAttrHelper helper(node);
vector<int32_t> axes = GetAxes(model_builder, node);
const auto& input_shape(shaper[input]);
auto input_dims = input_shape.size();
for (auto& axis : axes) {
axis = static_cast<int32_t>(HandleNegativeAxis(axis, input_dims));
}

if (axes.empty()) { // Squeeze all
for (size_t i = 0; i < input_dims; i++) {
if (input_shape[i] == 1)
axes.push_back(i);
}
}

const auto axes_name = model_builder.GetUniqueName(node.Name() + input + "_axes");
Shape axes_dimen = {static_cast<uint32_t>(axes.size())};
shaper.AddShape(axes_name, axes_dimen);
const OperandType axes_operand_type(Type::TENSOR_INT32, axes_dimen);
ORT_RETURN_IF_ERROR(model_builder.AddOperandFromPersistMemoryBuffer(axes_name, axes.data(), axes_operand_type));

std::vector<uint32_t> input_indices;
input_indices.push_back(operand_indices.at(input)); // input
input_indices.push_back(operand_indices.at(axes_name)); // axes

const auto& output = node.OutputDefs()[0]->Name();
ORT_RETURN_IF_ERROR(shaper.Squeeze(input, axes, output));
const OperandType output_operand_type(operand_types.at(input).type, shaper[output]);
ORT_RETURN_IF_ERROR(model_builder.AddOperation(ANEURALNETWORKS_SQUEEZE, input_indices,
{output}, {output_operand_type}, {false}));
return Status::OK();
return AddSqueezeOp(model_builder, node.Name(), input, node.OutputDefs()[0]->Name(), GetAxes(model_builder, node));
}

#pragma endregion
Expand Down
Loading

0 comments on commit ad600af

Please sign in to comment.