From cf41f76d79595fb766444b26d96db3759965e4f9 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Wed, 6 Mar 2019 11:46:59 -0800 Subject: [PATCH] Fix some warnings (#551) --- onnxruntime/core/framework/allocator.cc | 5 +++-- onnxruntime/core/framework/error_code.cc | 4 ++-- onnxruntime/core/framework/execution_frame.cc | 2 +- .../core/framework/kernel_registry_manager.cc | 3 ++- onnxruntime/core/framework/onnxruntime_typeinfo.cc | 2 +- onnxruntime/core/framework/path_lib.cc | 2 +- onnxruntime/core/framework/session_state.cc | 12 +++++------- .../core/framework/session_state_initializer.cc | 8 ++++---- onnxruntime/core/framework/tensor_type_and_shape.cc | 4 ++-- onnxruntime/core/framework/tensorprotoutils.cc | 4 ++-- onnxruntime/core/framework/utils.cc | 3 +-- 11 files changed, 24 insertions(+), 25 deletions(-) diff --git a/onnxruntime/core/framework/allocator.cc b/onnxruntime/core/framework/allocator.cc index b070287ebf..ddc45508c2 100644 --- a/onnxruntime/core/framework/allocator.cc +++ b/onnxruntime/core/framework/allocator.cc @@ -49,12 +49,13 @@ std::ostream& operator<<(std::ostream& out, const OrtAllocatorInfo& info) { return (out << info.ToString()); } -ORT_API_STATUS_IMPL(OrtCreateAllocatorInfo, const char* name1, OrtAllocatorType type, int id1, OrtMemType mem_type1, OrtAllocatorInfo** out) { +ORT_API_STATUS_IMPL(OrtCreateAllocatorInfo, _In_ const char* name1, OrtAllocatorType type, int id1, + OrtMemType mem_type1, _Out_ OrtAllocatorInfo** out) { *out = new OrtAllocatorInfo(name1, type, id1, mem_type1); return nullptr; } -ORT_API(void, OrtReleaseAllocatorInfo, OrtAllocatorInfo* p) { +ORT_API(void, OrtReleaseAllocatorInfo, _Frees_ptr_opt_ OrtAllocatorInfo* p) { delete p; } diff --git a/onnxruntime/core/framework/error_code.cc b/onnxruntime/core/framework/error_code.cc index fe7287248e..82f7f32454 100644 --- a/onnxruntime/core/framework/error_code.cc +++ b/onnxruntime/core/framework/error_code.cc @@ -12,7 +12,7 @@ struct OrtStatus { char msg[1]; // a null-terminated string }; -ORT_API(OrtStatus*, OrtCreateStatus, OrtErrorCode code, const char* msg) { +ORT_API(OrtStatus*, OrtCreateStatus, OrtErrorCode code, _In_ const char* msg) { assert(!(code == 0 && msg != nullptr)); size_t clen = strlen(msg); OrtStatus* p = reinterpret_cast(new char[sizeof(OrtStatus) + clen]); @@ -42,4 +42,4 @@ ORT_API(const char*, OrtGetErrorMessage, _In_ const OrtStatus* status) { return status->msg; } -ORT_API(void, OrtReleaseStatus, OrtStatus* value) { delete[] reinterpret_cast(value); } +ORT_API(void, OrtReleaseStatus, _Frees_ptr_opt_ OrtStatus* value) { delete[] reinterpret_cast(value); } diff --git a/onnxruntime/core/framework/execution_frame.cc b/onnxruntime/core/framework/execution_frame.cc index d66add7d3b..e7ae8805c2 100644 --- a/onnxruntime/core/framework/execution_frame.cc +++ b/onnxruntime/core/framework/execution_frame.cc @@ -416,7 +416,7 @@ Status ExecutionFrame::CreateNodeOutputMLValueImpl(MLValue& mlvalue, int mlvalue } Status ExecutionFrame::ReleaseMLValueImpl(int mlvalue_idx) { - IExecutionFrame::ReleaseMLValueImpl(mlvalue_idx); + ORT_RETURN_IF_ERROR(IExecutionFrame::ReleaseMLValueImpl(mlvalue_idx)); TraceFree(mlvalue_idx); return Status::OK(); } diff --git a/onnxruntime/core/framework/kernel_registry_manager.cc b/onnxruntime/core/framework/kernel_registry_manager.cc index bbfe0e5f8a..d8c7099f53 100644 --- a/onnxruntime/core/framework/kernel_registry_manager.cc +++ b/onnxruntime/core/framework/kernel_registry_manager.cc @@ -57,7 +57,8 @@ Status KernelRegistryManager::RegisterKernels(const ExecutionProviders& executio for (auto& provider : execution_providers) { auto iter = provider_type_to_registry_.find(provider->Type()); if (iter != provider_type_to_registry_.end()) { - ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "found duplicated provider ", provider->Type(), " in KernelRegistryManager"); + return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "found duplicated provider ", provider->Type(), + " in KernelRegistryManager"); } provider_type_to_registry_.insert(std::make_pair(provider->Type(), provider->GetKernelRegistry())); } diff --git a/onnxruntime/core/framework/onnxruntime_typeinfo.cc b/onnxruntime/core/framework/onnxruntime_typeinfo.cc index dc408b3ed5..9179ad3d96 100644 --- a/onnxruntime/core/framework/onnxruntime_typeinfo.cc +++ b/onnxruntime/core/framework/onnxruntime_typeinfo.cc @@ -25,7 +25,7 @@ ORT_API(const struct OrtTensorTypeAndShapeInfo*, OrtCastTypeInfoToTensorInfo, _I return input->type == ONNX_TYPE_TENSOR ? input->data : nullptr; } -ORT_API(void, OrtReleaseTypeInfo, OrtTypeInfo* ptr) { +ORT_API(void, OrtReleaseTypeInfo, _Frees_ptr_opt_ OrtTypeInfo* ptr) { delete ptr; } diff --git a/onnxruntime/core/framework/path_lib.cc b/onnxruntime/core/framework/path_lib.cc index 92ea842b60..01134ddcca 100644 --- a/onnxruntime/core/framework/path_lib.cc +++ b/onnxruntime/core/framework/path_lib.cc @@ -55,7 +55,7 @@ common::Status GetDirNameFromFilePath(const std::basic_string& s, std auto st = onnxruntime::RemoveFileSpec(const_cast(ret.data()), ret.length() + 1); if (!st.IsOK()) { std::ostringstream oss; - oss << "illegal input path:", ToMBString(s); + oss << "illegal input path:" << ToMBString(s); return Status(st.Category(), st.Code(), oss.str()); } ret.resize(wcslen(ret.c_str())); diff --git a/onnxruntime/core/framework/session_state.cc b/onnxruntime/core/framework/session_state.cc index dc6f727730..e8b116d283 100644 --- a/onnxruntime/core/framework/session_state.cc +++ b/onnxruntime/core/framework/session_state.cc @@ -98,8 +98,6 @@ Status SessionState::UpdateMemoryPatternGroupCache(const std::vectorName(), " (", current_provider, - ") and node ", node_info.p_node->Name(), " (", new_provider, ")."); + return ORT_MAKE_STATUS(ONNXRUNTIME, NOT_IMPLEMENTED, + "Using an input in multiple nodes on different devices is not supported currently. Input:", + input_name, " is used by node ", existing_entry.p_node->Name(), " (", current_provider, + ") and node ", node_info.p_node->Name(), " (", new_provider, ")."); } } } - return status; + return Status::OK(); } common::Status SessionState::GetInputNodeInfo(const std::string& input_name, diff --git a/onnxruntime/core/framework/session_state_initializer.cc b/onnxruntime/core/framework/session_state_initializer.cc index 09c6cffd09..ce72678484 100644 --- a/onnxruntime/core/framework/session_state_initializer.cc +++ b/onnxruntime/core/framework/session_state_initializer.cc @@ -445,13 +445,13 @@ common::Status SaveInputOutputNamesToNodeMapping(const onnxruntime::Graph& graph SessionState::NodeInfo node_info(index, &node, kci); if (IsArgNameInInputsOutputs(arg.Name(), graph_inputs)) { - session_state.AddInputNameToNodeInfoMapping(arg.Name(), node_info); + ORT_RETURN_IF_ERROR(session_state.AddInputNameToNodeInfoMapping(arg.Name(), node_info)); return Status::OK(); } if (implicit_inputs) { if (IsArgNameInInputsOutputs(arg.Name(), *implicit_inputs)) { - session_state.AddInputNameToNodeInfoMapping(arg.Name(), node_info); + ORT_RETURN_IF_ERROR(session_state.AddInputNameToNodeInfoMapping(arg.Name(), node_info)); return Status::OK(); } } @@ -476,7 +476,7 @@ common::Status SaveInputOutputNamesToNodeMapping(const onnxruntime::Graph& graph // copy to a different device is required SessionState::NodeInfo node_info(std::numeric_limits::max(), &node, kci); for (const auto& input_def : node_implicit_inputs) { - session_state.AddInputNameToNodeInfoMapping(input_def->Name(), node_info); + ORT_RETURN_IF_ERROR(session_state.AddInputNameToNodeInfoMapping(input_def->Name(), node_info)); } } } @@ -498,7 +498,7 @@ common::Status SaveInputOutputNamesToNodeMapping(const onnxruntime::Graph& graph // dummy entry for an input that we didn't find a use of in the graph. warn about it in case that's a bug. // utils::CopyOneInputAcrossDevices will use the input MLValue as is given we don't believe it's used anywhere. LOGS(session_state.Logger(), WARNING) << "Graph input with name " << name << " is not associated with a node. "; - session_state.AddInputNameToNodeInfoMapping(name, empty_node_info); + ORT_RETURN_IF_ERROR(session_state.AddInputNameToNodeInfoMapping(name, empty_node_info)); } } diff --git a/onnxruntime/core/framework/tensor_type_and_shape.cc b/onnxruntime/core/framework/tensor_type_and_shape.cc index 6d26e91ad0..3fd5323536 100644 --- a/onnxruntime/core/framework/tensor_type_and_shape.cc +++ b/onnxruntime/core/framework/tensor_type_and_shape.cc @@ -36,7 +36,7 @@ ORT_API(OrtTensorTypeAndShapeInfo*, OrtCreateTensorTypeAndShapeInfo) { return new OrtTensorTypeAndShapeInfo(); } -ORT_API(void, OrtReleaseTensorTypeAndShapeInfo, OrtTensorTypeAndShapeInfo* ptr) { +ORT_API(void, OrtReleaseTensorTypeAndShapeInfo, _Frees_ptr_opt_ OrtTensorTypeAndShapeInfo* ptr) { delete ptr; } @@ -47,7 +47,7 @@ ORT_API_STATUS_IMPL(OrtSetTensorElementType, _In_ OrtTensorTypeAndShapeInfo* thi API_IMPL_END } -ORT_API_STATUS_IMPL(OrtSetDims, _In_ OrtTensorTypeAndShapeInfo* this_ptr, _In_ const int64_t* dim_values, size_t dim_count) { +ORT_API_STATUS_IMPL(OrtSetDims, OrtTensorTypeAndShapeInfo* this_ptr, _In_ const int64_t* dim_values, size_t dim_count) { API_IMPL_BEGIN this_ptr->shape = onnxruntime::TensorShape(dim_values, dim_count); return nullptr; diff --git a/onnxruntime/core/framework/tensorprotoutils.cc b/onnxruntime/core/framework/tensorprotoutils.cc index 74a04000dc..aab55c1eee 100644 --- a/onnxruntime/core/framework/tensorprotoutils.cc +++ b/onnxruntime/core/framework/tensorprotoutils.cc @@ -217,7 +217,7 @@ Status UnpackTensor(const ONNX_NAMESPACE::TensorProto& tensor, const void* raw_d return Status(common::ONNXRUNTIME, common::FAIL, "UnpackTensor: the pre-allocate size does not match the size in proto"); - const int max_value = std::numeric_limits::max(); + constexpr int max_value = std::numeric_limits::max(); for (int i = 0; i < static_cast(expected_size); i++) { int v = tensor.int32_data()[i]; if (v < 0 || v > max_value) { @@ -251,7 +251,7 @@ Status UnpackTensor(const ONNX_NAMESPACE::TensorProto& tensor, const void* raw_d return Status(common::ONNXRUNTIME, common::FAIL, "UnpackTensor: the pre-allocate size does not match the size in proto"); - const int max_value = std::numeric_limits::max(); + constexpr int max_value = std::numeric_limits::max(); for (int i = 0; i < static_cast(expected_size); i++) { int v = tensor.int32_data()[i]; if (v < 0 || v > max_value) { diff --git a/onnxruntime/core/framework/utils.cc b/onnxruntime/core/framework/utils.cc index 8dca321872..c84cc33217 100644 --- a/onnxruntime/core/framework/utils.cc +++ b/onnxruntime/core/framework/utils.cc @@ -142,8 +142,7 @@ common::Status CopyOneInputAcrossDevices(const SessionState& session_state, // If a node requires input on cpu and input tensor is allocated with pinned memory allocator, don't do copy if (required_provider_type == onnxruntime::kCpuExecutionProvider && - (input_tensor_loc.mem_type == OrtMemTypeCPU || - input_tensor_loc.mem_type == OrtMemTypeCPUOutput)) { + input_tensor_loc.mem_type == OrtMemTypeCPU) { new_mlvalue = orig_mlvalue; break; }