2020-11-05 16:41:56 +08:00
|
|
|
//
|
|
|
|
// StaticModule.hpp
|
|
|
|
// MNN
|
|
|
|
//
|
|
|
|
// Created by MNN on b'2020/09/10'.
|
|
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef StaticModule_hpp
|
|
|
|
#define StaticModule_hpp
|
|
|
|
|
2020-12-29 10:22:25 +08:00
|
|
|
#include <set>
|
2020-11-05 16:41:56 +08:00
|
|
|
#include <MNN/expr/Module.hpp>
|
|
|
|
namespace MNN {
|
2021-01-06 16:29:37 +08:00
|
|
|
class Session;
|
|
|
|
class Backend;
|
2020-11-05 16:41:56 +08:00
|
|
|
namespace Express {
|
2021-02-07 10:45:07 +08:00
|
|
|
struct BufferStorage;
|
2020-11-05 16:41:56 +08:00
|
|
|
class StaticModule : public Module {
|
|
|
|
public:
|
2021-02-07 10:45:07 +08:00
|
|
|
StaticModule(const void* buffer, size_t length, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, const Module::Config& config, bool copyOutput);
|
2020-11-05 16:41:56 +08:00
|
|
|
virtual ~ StaticModule();
|
|
|
|
virtual std::vector<Express::VARP> onForward(const std::vector<Express::VARP>& inputs) override;
|
2021-01-06 16:29:37 +08:00
|
|
|
void setReusedTensors(std::set<int> reused);
|
2020-11-05 16:41:56 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
StaticModule() = default;
|
|
|
|
|
|
|
|
Module* clone(CloneContext* ctx) const override;
|
2021-02-07 10:45:07 +08:00
|
|
|
void resizeTensor(Tensor* tensor, const std::vector<int>& dims);
|
2020-11-05 16:41:56 +08:00
|
|
|
|
2021-02-07 10:45:07 +08:00
|
|
|
struct Resource {
|
|
|
|
std::vector<std::string> mInputs;
|
|
|
|
std::vector<std::string> mOutputs;
|
|
|
|
bool mShapeFix;
|
|
|
|
int mOutputNumbers;
|
|
|
|
// First: outputIndex, Second: outputTensor Index
|
|
|
|
std::vector<int> mOutputFromTensor;
|
|
|
|
// First: outputIndex, Second: input var index
|
|
|
|
std::vector<std::pair<int, int>> mOutputFromInput;
|
|
|
|
// the outputs will be used as inputs
|
|
|
|
std::set<int> mReusedTensors;
|
|
|
|
std::shared_ptr<BufferStorage> mNetStorage;
|
|
|
|
bool mCopyOutput = false;
|
|
|
|
};
|
2021-01-06 16:29:37 +08:00
|
|
|
std::shared_ptr<Session> mSession;
|
2020-11-05 16:41:56 +08:00
|
|
|
std::vector<Tensor*> mInputTensors;
|
|
|
|
std::vector<Tensor*> mOutputTensors;
|
|
|
|
|
2021-01-06 16:29:37 +08:00
|
|
|
std::shared_ptr<Backend> mResourceBackend;
|
2021-02-07 10:45:07 +08:00
|
|
|
std::shared_ptr<Resource> mResource;
|
2020-11-05 16:41:56 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|