// // Schedule.hpp // MNN // // Created by MNN on 2018/07/30. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef Schedule_hpp #define Schedule_hpp #include #include #include #include #include #include #include "core/Backend.hpp" #include "core/Command.hpp" namespace MNN { struct Op; struct Net; /** net scheduler */ class MNN_PUBLIC Schedule { public: enum Type { // Size can be compute separately SEPARATE = 0, // When size is fixed, the content is fixed CONSTANT = 1, // Size can't be compute separately NOT_SEPERATE }; class OpResizeCache { public: bool match(const std::vector& inputs, bool& compared); void insert(const std::vector& inputs); void close(bool pass = false); void open(); bool needComputeShape = true; bool needExecuteConst = false; void addContentIndex(int index); void copyImmutable(const OpResizeCache& cache); bool canCache() const { return mCanCache; } private: struct ShapeInfo { int order; std::vector dim; halide_type_t type; std::vector buffer; }; std::vector mInputInfos; bool mComputed = false; bool mCanCache = false; bool mPass = false; std::vector mNeedCompareContent; }; /** pipeline info */ struct OpCacheInfo { /** op */ const Op* op; /** input tensors */ std::vector inputs; /** output tensors */ std::vector outputs; /** schedule type*/ Schedule::Type type = Schedule::Type::SEPARATE; /**Command buffer for cache*/ CommandBuffer cacheBuffer; /**Command buffer for execute*/ CommandBuffer executeBuffer; std::map> executionCache; OpResizeCache computeCache; /** For CONSTANT info, can release indexes after resize*/ std::vector releaseAbleInputs; }; // Backend, Tensor, shape-dirty, content-dirty typedef std::tuple, bool, bool> TENSORCACHE; struct BackendCache { Backend::Info info; BackendConfig config; std::pair, std::shared_ptr> cache; bool needComputeShape = true; bool needComputeGeometry = true; bool reportError = true; bool inputBackendChange = false; std::map inputTensorCopyCache; }; typedef std::pair> PipelineInfo; /** schedule info */ struct ScheduleInfo { /** pipelines with backend info */ std::vector pipelineInfo; /** input tensors map */ std::map inputTensors; /** output tensors map */ std::map outputTensor; /** all tensors */ std::vector> allTensors; /** input valid for resize*/ bool validForResize; /** Default Backend for alloc const*/ std::shared_ptr defaultBackend; /** Replace Backend for alloc const*/ std::shared_ptr constReplaceBackend; /** size need input's content*/ bool needInputContentForShape = false; /** external weight*/ std::string externalWeightPath; }; /** * @breif schedule net ops to pipeline with configuration. * @param net given net. * @param config given configuration. * @return schedule info. */ static bool schedule(ScheduleInfo& result, const Net* net, const std::vector& config, const RuntimeInfo& runtimeInfo); static MNNForwardType getAppropriateType(const ScheduleConfig& config); }; } // namespace MNN #endif /* Schedule_hpp */