forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Ort v1.15.0 ov changes customer a #314
Open
preetha-intel
wants to merge
9
commits into
ort_v1.15.0_ov_changes
Choose a base branch
from
ort_v1.15.0_ov_changes_customerA
base: ort_v1.15.0_ov_changes
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9b6a51a
Enable inference precision for OV inference
preetha-intel ba69aed
Remove legacy OV API reference
preetha-intel 7f2f30e
Remove enable_dynamic_shapes API
preetha-intel 2ef1750
Enable LUID and handle Ngraph deprecations (#310)
preetha-intel 9112813
Add warnings for corner case runtime options
preetha-intel 6326e58
Add 2023.1 support; Fix string nullptr bug
sspintel b916082
Merge pull request #318 from intel/customerA
sspintel 6dadd2b
Fix for when device_type is empty
sspintel 3c47cf2
Merge pull request #319 from intel/customerA
sspintel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ | |
#include <fstream> | ||
|
||
#include "ov_interface.h" | ||
#include <ngraph/pass/convert_fp32_to_fp16.hpp> | ||
#include <ngraph/pass/constant_folding.hpp> | ||
#include "openvino/pass/convert_fp32_to_fp16.hpp" | ||
#include "openvino/pass/constant_folding.hpp" | ||
#include "core/providers/shared_library/provider_api.h" | ||
#include "backend_utils.h" | ||
|
||
|
@@ -50,14 +50,14 @@ struct static_cast_int64 { | |
std::shared_ptr<OVNetwork> | ||
CreateOVModel(const ONNX_NAMESPACE::ModelProto& model_proto, const GlobalContext& global_context, | ||
const SubGraphContext& subgraph_context, | ||
std::map<std::string, std::shared_ptr<ngraph::Node>>& const_outputs_map) { | ||
std::map<std::string, std::shared_ptr<ov::Node>>& const_outputs_map) { | ||
if (IsCILogEnabled()) { | ||
std::cout << "CreateNgraphFunc" << std::endl; | ||
} | ||
const std::string model = model_proto.SerializeAsString(); | ||
try { | ||
auto cnn_network = global_context.ie_core.ReadModel(model); | ||
if ((subgraph_context.precision == InferenceEngine::Precision::FP16) && | ||
if ((subgraph_context.precision == "FP16") && | ||
(global_context.device_type.find("VPUX") == std::string::npos)) { | ||
// FP16 transformations | ||
ov::pass::ConvertFP32ToFP16 pass_obj; | ||
|
@@ -88,20 +88,19 @@ CreateOVModel(const ONNX_NAMESPACE::ModelProto& model_proto, const GlobalContext | |
size_t index = results.size() - 1; | ||
|
||
for (auto it = results.rbegin(); it != results.rend(); ++it) { | ||
if (auto const_node = std::dynamic_pointer_cast<ngraph::op::Constant>((*it)->input_value(0).get_node_shared_ptr())) { | ||
if (auto const_node = std::dynamic_pointer_cast<ov::op::v0::Constant>((*it)->input_value(0).get_node_shared_ptr())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using OV API 1.0 or 2.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are with API 2.0 as we are supporting only the latest three release of OV. |
||
const_outputs_map[(*it)->get_friendly_name()] = const_node; | ||
results.erase(results.begin() + index); | ||
} | ||
--index; | ||
} | ||
} | ||
#ifndef NDEBUG | ||
#if defined(OPENVINO_2022_3) || (OPENVINO_2023_0) | ||
#if defined(OPENVINO_2022_3) || (OPENVINO_2023_0) || (OPENVINO_2023_1) | ||
if (IsDebugEnabled()) { | ||
std::string name = cnn_network->get_friendly_name(); | ||
ov::pass::Serialize serializer(name + ".xml", name + ".bin"); | ||
serializer.run_on_model(cnn_network); | ||
ngraph::plot_graph(cnn_network, name + "_executable" + ".dot"); | ||
} | ||
#endif | ||
#endif | ||
|
@@ -111,31 +110,6 @@ CreateOVModel(const ONNX_NAMESPACE::ModelProto& model_proto, const GlobalContext | |
} | ||
} | ||
|
||
InferenceEngine::Precision ConvertPrecisionONNXToOpenVINO(const ONNX_NAMESPACE::TypeProto& onnx_type) { | ||
ONNX_NAMESPACE::DataType type_string = ONNX_NAMESPACE::Utils::DataTypeUtils::ToType(onnx_type); | ||
if (*type_string == "float" || *type_string == "tensor(float)") { | ||
return InferenceEngine::Precision::FP32; | ||
} else if (*type_string == "float16" || *type_string == "tensor(float16)") { | ||
return InferenceEngine::Precision::FP16; | ||
} else if (*type_string == "int32" || *type_string == "tensor(int32)") { | ||
return InferenceEngine::Precision::I32; | ||
} else if (*type_string == "int16" || *type_string == "tensor(int16)") { | ||
return InferenceEngine::Precision::I16; | ||
} else if (*type_string == "int8" || *type_string == "tensor(int8)") { | ||
return InferenceEngine::Precision::I8; | ||
} else if (*type_string == "uint16" || *type_string == "tensor(uint16)") { | ||
return InferenceEngine::Precision::U16; | ||
} else if (*type_string == "uint8" || *type_string == "tensor(uint8)") { | ||
return InferenceEngine::Precision::U8; | ||
} else if (*type_string == "bool" || *type_string == "tensor(bool)") { | ||
return InferenceEngine::Precision::U8; | ||
} else if (*type_string == "int64" || *type_string == "tensor(int64)") { | ||
return InferenceEngine::Precision::I32; | ||
} else { | ||
throw std::string(log_tag + "Unsupported Data type"); | ||
} | ||
} | ||
|
||
Ort::UnownedValue | ||
GetOutputTensor(Ort::KernelContext& context, size_t batch_size, | ||
OVInferRequestPtr infer_request, | ||
|
@@ -166,7 +140,7 @@ Ort::UnownedValue | |
GetOutputTensor(Ort::KernelContext& context, | ||
std::string output_name, | ||
std::unordered_map<std::string, int> output_names, | ||
std::shared_ptr<ngraph::Node> node) { | ||
std::shared_ptr<ov::Node> node) { | ||
// Find position of '/' in the output_name | ||
int pos = output_name.find("/"); | ||
// Copy the substring from start to pos | ||
|
@@ -210,25 +184,25 @@ int GetFirstAvailableDevice(GlobalContext& global_context) { | |
return i; | ||
} | ||
|
||
void FillOutputsWithConstantData(std::shared_ptr<ngraph::Node> node, Ort::UnownedValue& out_tensor) { | ||
void FillOutputsWithConstantData(std::shared_ptr<ov::Node> node, Ort::UnownedValue& out_tensor) { | ||
switch (node->get_element_type()) { | ||
case ngraph::element::Type_t::f32: { | ||
case ov::element::Type_t::f32: { | ||
FillOutputHelper<float>(out_tensor, node); | ||
break; | ||
} | ||
case ngraph::element::Type_t::boolean: { | ||
case ov::element::Type_t::boolean: { | ||
FillOutputHelper<char>(out_tensor, node); | ||
break; | ||
} | ||
case ngraph::element::Type_t::i32: { | ||
case ov::element::Type_t::i32: { | ||
FillOutputHelper<int32_t>(out_tensor, node); | ||
break; | ||
} | ||
case ngraph::element::Type_t::i64: { | ||
case ov::element::Type_t::i64: { | ||
FillOutputHelper<int64_t>(out_tensor, node); | ||
break; | ||
} | ||
case ngraph::element::Type_t::f16: { | ||
case ov::element::Type_t::f16: { | ||
FillOutputHelper<float>(out_tensor, node); | ||
break; | ||
} | ||
|
@@ -237,14 +211,22 @@ void FillOutputsWithConstantData(std::shared_ptr<ngraph::Node> node, Ort::Unowne | |
} | ||
} | ||
|
||
#if defined(_MSC_VER) | ||
#pragma warning(disable : 4127) | ||
#endif | ||
|
||
template <typename T> | ||
void FillOutputHelper(Ort::UnownedValue& out_tensor, std::shared_ptr<ngraph::Node> node) { | ||
auto const_node = std::dynamic_pointer_cast<ngraph::op::Constant>(node); | ||
void FillOutputHelper(Ort::UnownedValue& out_tensor, std::shared_ptr<ov::Node> node) { | ||
auto const_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(node); | ||
auto res = const_node->cast_vector<T>(); | ||
T* tensor_data = out_tensor.GetTensorMutableData<T>(); | ||
std::copy(res.begin(), res.end(), tensor_data); | ||
} | ||
|
||
#if defined(_MSC_VER) | ||
#pragma warning(default : 4127) | ||
#endif | ||
|
||
void FillInputBlob(OVTensorPtr inputBlob, size_t batch_slice_idx, | ||
std::string input_name, Ort::KernelContext& context, | ||
const SubGraphContext& subgraph_context) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For NPU we still need dynamic backend so maybe this logic wont be suitable going forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is only skipping whether enable_dynamic_shapes runtime option is provided. According to this logic, if a model has dynamic shaped input it will be handled with dynamic backend.