Skip to content

Commit

Permalink
[IE Myriad] ie::ICore pointer passed into FrontEnd from plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-kud committed Jul 16, 2020
1 parent 5b2ec78 commit 7061559
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <tuple>
#include <set>

#include <ie_icore.hpp>
#include <cpp/ie_cnn_network.h>
#include <details/caseless.hpp>

Expand All @@ -30,7 +31,7 @@ class FrontEnd final {
public:
using Ptr = std::shared_ptr<FrontEnd>;

explicit FrontEnd(StageBuilder::Ptr stageBuilder);
explicit FrontEnd(StageBuilder::Ptr stageBuilder, const ie::ICore* core);

ModelPtr buildInitialModel(ie::ICNNNetwork& network);

Expand Down Expand Up @@ -202,6 +203,7 @@ class FrontEnd final {

private:
StageBuilder::Ptr _stageBuilder;
const ie::ICore* _core;

IeParsedNetwork _ieParsedNetwork;
std::unordered_set<ie::DataPtr> _unbatchedOutputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <set>
#include <utility>

#include <ie_icore.hpp>
#include <ie_icnn_network.hpp>
#include <details/caseless.hpp>

Expand Down Expand Up @@ -163,11 +164,13 @@ CompiledGraph::Ptr compileNetwork(
ie::ICNNNetwork& network,
Platform platform,
const CompilationConfig& config,
const Logger::Ptr& log);
const Logger::Ptr& log,
const ie::ICore* core);

CompiledGraph::Ptr compileSubNetwork(
ie::ICNNNetwork& network,
const CompilationConfig& subConfig);
const CompilationConfig& subConfig,
const ie::ICore* core);

//
// getSupportedLayers
Expand All @@ -177,7 +180,8 @@ std::set<std::string> getSupportedLayers(
const ie::ICNNNetwork& network,
Platform platform,
const CompilationConfig& config,
const Logger::Ptr& log);
const Logger::Ptr& log,
const ie::ICore* core);

//
// Blob version and checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ namespace vpu {
[this](const Model& model, const ie::CNNLayerPtr& layer, const DataVector& inputs, const DataVector& outputs) \
{ functor_name(model, layer, inputs, outputs); }

FrontEnd::FrontEnd(StageBuilder::Ptr stageBuilder)
: _stageBuilder(std::move(stageBuilder))
, parsers{{
FrontEnd::FrontEnd(StageBuilder::Ptr stageBuilder, const ie::ICore* core)
: _stageBuilder(std::move(stageBuilder)),
_core(core),
parsers{{
{"Convolution", LAYER_PARSER(parseConvolution)},
{"Pooling", LAYER_PARSER(parsePooling)},
{"ReLU", LAYER_PARSER(parseReLU)},
Expand Down Expand Up @@ -117,7 +118,9 @@ FrontEnd::FrontEnd(StageBuilder::Ptr stageBuilder)
{"StaticShapeBroadcast", LAYER_PARSER(parseBroadcast)},
{"StaticShapeNonMaxSuppression", LAYER_PARSER(parseStaticShapeNMS)},
{"StaticShapeReshape", LAYER_PARSER(parseReshape)},
}} {}
}} {
VPU_THROW_UNLESS(_core != nullptr, "Argument core is null");
}

