Skip to content

Commit

Permalink
openVINO as out-tree EP works on Detection model
Browse files Browse the repository at this point in the history
  • Loading branch information
jslhcl committed Dec 19, 2023
1 parent f8d6a70 commit 970a3f2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/onnxruntime/interface/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class GraphViewRef {
#endif

virtual std::string_view SerializeModelProtoToString() const = 0;
virtual std::string SerializeModelProtoToString2() const = 0;

virtual ModelProtoPtr SerializeModelProto() const = 0;

Expand Down
38 changes: 32 additions & 6 deletions onnxruntime/core/graph/graph_view_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ std::string_view ApiGraphView::SerializeModelProtoToString() const {
return ret;
}

interface::ModelProtoPtr ApiGraphView::SerializeModelProto() const {
std::string ApiGraphView::SerializeModelProtoToString2() const {
GraphViewer graph_viewer(graph_, isg_);
Model model(graph_viewer.Name(), true, ModelMetaData(), PathString(),
#if defined(ORT_MINIMAL_BUILD)
Expand All @@ -366,12 +366,38 @@ interface::ModelProtoPtr ApiGraphView::SerializeModelProto() const {
);
onnx::ModelProto model_proto = model.ToProto();
GraphViewerToProto(graph_viewer, *model_proto.mutable_graph(), true, true);
std::string model_str;
model_proto.SerializeToString(&model_str);
std::string ret;
model_proto.SerializeToString(&ret);
return ret;
}

interface::ModelProtoPtr ApiGraphView::SerializeModelProto() const {
// GraphViewer graph_viewer(graph_, isg_);
// Model model(graph_viewer.Name(), true, ModelMetaData(), PathString(),
//#if defined(ORT_MINIMAL_BUILD)
// IOnnxRuntimeOpSchemaRegistryList(),
//#else
// IOnnxRuntimeOpSchemaRegistryList({graph_viewer.GetSchemaRegistry()}),
//#endif
// graph_viewer.DomainToVersionMap(), std::vector<onnx::FunctionProto>(), graph_viewer.GetGraph().GetLogger()
// );
// onnx::ModelProto model_proto = model.ToProto();
// GraphViewerToProto(graph_viewer, *model_proto.mutable_graph(), true, true);
// std::string model_str;
// model_proto.SerializeToString(&model_str);
// interface::ModelProtoPtr ret;
// ret.p = model_str.data();
// ret.len = model_str.length();
// ret.version = 0;
interface::ModelProtoPtr ret;
ret.p = model_str.data();
ret.len = model_str.length();
ret.version = 0;
ret.len = ret.version = 5;
char *p = new char[ret.len];
p[0] = 'a';
p[1] = 'b';
p[2] = 'c';
p[3] = 0;
p[4] = 'd';
ret.p = p;
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/graph/graph_view_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ApiGraphView : virtual public interface::GraphViewRef {
onnx::ModelProto ToModelProto() const override;
#endif
std::string_view SerializeModelProtoToString() const override;
std::string SerializeModelProtoToString2() const override;
interface::ModelProtoPtr SerializeModelProto() const override;
private:
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(ApiGraphView);
Expand Down
5 changes: 3 additions & 2 deletions samples/openvino/backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ bool BackendManager::ModelHasSymbolicInputDims(const onnxruntime::interface::Gra
std::unique_ptr<ONNX_NAMESPACE::ModelProto>
BackendManager::GetModelProtoFromFusedNode(const onnxruntime::interface::NodeViewRef& fused_node,
const onnxruntime::interface::GraphViewRef& subgraph) const {
onnxruntime::interface::ModelProtoPtr model_proto = subgraph.SerializeModelProto();
//onnxruntime::interface::ModelProtoPtr model_proto = subgraph.SerializeModelProto();
// TODO: check version
std::string model_proto_str(model_proto.p, model_proto.len);
//std::string model_proto_str(model_proto.p, model_proto.len);
std::string model_proto_str = subgraph.SerializeModelProtoToString2();
std::unique_ptr<ONNX_NAMESPACE::ModelProto> ret = std::make_unique<ONNX_NAMESPACE::ModelProto>();
ret->ParseFromString(model_proto_str);
#ifndef NDEBUG
Expand Down
3 changes: 2 additions & 1 deletion samples/openvino/openvino_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ common::Status OpenVINOExecutionProvider::Compile(
*state = static_cast<FunctionState>(p);
return 0;
};
compute_info.compute_func = [](FunctionState state, const OrtApi* /* api */, OrtKernelContext* context) {
compute_info.compute_func = [](FunctionState state, const OrtApi* api, OrtKernelContext* context) {
Ort::InitApi(api);
auto function_state = static_cast<OpenVINOEPFunctionState*>(state);
try {
function_state->backend_manager->Compute(context);
Expand Down
12 changes: 8 additions & 4 deletions samples/openvino/ov_versions/capability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ std::vector<std::unique_ptr<interface::SubGraphDef>> GetCapability::Execute() {
std::vector<std::string> inputs;
std::vector<std::string> outputs;
// Fill inputs with names
std::for_each(graph_viewer_.GetInputs().begin(), graph_viewer_.GetInputs().end(),
[&inputs](std::string_view node_arg) { inputs.push_back(std::string(node_arg)); });
//std::for_each(graph_viewer_.GetInputs().begin(), graph_viewer_.GetInputs().end(),
// [&inputs](std::string_view node_arg) { inputs.push_back(std::string(node_arg)); });
std::vector<std::string_view> graph_inputs = graph_viewer_.GetInputs();
for (size_t i = 0; i < graph_inputs.size(); i++) inputs.push_back(std::string(graph_inputs[i]));

/* In scenarios, when there are no inputs or all inputs being initializers,
ConstantFolding optimization in onnxruntime pre-computes the value.*/
Expand Down Expand Up @@ -99,8 +101,10 @@ std::vector<std::unique_ptr<interface::SubGraphDef>> GetCapability::Execute() {
[&inputs](const std::string& initializer) { inputs.push_back(initializer); });

// Fill outputs with names
std::for_each(graph_viewer_.GetOutputs().begin(), graph_viewer_.GetOutputs().end(),
[&outputs](std::string_view node_arg) { outputs.push_back(std::string(node_arg)); });
// std::for_each(graph_viewer_.GetOutputs().begin(), graph_viewer_.GetOutputs().end(),
// [&outputs](std::string_view node_arg) { outputs.push_back(std::string(node_arg)); });
std::vector<std::string_view> graph_outputs = graph_viewer_.GetOutputs();
for (size_t i = 0; i < graph_outputs.size(); i++) outputs.push_back(std::string(graph_outputs[i]));

// Create and add this graph to result.
AppendClusterToSubGraph(graph_viewer_.GetNodesInTopologicalOrder(), inputs, outputs, result);
Expand Down

0 comments on commit 970a3f2

Please sign in to comment.