1 //
2 //  GLConvolution.h
3 //  MNN
4 //
5 //  Created by MNN on 2019/01/31.
6 //  Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #ifndef MNNDEMO_GLCONVOLUTION_H
10 #define MNNDEMO_GLCONVOLUTION_H
11 
12 #include <functional>
13 #include "core/Execution.hpp"
14 #include "backend/opengl/GLProgram.hpp"
15 #include "backend/opengl/GLSSBOBuffer.hpp"
16 #include "backend/opengl/GLTexture.hpp"
17 #include "backend/opengl/GLBackend.hpp"
18 #include "MNN_generated.h"
19 
20 namespace MNN {
21 namespace OpenGL {
22 class GPUConvolution : public Execution {
23 public:
24     GPUConvolution(const Op *convOp, Backend *b);
25     virtual ~GPUConvolution();
26 
27     virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
28 
29 protected:
30     const Convolution2DCommon *mCommon;
31 
32     // In execute, use pad from mPadX and mPadY, don't use mCommon's pad
33     mutable int mPadX;
34     mutable int mPadY;
35 
36     int mInputDepth;
37 };
38 
39 class GLConvolution : public GPUConvolution {
40 public:
41     GLConvolution(const std::vector<Tensor *> &inputs, const Op *convOp, Backend *b);
42     virtual ~GLConvolution();
43     virtual ErrorCode onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
44     virtual ErrorCode onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) override;
45 
46 private:
47     std::shared_ptr<GLTexture> mKernelTexture;
48     std::shared_ptr<GLSSBOBuffer> mBiasBuffer;
49     std::shared_ptr<GLProgram> mProgram;
50     bool mIs1x1 = false;
51     int mLocalSize[3];
52     GLBackend* mBackend;
53     int mKx, mKy, mSx, mSy, mDx, mDy;
54 };
55 } // namespace OpenGL
56 } // namespace MNN
57 
58 #endif // MNNDEMO_GLCONVOLUTION_H
59