ModelPtr FrontEnd::buildInitialModel(ie::ICNNNetwork& network) {
VPU_PROFILE(buildInitialModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ void CompileEnv::free() {

namespace {

CompiledGraph::Ptr compileImpl(ie::ICNNNetwork& network) {
CompiledGraph::Ptr compileImpl(ie::ICNNNetwork& network,
const ie::ICore* core) {
const auto& env = CompileEnv::get();

env.log->debug("Compile network [%s]", network.getName());
VPU_LOGGER_SECTION(env.log);

auto stageBuilder = std::make_shared<StageBuilder>();
auto frontEnd = std::make_shared<FrontEnd>(stageBuilder);
auto frontEnd = std::make_shared<FrontEnd>(stageBuilder, core);
auto backEnd = std::make_shared<BackEnd>();
auto passManager = std::make_shared<PassManager>(stageBuilder, backEnd);

Expand Down Expand Up @@ -190,15 +191,16 @@ CompiledGraph::Ptr compileNetwork(
ie::ICNNNetwork& network,
Platform platform,
const CompilationConfig& config,
const Logger::Ptr& log) {
const Logger::Ptr& log,
const ie::ICore* core) {
CompileEnv::init(platform, config, log);
AutoScope autoDeinit([] {
CompileEnv::free();
});

VPU_PROFILE(compileNetwork);

return compileImpl(network);
return compileImpl(network, core);
}

CompiledGraph::Ptr compileModel(
Expand All @@ -218,7 +220,8 @@ CompiledGraph::Ptr compileModel(

CompiledGraph::Ptr compileSubNetwork(
ie::ICNNNetwork& network,
const CompilationConfig& subConfig) {
const CompilationConfig& subConfig,
const ie::ICore* core) {
VPU_PROFILE(compileSubNetwork);

const auto& env = CompileEnv::get();
Expand All @@ -230,7 +233,7 @@ CompiledGraph::Ptr compileSubNetwork(

CompileEnv::updateConfig(subConfig);

return compileImpl(network);
return compileImpl(network, core);
}

//
Expand All @@ -241,7 +244,8 @@ std::set<std::string> getSupportedLayers(
const ie::ICNNNetwork& network,
Platform platform,
const CompilationConfig& config,
const Logger::Ptr& log) {
const Logger::Ptr& log,
const ie::ICore* core) {
CompileEnv::init(platform, config, log);
AutoScope autoDeinit([] {
CompileEnv::free();
Expand All @@ -250,7 +254,7 @@ std::set<std::string> getSupportedLayers(
VPU_PROFILE(getSupportedLayers);

auto stageBuilder = std::make_shared<StageBuilder>();
auto frontEnd = std::make_shared<FrontEnd>(stageBuilder);
auto frontEnd = std::make_shared<FrontEnd>(stageBuilder, core);

auto clonedNetworkImpl = ie::cloneNet(network);

Expand Down
20 changes: 10 additions & 10 deletions inference-engine/src/vpu/graph_transformer/src/stages/mtcnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ std::pair<int, int> getResolution(const std::string& str) {

ie::CNNNetwork loadSubNetwork(
const std::string& fileName,
const std::pair<int, int>& imgSize, int* zdir_batchsize = nullptr) {
const std::pair<int, int>& imgSize,
const ie::ICore* core,
int* zdir_batchsize = nullptr) {
//
// Load network
//

// ticket 30632 : replace with ICore interface
InferenceEngine::Core reader;
auto network = reader.ReadNetwork(fileName);
auto network = core->ReadNetwork(fileName, std::string());

//
// Set precision of input/output
Expand Down Expand Up @@ -206,25 +206,25 @@ void FrontEnd::parseMTCNN(const Model& model, const ie::CNNLayerPtr& layer, cons

// Convert p-nets
for (const auto& p_net_input : pyramid) {
auto pNet = loadSubNetwork(pnet_ir_name, p_net_input);
auto res = compileSubNetwork(pNet, env.config);
auto pNet = loadSubNetwork(pnet_ir_name, p_net_input, _core);
auto res = compileSubNetwork(pNet, env.config, _core);
mergedBlobSize += res->blob.size();
compiledSubNetworks.emplace_back(std::move(res));
}

int stage2_zdir_batchsize = 1;
// Convert r-net
{
auto rNet = loadSubNetwork(rnet_ir_name, r_net_input, &stage2_zdir_batchsize);
auto res = compileSubNetwork(rNet, env.config);
auto rNet = loadSubNetwork(rnet_ir_name, r_net_input, _core, &stage2_zdir_batchsize);
auto res = compileSubNetwork(rNet, env.config, _core);
mergedBlobSize += res->blob.size();
compiledSubNetworks.emplace_back(std::move(res));
}

// Convert o-net
{
auto oNet = loadSubNetwork(onet_ir_name, o_net_input);
auto res = compileSubNetwork(oNet, env.config);
auto oNet = loadSubNetwork(onet_ir_name, o_net_input, _core);
auto res = compileSubNetwork(oNet, env.config, _core);
mergedBlobSize += res->blob.size();
compiledSubNetworks.emplace_back(std::move(res));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ namespace MyriadPlugin {
ExecutableNetwork::ExecutableNetwork(
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr>& devicePool,
const MyriadConfig& config) :
_config(config) {
const MyriadConfig& config,
const ie::ICore* core) :
_config(config),
_core(core) {
VPU_PROFILE(ExecutableNetwork);

_log = std::make_shared<Logger>(
Expand Down Expand Up @@ -53,8 +55,9 @@ ExecutableNetwork::ExecutableNetwork(
ICNNNetwork& network,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr>& devicePool,
const MyriadConfig& config) :
ExecutableNetwork(std::move(mvnc), devicePool, config) {
const MyriadConfig& config,
const ie::ICore* core) :
ExecutableNetwork(std::move(mvnc), devicePool, config, core) {
VPU_PROFILE(ExecutableNetwork);

const auto compilerLog = std::make_shared<Logger>(
Expand All @@ -68,7 +71,8 @@ ExecutableNetwork::ExecutableNetwork(
network,
static_cast<Platform>(_device->_platform),
_config.compileConfig(),
compilerLog);
compilerLog,
core);

_actualNumExecutors = compiledGraph->numExecutors;
_graphBlob = std::move(compiledGraph->blob);
Expand Down Expand Up @@ -146,8 +150,9 @@ void ExecutableNetwork::Import(std::istream& strm,
ExecutableNetwork::ExecutableNetwork(std::istream& strm,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr> &devicePool,
const MyriadConfig& config) :
ExecutableNetwork(std::move(mvnc), devicePool, config) {
const MyriadConfig& config,
const ie::ICore* core) :
ExecutableNetwork(std::move(mvnc), devicePool, config, core) {
VPU_PROFILE(ExecutableNetwork);
Import(strm, devicePool, config);
}
Expand All @@ -156,8 +161,9 @@ ExecutableNetwork::ExecutableNetwork(
const std::string& blobFilename,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr>& devicePool,
const MyriadConfig& config) :
ExecutableNetwork(std::move(mvnc), devicePool, config) {
const MyriadConfig& config,
const ie::ICore* core) :
ExecutableNetwork(std::move(mvnc), devicePool, config, core) {
VPU_PROFILE(ExecutableNetwork);
std::ifstream blobFile{blobFilename, std::ios::binary};
Import(blobFile, devicePool, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ class ExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSafeDef
explicit ExecutableNetwork(InferenceEngine::ICNNNetwork &network,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr> &devicePool,
const MyriadConfig& config);
const MyriadConfig& config,
const ie::ICore* core);

explicit ExecutableNetwork(std::istream& strm,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr> &devicePool,
const MyriadConfig& config);
const MyriadConfig& config,
const ie::ICore* core);

explicit ExecutableNetwork(const std::string &blobFilename,
std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr> &devicePool,
const MyriadConfig& config);
const MyriadConfig& config,
const ie::ICore* core);


virtual ~ExecutableNetwork() {
Expand Down Expand Up @@ -120,6 +123,7 @@ class ExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSafeDef
DevicePtr _device;
GraphMetaInfo _graphMetaData;
MyriadConfig _config;
const ie::ICore* _core;
int _actualNumExecutors = 0;
std::vector<std::string> _supportedMetrics;

Expand All @@ -131,7 +135,8 @@ class ExecutableNetwork : public InferenceEngine::ExecutableNetworkThreadSafeDef

ExecutableNetwork(std::shared_ptr<IMvnc> mvnc,
std::vector<DevicePtr> &devicePool,
const MyriadConfig& config);
const MyriadConfig& config,
const ie::ICore* core);

InferenceEngine::ITaskExecutor::Ptr getNextTaskExecutor() {
std::string id = _taskExecutorGetResultIds.front();
Expand Down
7 changes: 4 additions & 3 deletions inference-engine/src/vpu/myriad_plugin/myriad_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ExecutableNetworkInternal::Ptr Engine::LoadExeNetworkImpl(
vpu::EliminateShapeOfAfterDSR().run_on_function(function);
}

return std::make_shared<ExecutableNetwork>(*clonedNetwork, _mvnc, _devicePool, parsedConfigCopy);
return std::make_shared<ExecutableNetwork>(*clonedNetwork, _mvnc, _devicePool, parsedConfigCopy, GetCore());
}

void Engine::SetConfig(const std::map<std::string, std::string> &config) {
Expand Down Expand Up @@ -96,7 +96,8 @@ void Engine::QueryNetwork(
network,
static_cast<Platform>(parsedConfigCopy.platform()),
parsedConfigCopy.compileConfig(),
log);
log,
GetCore());

for (const auto& layerName : layerNames) {
res.supportedLayersMap.insert({ layerName, GetName() });
Expand Down Expand Up @@ -134,7 +135,7 @@ InferenceEngine::ExecutableNetwork Engine::ImportNetwork(

const auto executableNetwork =
std::make_shared<ExecutableNetwork>(
model, _mvnc, _devicePool, parsedConfigCopy);
model, _mvnc, _devicePool, parsedConfigCopy, GetCore());

return InferenceEngine::ExecutableNetwork{IExecutableNetwork::Ptr(
new ExecutableNetworkBase<ExecutableNetworkInternal>(executableNetwork),
Expand Down

0 comments on commit 7061559

Please sign in to comment.