-
Notifications
You must be signed in to change notification settings - Fork 64
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
Cavusmustafa/modular backend review v6 #762
Open
cavusmustafa
wants to merge
3
commits into
master
Choose a base branch
from
cavusmustafa/modular_backend_review_v6
base: master
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 2 commits
Commits
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright 2017-2020 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
#include "ngraph_bridge/ie_backend_engine.h" | ||
#include <iostream> | ||
#include "ngraph_bridge/ie_utils.h" | ||
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. General guideline followed in the bridge |
||
|
||
namespace tensorflow { | ||
namespace ngraph_bridge { | ||
|
||
IE_Backend_Engine::IE_Backend_Engine(InferenceEngine::CNNNetwork ie_network, | ||
std::string device) | ||
: m_network(ie_network), | ||
m_func(ie_network.getFunction()), | ||
m_device(device), | ||
m_multi_req_execution(false), | ||
m_network_ready(false) { | ||
if (std::getenv("NGRAPH_TF_DUMP_GRAPHS")) { | ||
auto& name = m_network.getName(); | ||
m_network.serialize(name + ".xml", name + ".bin"); | ||
} | ||
} | ||
|
||
IE_Backend_Engine::~IE_Backend_Engine() {} | ||
|
||
void IE_Backend_Engine::load_network() { | ||
if (m_network_ready) return; | ||
|
||
std::map<std::string, std::string> config; | ||
|
||
if (m_device == "MYRIAD") { | ||
// Set MYRIAD configurations | ||
if (IE_Utils::VPUConfigEnabled()) { | ||
config["MYRIAD_DETECT_NETWORK_BATCH"] = "NO"; | ||
} | ||
|
||
if (IE_Utils::VPUFastCompileEnabled()) { | ||
config["MYRIAD_HW_INJECT_STAGES"] = "NO"; | ||
config["MYRIAD_COPY_OPTIMIZATION"] = "NO"; | ||
} | ||
} | ||
|
||
InferenceEngine::Core ie; | ||
// Load network to the plugin (m_device) | ||
m_exe_network = ie.LoadNetwork(m_network, m_device, config); | ||
m_network_ready = true; | ||
} | ||
|
||
void IE_Backend_Engine::start_async_inference(const int req_id) { | ||
// Start Async inference | ||
try { | ||
m_infer_reqs[req_id].StartAsync(); | ||
} catch (InferenceEngine::details::InferenceEngineException e) { | ||
THROW_IE_EXCEPTION << "Couldn't start Inference: "; | ||
} catch (...) { | ||
THROW_IE_EXCEPTION << "Couldn't start Inference: "; | ||
} | ||
} | ||
|
||
void IE_Backend_Engine::complete_async_inference(const int req_id) { | ||
// Wait for Async inference completion | ||
try { | ||
m_infer_reqs[req_id].Wait( | ||
InferenceEngine::IInferRequest::WaitMode::RESULT_READY); | ||
} catch (InferenceEngine::details::InferenceEngineException e) { | ||
THROW_IE_EXCEPTION << " Exception with completing Inference: "; | ||
} catch (...) { | ||
THROW_IE_EXCEPTION << " Exception with completing Inference: "; | ||
} | ||
} | ||
|
||
size_t IE_Backend_Engine::getOutputBatchSize(size_t inputBatchSize) const { | ||
return m_network.getBatchSize() * | ||
IE_Utils::GetNumRequests(inputBatchSize, m_device); | ||
} | ||
|
||
// Enables multi request execution if the execution engine supprts | ||
void IE_Backend_Engine::enable_multi_req_execution() { | ||
m_multi_req_execution = true; | ||
} | ||
// Disables multi request execution | ||
void IE_Backend_Engine::disable_multi_req_execution() { | ||
m_multi_req_execution = false; | ||
} | ||
|
||
std::shared_ptr<ngraph::Function> IE_Backend_Engine::get_func() { | ||
return m_func; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright 2017-2020 Intel Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
#ifndef IE_BACKEND_ENGINE_H_ | ||
#define IE_BACKEND_ENGINE_H_ | ||
|
||
#include <ie_core.hpp> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
#include "ngraph_bridge/ie_tensor.h" | ||
|
||
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. Same as above |
||
namespace tensorflow { | ||
namespace ngraph_bridge { | ||
|
||
class IE_Backend_Engine { | ||
public: | ||
IE_Backend_Engine(InferenceEngine::CNNNetwork ie_network, std::string device); | ||
~IE_Backend_Engine(); | ||
|
||
// Executes the inference | ||
virtual void infer(std::vector<std::shared_ptr<IETensor>>& inputs, | ||
std::vector<std::string>& input_names, | ||
std::vector<std::shared_ptr<IETensor>>& outputs, | ||
std::vector<std::string>& output_names, | ||
std::vector<std::shared_ptr<IETensor>>& hoisted_params, | ||
std::vector<std::string>& param_names) = 0; | ||
|
||
// Returns output batch size based on the input batch size and the device | ||
// FIXME: This may not be needed | ||
virtual size_t getOutputBatchSize(size_t inputBatchSize) const; | ||
|
||
// Enables multi request execution if the execution engine supprts | ||
void enable_multi_req_execution(); | ||
// Disables multi request execution | ||
void disable_multi_req_execution(); | ||
|
||
// Returns the NGraph Function from the CNNNetwork | ||
std::shared_ptr<ngraph::Function> get_func(); | ||
|
||
virtual const std::vector<size_t> get_output_shape(const int i) = 0; | ||
|
||
protected: | ||
InferenceEngine::CNNNetwork m_network; | ||
std::shared_ptr<ngraph::Function> m_func; | ||
std::vector<InferenceEngine::InferRequest> m_infer_reqs; | ||
std::string m_device; | ||
bool m_multi_req_execution; | ||
InferenceEngine::ExecutableNetwork m_exe_network; | ||
bool m_network_ready; | ||
|
||
virtual void start_async_inference(const int req_id); | ||
virtual void complete_async_inference(const int req_id); | ||
virtual void load_network(); | ||
}; | ||
} | ||
} | ||
|
||
#endif // IE_BACKEND_ENGINE_H_ |
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.
Is this needed, isn't it disabled by default?
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.
It's added in case batching might be disabled during consecutive executions. But we don't have advanced checks for now and there is no scenario to disable batching if it's already enabled. I updated it accordingly.