1 //
2 //  GeometryComputerUtils.hpp
3 //  MNN
4 //
5 //  Created by MNN on 2020/05/11.
6 //  Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #ifndef GeometryComputerUtils_hpp
10 #define GeometryComputerUtils_hpp
11 #include "core/Schedule.hpp"
12 #include "geometry/GeometryComputer.hpp"
13 namespace MNN {
14 class GeometryComputerUtils {
15 public:
16     MNN_PUBLIC static void makeRaster(const CommandBuffer& srcBuffer, CommandBuffer& dstBuffer, GeometryComputer::Context& ctx);
17     static void addConvert(const CommandBuffer& srcBuffer, CommandBuffer& dstBuffer, GeometryComputer::Context& ctx);
18     static Command makeCommand(flatbuffers::FlatBufferBuilder& builder, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs);
19     static Command makeBinary(int type, Tensor* input0, Tensor* input1, Tensor* output);
20     static Command makeReduce(ReductionType type, Tensor* input0, Tensor* output);
21     static Command makeUnary(UnaryOpOperation type, Tensor* input0, Tensor* output);
22     static Command makeMatMul(Tensor* input0, Tensor* input1, Tensor* output, Tensor* Bias = nullptr,
23                               bool transposeA = false, bool transposeB = false);
24     static flatbuffers::Offset<Op> makePool(flatbuffers::FlatBufferBuilder& builder, std::pair<int, int> kernel, std::pair<int, int> stride, PoolType type, MNN::PoolPadType pad, std::pair<int, int> pads, bool isglobal, AvgPoolCountType countType = AvgPoolCountType_DEFAULT);
25 
26     // offset, dstSize, originSize must be 3-int
27     static void makeSliceRef(Tensor* dst, Tensor* src, const std::vector<int>& originSize,
28                              const std::vector<int>& offset, const std::vector<int>& dstSize);
29 
30     static Tensor::InsideDescribe::Region makeRawAddressRef(Tensor* src, int srcOffset, int size, int dstOffset = 0);
31     static void makeRawAddressRef(Tensor* dst, Tensor* src, int srcOffset, int size, int dstOffset = 0);
32     MNN_PUBLIC static void buildConstantTensors(std::vector<Schedule::PipelineInfo>& infos, std::shared_ptr<Backend> backupBackend,
33                                      bool netHold, std::vector<Tensor*>& constTensors,
34                                      std::vector<Tensor*>& midConstTensors);
35     MNN_PUBLIC static ErrorCode shapeComputeAndGeometryTransform(std::vector<Schedule::PipelineInfo>& infos, CommandBuffer& buffer,
36                                                       GeometryComputer::Context& geoContext,
37                                                       std::shared_ptr<Backend> backupBackend,
38                                                                  Runtime::CompilerType compileType);
39 };
40 }; // namespace MNN
41 
42 #endif
43