#include "ITensorBuilder.h"
#include "IStage.h"
#include "model/OperationVisitor.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
#include "cpp14/memory.h"
// TODO Remove dependencies for below header. Should include only interface.
#include "model/Operation.h"
#include "model/Model.h"
#include "graph/LowerInfoMap.h"
-#include "model/operation/Subgraph.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/Subgraph.h"
+#include "model/SubgraphContext.h"
namespace neurun
{
bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; }
std::shared_ptr<const model::Model> shareModel() { return _model; }
std::unique_ptr<graph::LowerInfoMap> releaseLowerInfo() { return std::move(_lower_info_map); }
- std::unique_ptr<model::operation::SubgraphContext> releaseSubgraphContext()
- {
- return std::move(_subg_ctx);
- }
+ std::unique_ptr<model::SubgraphContext> releaseSubgraphContext() { return std::move(_subg_ctx); }
private:
void initializeUseDef();
operand::LowerInfo *getLowerInfo(const model::OperandIndex &index);
void setLowerInfo(const model::OperandIndex &index,
std::unique_ptr<operand::LowerInfo> &&lower_info);
- model::operation::SubgraphContext &subg_ctx()
+ model::SubgraphContext &subg_ctx()
{
assert(_subg_ctx);
return *_subg_ctx;
}
- const model::operation::SubgraphContext *subg_ctx() const { return _subg_ctx.get(); }
+ const model::SubgraphContext *subg_ctx() const { return _subg_ctx.get(); }
private:
std::unique_ptr<compiler::BackendResolver> _backend_resolver;
std::unique_ptr<LowerInfoMap> _lower_info_map;
// Pass(for Perm) can accept only graph so that Graph has SubgraphContext as a member
- std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+ std::unique_ptr<model::SubgraphContext> _subg_ctx;
};
} // namespace graph
#define __NEURUN_MODEL_OPERATION_VISITOR_H__
#include "Operations.Include.h"
-#include "operation/Subgraph.h"
+#include "Subgraph.h"
namespace neurun
{
// This Subgraph node should be handled specially so that
// Op.lst doesn't have Subgraph
- virtual void visit(const operation::Subgraph &subgraph)
+ virtual void visit(const Subgraph &subgraph)
{
for (const auto &e : subgraph.operations())
{
* limitations under the License.
*/
-#ifndef __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
-#define __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
+#ifndef __NEURUN_MODEL_SUBGRAPH_H__
+#define __NEURUN_MODEL_SUBGRAPH_H__
#include <vector>
#include <string>
#include <memory>
-#include "model/Index.h"
-#include "model/Operation.h"
+#include "Index.h"
+#include "Operation.h"
namespace neurun
{
namespace model
{
-namespace operation
-{
// To support ValueSwappable, Element doesn't have members which are classes
// as value(or can have members which are classes as value and the classes
std::vector<Element> _operations;
};
-} // namespace operation
} // namespace model
} // namespace neurun
-#endif // __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
+#endif // __NEURUN_MODEL_SUBGRAPH_H__
* limitations under the License.
*/
-#ifndef __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
-#define __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
+#ifndef __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
+#define __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
#include <memory>
#include "Subgraph.h"
-#include "model/Index.h"
+#include "Index.h"
#include <unordered_map>
{
namespace model
{
-namespace operation
-{
class SubgraphContext
{
uint32_t _index_count;
};
-} // namespace operation
} // namespace model
} // namespace neurun
-#endif // __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
+#endif // __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
std::unordered_map<model::SubgraphIndex, std::unique_ptr<backend::IStage>> stages;
model.subg_ctx().iterate(
- [&](const model::SubgraphIndex &subg_index, const model::operation::Subgraph &subg) {
+ [&](const model::SubgraphIndex &subg_index, const model::Subgraph &subg) {
auto backend = model.getLowerInfo(subg_index)->backend();
// Generate Stage
#include "DotDumper.h"
#include "DotBuilder.h"
#include "DotSubgraphInfo.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
namespace neurun
{
const auto subg_ctx = _graph.subg_ctx();
if (subg_ctx)
{
- subg_ctx->iterate(
- [&](const model::SubgraphIndex &index, const model::operation::Subgraph &subgraph) {
- DotSubgraphInfo subgraph_info{index, subgraph};
- dot_builder.addSubgraph(subgraph_info);
- });
+ subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::Subgraph &subgraph) {
+ DotSubgraphInfo subgraph_info{index, subgraph};
+ dot_builder.addSubgraph(subgraph_info);
+ });
}
// Dump to file
namespace dot
{
-DotSubgraphInfo::DotSubgraphInfo(const model::SubgraphIndex &index,
- const model::operation::Subgraph &subgraph)
+DotSubgraphInfo::DotSubgraphInfo(const model::SubgraphIndex &index, const model::Subgraph &subgraph)
: _index{index}
{
for (const auto &element : subgraph.operations())
#include <unordered_set>
#include "model/Index.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
namespace neurun
{
class DotSubgraphInfo
{
public:
- DotSubgraphInfo(const model::SubgraphIndex &index, const model::operation::Subgraph &subgraph);
+ DotSubgraphInfo(const model::SubgraphIndex &index, const model::Subgraph &subgraph);
std::string index_str() const;
const std::unordered_set<model::OperationIndex> &operations() const { return _operations; }
}
DataflowExecutor::DataflowExecutor(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info,
CodeMap &&code_map)
assert(_subg_ctx);
// Create jobs
- _subg_ctx->iterate(
- [&](const model::SubgraphIndex &subg_index, const model::operation::Subgraph &subg) {
- VERBOSE(DataflowExecutor) << "Add a job #" << subg_index.value() << std::endl;
- _finished_jobs.emplace_back(nnfw::cpp14::make_unique<Job>(
- subg_index, _code_map.at(subg_index).get(),
- _lower_info->operation.at(subg_index)->backend(), subg.getInputs(), subg.getOutputs()));
- });
+ _subg_ctx->iterate([&](const model::SubgraphIndex &subg_index, const model::Subgraph &subg) {
+ VERBOSE(DataflowExecutor) << "Add a job #" << subg_index.value() << std::endl;
+ _finished_jobs.emplace_back(nnfw::cpp14::make_unique<Job>(
+ subg_index, _code_map.at(subg_index).get(),
+ _lower_info->operation.at(subg_index)->backend(), subg.getInputs(), subg.getOutputs()));
+ });
// Save operands that are initially ready
{
* @param code_map Compiled code map
*/
DataflowExecutor(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info, CodeMap &&code_map);
{
ExecutorBase::ExecutorBase(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info)
: _model{model}, _subg_ctx{std::move(subg_ctx)}, _operand_context{operand_context},
#include "model/OperandInfo.h"
#include "backend/Backend.h"
#include "compiler/OperandContext.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
namespace neurun
{
{
public:
ExecutorBase(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info);
protected:
std::shared_ptr<const model::Model> _model;
- std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+ std::unique_ptr<model::SubgraphContext> _subg_ctx;
std::shared_ptr<compiler::OperandContext> _operand_context;
std::unique_ptr<graph::LowerInfoMap> _lower_info;
std::vector<std::unique_ptr<ISource>> _sources;
* @param[in] plan Execution plan generated by compiled result
*/
LinearExecutor(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info,
std::unique_ptr<std::vector<linear::Element>> elements,
{
assert(_phase == Phase::MODEL);
- _subg_ctx = nnfw::cpp14::make_unique<model::operation::SubgraphContext>();
+ _subg_ctx = nnfw::cpp14::make_unique<model::SubgraphContext>();
// Lower
{
const auto &node_outputs = node.getOutputs();
// subg's operations are in order so that we just check the first and the last
- std::vector<model::operation::Element> subg_ops{subg.operations()[0]};
+ std::vector<model::Element> subg_ops{subg.operations()[0]};
if (subg.operations().size() > 1)
subg_ops.emplace_back(subg.operations()[subg.operations().size() - 1]);
return subg_index;
};
- model::operation::Subgraph *subg = nullptr;
+ model::Subgraph *subg = nullptr;
model::SubgraphIndex subg_index;
// Make subgraphs while checking whether a node can be merged into a subgraph.
subg = nullptr;
});
- _subg_ctx->iterate([&](const model::SubgraphIndex &, model::operation::Subgraph &subg) {
+ _subg_ctx->iterate([&](const model::SubgraphIndex &, model::Subgraph &subg) {
assert(subg.operations().size() > 0);
std::reverse(std::begin(subg.operations()), std::end(subg.operations()));
});
#ifndef __NEURUN_LINEAR_ELEMENT_H__
#define __NEURUN_LINEAR_ELEMENT_H__
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
#include "graph/LowerInfoMap.h"
namespace neurun
struct Element
{
- const model::operation::Subgraph *subgraph;
+ const model::Subgraph *subgraph;
const graph::operation::LowerInfo *lower_info;
- Element(const model::operation::Subgraph *subgraph, const graph::operation::LowerInfo *lower_info)
+ Element(const model::Subgraph *subgraph, const graph::operation::LowerInfo *lower_info)
: subgraph{subgraph}, lower_info{lower_info}
{
// DO NOTHING
{
Linear::Linear(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
std::unique_ptr<graph::LowerInfoMap> lower_info_map)
: _model(model), _subg_ctx{std::move(subg_ctx)}, _lower_info_map{std::move(lower_info_map)}
{
// [SUBG3]
// |
// [4]
- _subg_ctx->iterate([&](const model::SubgraphIndex &subg_idx, model::operation::Subgraph &subg) {
+ _subg_ctx->iterate([&](const model::SubgraphIndex &subg_idx, model::Subgraph &subg) {
for (auto input : subg.getInputs())
{
// only valid_inputs
});
std::unordered_map<model::SubgraphIndex, bool> visited;
- _subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::operation::Subgraph &) {
+ _subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::Subgraph &) {
visited[index] = false;
});
- std::function<void(const model::SubgraphIndex &, model::operation::Subgraph &)> dfs_recursive =
- [&](const model::SubgraphIndex &index, model::operation::Subgraph &subg) -> void {
+ std::function<void(const model::SubgraphIndex &, model::Subgraph &)> dfs_recursive =
+ [&](const model::SubgraphIndex &index, model::Subgraph &subg) -> void {
if (visited[index])
return;
visited[index] = true;
#include "Element.h"
#include "model/Model.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
#include "backend/ITensorBuilder.h"
#include "graph/LowerInfoMap.h"
{
public:
Linear(const std::shared_ptr<const model::Model> &model,
- std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+ std::unique_ptr<model::SubgraphContext> subg_ctx,
std::unique_ptr<graph::LowerInfoMap> lower_info_map);
public:
std::unique_ptr<graph::LowerInfoMap> releaseLowerInfo() { return std::move(_lower_info_map); }
graph::LowerInfoMap *getLowerInfo() { return _lower_info_map.get(); }
- std::unique_ptr<model::operation::SubgraphContext> releaseSubgraphContext()
- {
- return std::move(_subg_ctx);
- }
+ std::unique_ptr<model::SubgraphContext> releaseSubgraphContext() { return std::move(_subg_ctx); }
std::unique_ptr<std::vector<Element>> releaseElements() { return std::move(_elements); }
private:
std::shared_ptr<const model::Model> _model;
- std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+ std::unique_ptr<model::SubgraphContext> _subg_ctx;
std::unique_ptr<graph::LowerInfoMap> _lower_info_map;
std::unique_ptr<std::vector<Element>> _elements;
};
* limitations under the License.
*/
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
#include "model/OperationVisitor.h"
#include <sstream>
{
namespace model
{
-namespace operation
-{
Subgraph::Subgraph() : Operation{OperandConstraint::createAny()}
{
return ss.str();
}
-} // namespace operation
} // namespace model
} // neurun
* limitations under the License.
*/
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
#include "util/logging.h"
#include "cpp14/memory.h"
{
namespace model
{
-namespace operation
-{
SubgraphIndex SubgraphContext::generateIndex()
{
SubgraphIndex SubgraphContext::append(const OperationIndex &index, const Operation &node)
{
- std::unique_ptr<Subgraph> subg = nnfw::cpp14::make_unique<model::operation::Subgraph>();
+ std::unique_ptr<Subgraph> subg = nnfw::cpp14::make_unique<model::Subgraph>();
subg->appendOperation(index, node);
return append(std::move(subg));
}
void SubgraphContext::dump(const std::string &msg) const
{
VERBOSE(SubgraphContext) << "SubgraphContext(" << msg << ")" << std::endl;
- iterate([&](const SubgraphIndex &idx, const model::operation::Subgraph &subg) {
+ iterate([&](const SubgraphIndex &idx, const model::Subgraph &subg) {
VERBOSE(SubgraphContext) << idx.value() << "] " << subg.getStr() << std::endl;
});
}
-} // namespace operation
} // namespace model
} // namespace neurun