Skip to content

Commit 530117c

Browse files
stevenlixRyan Laipranavsharmatracysh
authored
Cherry pick more commits to Rel-1.3.1 (#4231)
* Fix deprecated CentOS link for Linux CI pipeline (#4000) * Fix Linux_CI_GPU_Dev * centos6 * Fix crash reported in #4070. (#4091) * Fix crash reported in #4070. * Add newline to warning message * Add comment for using cout instead of the logger * fix optional input/outputs (#4229) Co-authored-by: Ryan Lai <[email protected]> Co-authored-by: Pranav Sharma <[email protected]> Co-authored-by: Tracy Sharpe <[email protected]>
1 parent 814638c commit 530117c

File tree

8 files changed

+97
-13
lines changed

8 files changed

+97
-13
lines changed

cmake/onnxruntime_unittests.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ endif()
220220

221221
set (ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR "${ONNXRUNTIME_ROOT}/test/shared_lib")
222222
set (ONNXRUNTIME_GLOBAL_THREAD_POOLS_TEST_SRC_DIR "${ONNXRUNTIME_ROOT}/test/global_thread_pools")
223+
set (ONNXRUNTIME_API_TESTS_WITHOUT_ENV_SRC_DIR "${ONNXRUNTIME_ROOT}/test/api_tests_without_env")
223224

224225
set (onnxruntime_shared_lib_test_SRC
225226
${ONNXRUNTIME_SHARED_LIB_TEST_SRC_DIR}/test_fixture.h
@@ -238,6 +239,9 @@ set (onnxruntime_global_thread_pools_test_SRC
238239
${ONNXRUNTIME_GLOBAL_THREAD_POOLS_TEST_SRC_DIR}/test_main.cc
239240
${ONNXRUNTIME_GLOBAL_THREAD_POOLS_TEST_SRC_DIR}/test_inference.cc)
240241

242+
set (onnxruntime_api_tests_without_env_SRC
243+
${ONNXRUNTIME_API_TESTS_WITHOUT_ENV_SRC_DIR}/test_apis_without_env.cc)
244+
241245
# tests from lowest level library up.
242246
# the order of libraries should be maintained, with higher libraries being added first in the list
243247

@@ -763,6 +767,16 @@ if (onnxruntime_BUILD_SHARED_LIB)
763767
DEPENDS ${all_dependencies}
764768
)
765769
endif()
770+
771+
# A separate test is needed to test the APIs that don't rely on the env being created first.
772+
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
773+
AddTest(DYN
774+
TARGET onnxruntime_api_tests_without_env
775+
SOURCES ${onnxruntime_api_tests_without_env_SRC}
776+
LIBS ${onnxruntime_shared_lib_test_LIBS}
777+
DEPENDS ${all_dependencies}
778+
)
779+
endif()
766780
endif()
767781

768782
#some ETW tools

onnxruntime/core/framework/provider_bridge_ort.cc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "core/framework/data_types.h"
88
#include "core/framework/allocatormgr.h"
99
#include "core/providers/dnnl/dnnl_provider_factory.h"
10+
#include "core/session/inference_session.h"
1011
#include "core/session/abi_session_options_impl.h"
1112
#include "core/session/ort_apis.h"
1213
#include "core/platform/env.h"

onnxruntime/core/framework/sequential_executor.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void CalculateTotalOutputSizes(OpKernelContextInternal* op_kernel_context
5555
ORT_UNUSED_PARAMETER(node_name);
5656
for (auto i = 0; i < op_kernel_context->OutputCount(); i++) {
5757
const OrtValue* p_output = op_kernel_context->GetOutputMLValue(i);
58-
if (p_output->IsTensor()) {
58+
if (p_output != nullptr && p_output->IsTensor()) {
5959
const auto& tensor = p_output->Get<Tensor>();
6060
size_t tensor_size = tensor.SizeInBytes();
6161
#if defined(TRACE_EXECUTION)
@@ -83,7 +83,7 @@ static void CalculateTotalInputSizes(const OpKernelContextInternal* op_kernel_co
8383
const int input_count = op_kernel_context->InputCount();
8484
for (auto i = 0; i < input_count; i++) {
8585
const OrtValue* p_input = op_kernel_context->GetInputMLValue(i);
86-
if (p_input->IsTensor()) {
86+
if (p_input != nullptr && p_input->IsTensor()) {
8787
const OpKernelInfo& op_kernel_info = p_op_kernel->Info();
8888
const Tensor* p_tensor = nullptr;
8989
bool is_param = op_kernel_info.TryGetConstantInput(i, &p_tensor);
@@ -241,7 +241,7 @@ Status SequentialExecutor::Execute(const SessionState& session_state, const std:
241241

242242
const std::string node_name_for_profiling = [&]() -> std::string {
243243
if (!is_profiler_enabled) return {};
244-
// Derive something meaningful for profile traces and logs if node name field is blank in execution graph
244+
// Derive something meaningful for profile traces and logs if node name field is blank in execution graph
245245
return node.Name().empty() ? MakeString(node.OpType(), "_", node_index) : node.Name();
246246
}();
247247

onnxruntime/core/session/abi_session_options.cc

+8-7
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ ORT_API_STATUS_IMPL(OrtApis::SetIntraOpNumThreads, _Inout_ OrtSessionOptions* op
144144
#ifdef _OPENMP
145145
ORT_UNUSED_PARAMETER(options);
146146
ORT_UNUSED_PARAMETER(intra_op_num_threads);
147-
LOGS_DEFAULT(WARNING) << "Since openmp is enabled in this build, this API cannot be used to configure"
148-
" intra op num threads. Please use the openmp environment variables to control"
149-
" the number of threads.";
147+
// Can't use the default logger here since it's possible that the default logger has not been created
148+
// at this point. The default logger gets created when the env is created and these APIs don't require
149+
// the env to be created first.
150+
std::cout << "WARNING: Since openmp is enabled in this build, this API cannot be used to configure"
151+
" intra op num threads. Please use the openmp environment variables to control"
152+
" the number of threads.\n";
150153
#else
151154
options->value.intra_op_param.thread_pool_size = intra_op_num_threads;
152155
#endif
@@ -161,16 +164,14 @@ ORT_API_STATUS_IMPL(OrtApis::SetInterOpNumThreads, _Inout_ OrtSessionOptions* op
161164
ORT_API_STATUS_IMPL(OrtApis::AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options,
162165
_In_ const char* dim_denotation, _In_ int64_t dim_value) {
163166
options->value.free_dimension_overrides.push_back(
164-
onnxruntime::FreeDimensionOverride{dim_denotation, onnxruntime::FreeDimensionOverrideType::Denotation, dim_value}
165-
);
167+
onnxruntime::FreeDimensionOverride{dim_denotation, onnxruntime::FreeDimensionOverrideType::Denotation, dim_value});
166168
return nullptr;
167169
}
168170

169171
ORT_API_STATUS_IMPL(OrtApis::AddFreeDimensionOverrideByName, _Inout_ OrtSessionOptions* options,
170172
_In_ const char* dim_name, _In_ int64_t dim_value) {
171173
options->value.free_dimension_overrides.push_back(
172-
onnxruntime::FreeDimensionOverride{dim_name, onnxruntime::FreeDimensionOverrideType::Name, dim_value}
173-
);
174+
onnxruntime::FreeDimensionOverride{dim_name, onnxruntime::FreeDimensionOverrideType::Name, dim_value});
174175
return nullptr;
175176
}
176177

onnxruntime/core/session/abi_session_options_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include <vector>
88
#include <atomic>
9-
#include "core/session/inference_session.h"
9+
#include "core/framework/session_options.h"
1010
#include "core/session/onnxruntime_c_api.h"
1111
#include "core/providers/providers.h"
1212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#ifndef USE_ONNXRUNTIME_DLL
5+
#ifdef __GNUC__
6+
#pragma GCC diagnostic push
7+
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
8+
#pragma GCC diagnostic ignored "-Wunused-parameter"
9+
#else
10+
#pragma warning(push)
11+
#pragma warning(disable : 4018) /*'expression' : signed/unsigned mismatch */
12+
#pragma warning(disable : 4065) /*switch statement contains 'default' but no 'case' labels*/
13+
#pragma warning(disable : 4100)
14+
#pragma warning(disable : 4146) /*unary minus operator applied to unsigned type, result still unsigned*/
15+
#pragma warning(disable : 4127)
16+
#pragma warning(disable : 4244) /*'conversion' conversion from 'type1' to 'type2', possible loss of data*/
17+
#pragma warning(disable : 4251) /*'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'*/
18+
#pragma warning(disable : 4267) /*'var' : conversion from 'size_t' to 'type', possible loss of data*/
19+
#pragma warning(disable : 4305) /*'identifier' : truncation from 'type1' to 'type2'*/
20+
#pragma warning(disable : 4307) /*'operator' : integral constant overflow*/
21+
#pragma warning(disable : 4309) /*'conversion' : truncation of constant value*/
22+
#pragma warning(disable : 4334) /*'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)*/
23+
#pragma warning(disable : 4355) /*'this' : used in base member initializer list*/
24+
#pragma warning(disable : 4506) /*no definition for inline function 'function'*/
25+
#pragma warning(disable : 4800) /*'type' : forcing value to bool 'true' or 'false' (performance warning)*/
26+
#pragma warning(disable : 4996) /*The compiler encountered a deprecated declaration.*/
27+
#pragma warning(disable : 6011) /*Dereferencing NULL pointer*/
28+
#pragma warning(disable : 6387) /*'value' could be '0'*/
29+
#pragma warning(disable : 26495) /*Variable is uninitialized.*/
30+
#endif
31+
#include <google/protobuf/message_lite.h>
32+
#ifdef __GNUC__
33+
#pragma GCC diagnostic pop
34+
#else
35+
#pragma warning(pop)
36+
#endif
37+
#endif
38+
39+
#include "gtest/gtest.h"
40+
#include "core/session/onnxruntime_cxx_api.h"
41+
#include "core/session/abi_session_options_impl.h"
42+
43+
TEST(TestSessionOptions, SetIntraOpNumThreadsWithoutEnv) {
44+
Ort::SessionOptions session_options;
45+
session_options.SetIntraOpNumThreads(48);
46+
const auto* ort_session_options = (const OrtSessionOptions*)session_options;
47+
#ifdef _OPENMP
48+
ASSERT_EQ(ort_session_options->value.intra_op_param.thread_pool_size, 0);
49+
#else
50+
ASSERT_EQ(ort_session_options->value.intra_op_param.thread_pool_size, 48);
51+
#endif
52+
}
53+
54+
int main(int argc, char** argv) {
55+
int status = 0;
56+
try {
57+
::testing::InitGoogleTest(&argc, argv);
58+
status = RUN_ALL_TESTS();
59+
} catch (const std::exception& ex) {
60+
std::cerr << ex.what();
61+
status = -1;
62+
}
63+
64+
#ifndef USE_ONNXRUNTIME_DLL
65+
//make memory leak checker happy
66+
::google::protobuf::ShutdownProtobufLibrary();
67+
#endif
68+
return status;
69+
}

onnxruntime/test/shared_lib/test_fixture.h

-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ typedef const char* PATH_TYPE;
1616
static inline void ORT_API_CALL MyLoggingFunction(void*, OrtLoggingLevel, const char*, const char*, const char*, const char*) {
1717
}
1818

19-

tools/ci_build/github/linux/docker/scripts/install_centos.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ elif [ "$os_major_version" == "6" ] && [ ! -d "/opt/python/cp35-cp35m" ]; then
1616
#The base image we are using already contains devtoolset-2
1717
yum install -y redhat-lsb-core expat-devel libcurl-devel tar unzip curl zlib-devel make libunwind icu aria2 rsync bzip2 git bzip2-devel
1818
#Install python 3.6
19-
yum install -y https://centos6.iuscommunity.org/ius-release.rpm
19+
yum install -y https://repo.ius.io/ius-release-el6.rpm
2020
yum --enablerepo=ius install -y python36u python36u-devel python36u-pip python36u-numpy python36u-setuptools python36u-wheel
2121
/usr/bin/python3.6 -m pip install --upgrade pip
2222
else

0 commit comments

Comments
 (0)