MNN/source/core/Pipeline.hpp

74 lines
2.3 KiB
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// Pipeline.hpp
// MNN
//
// Created by MNN on 2019/01/14.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef Pipeline_hpp
#define Pipeline_hpp
#include "Schedule.hpp"
2020-11-05 16:41:56 +08:00
#include "core/Execution.hpp"
#include "geometry/GeometryComputer.hpp"
2019-04-17 10:49:11 +08:00
namespace MNN {
struct OperatorInfo::Info {
std::string name;
std::string type;
float flops = 0.0f;
};
class SizeComputer;
/** pipeline. one session may contains multiple pipeline, and one pipeline may contains more than one unit. */
class Pipeline : public NonCopyable {
public:
2020-11-05 16:41:56 +08:00
Pipeline(std::vector<Schedule::PipelineInfo>&& info, std::shared_ptr<Backend> major,
std::shared_ptr<Backend> backup, bool allocInput, bool useGeometry);
~Pipeline();
class UnitInfo : public OperatorInfo {
public:
UnitInfo() = default;
virtual ~UnitInfo() = default;
void setUp(const Command& cmd, int index);
};
2021-01-06 16:29:37 +08:00
void cloneExecution(const std::map<const Op*, std::shared_ptr<Execution>>& cache);
const std::map<const Op*, std::shared_ptr<Execution>>& getCache() {
return mOriginExecution;
}
2019-04-17 10:49:11 +08:00
public:
2020-11-05 16:41:56 +08:00
/** encode :
1. compute shape for every op's inputs and outputs;
2. geometry transform;
3. copy op, inputs and outputs tensor info to mBuffer
static_model: 3; dynamic_model: 1,2,3
*/
2021-04-08 15:34:23 +08:00
ErrorCode encode(bool isStatic = false, bool supportDebug = false);
2020-11-05 16:41:56 +08:00
/** allocMemory: create Execution and alloc memory for every op */
2021-04-08 15:34:23 +08:00
ErrorCode allocMemory();
2020-11-05 16:41:56 +08:00
/** execute this pipline */
2019-04-17 10:49:11 +08:00
ErrorCode execute();
ErrorCode executeCallBack(const TensorCallBackWithInfo& before, const TensorCallBackWithInfo& after);
2020-11-05 16:41:56 +08:00
std::vector<Schedule::PipelineInfo>& getPipelineInfo();
2019-04-17 10:49:11 +08:00
private:
2020-11-05 16:41:56 +08:00
std::shared_ptr<Backend> mBackend;
std::shared_ptr<Backend> mBackupBackend;
std::vector<std::shared_ptr<Execution>> mExecutions;
std::vector<UnitInfo> mDebugInfos;
CommandBuffer mBuffer;
std::vector<Schedule::PipelineInfo> mInfo;
std::vector<Tensor*> mMidConstTensors;
std::vector<Tensor*> mConstTensors;
bool mAllocInput;
bool mInit = false;
std::map<const Op*, std::shared_ptr<Execution>> mOriginExecution;
#ifndef MNN_BUILD_MINI
GeometryComputer::Context mContext;
bool mUseGeometry = true;
#endif
2019-04-17 10:49:11 +08:00
};
} // namespace MNN
#endif /* Pipeline_hpp */