Blame view

3rdparty/opencv-4.5.4/modules/dnn/src/op_vkcom.hpp 2.24 KB
f4334277   Hu Chunming   提交3rdparty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  // This file is part of OpenCV project.
  // It is subject to the license terms in the LICENSE file found in the top-level directory
  // of this distribution and at http://opencv.org/license.html.
  //
  // Copyright (C) 2018, Intel Corporation, all rights reserved.
  // Third party copyrights are property of their respective owners.
  
  #ifndef OPENCV_DNN_OP_VKCOM_HPP
  #define OPENCV_DNN_OP_VKCOM_HPP
  
  #include <opencv2/dnn/shape_utils.hpp>
  #ifdef HAVE_VULKAN
  #include "vkcom/include/vkcom.hpp"
  #endif  // HAVE_VULKAN
  
  namespace cv
  {
  namespace dnn
  {
  #ifdef HAVE_VULKAN
      std::vector<vkcom::Tensor> VkComTensors(const std::vector<Ptr<BackendWrapper> >& ptrs);
  
      vkcom::Tensor VkComTensor(const Ptr<BackendWrapper>& ptr);
  
      // Data copied from/to Mat to/from Tensor. Change the shape of dst if
      // needed to make it the same shape as src
      void copyToTensor(vkcom::Tensor &dst, const Mat &src);
  
      void copyToMat(Mat &dst, const vkcom::Tensor &src);
  
      class VkComBackendNode : public BackendNode
      {
      public:
          VkComBackendNode(const std::vector<Ptr<BackendWrapper> >& inputsWrapper,
                           const std::shared_ptr<vkcom::OpBase> &op,
                           const std::vector<Ptr<BackendWrapper> >& blobsWrapper =
                           std::vector<Ptr<BackendWrapper> >());
  
          bool forward(std::vector<vkcom::Tensor>& outs);
  
      private:
          std::vector<vkcom::Tensor> ins;
          std::vector<vkcom::Tensor> blobs;
          std::vector<Ptr<BackendWrapper> > inputsWrapper_;
          std::shared_ptr<vkcom::OpBase> operation;
      };
  
      class VkComBackendWrapper : public BackendWrapper
      {
      public:
          VkComBackendWrapper(Mat& m);
          VkComBackendWrapper(const Ptr<BackendWrapper>& baseBuffer, Mat& m);
  
          virtual void copyToHost() CV_OVERRIDE;
          virtual void setHostDirty() CV_OVERRIDE;
          void setDeviceDirty();
          void copyToDevice();
          vkcom::Tensor getTensor();
  
      private:
          vkcom::Tensor tensor;
          Mat* host;
          bool hostDirty;
          bool deviceDirty;
      };
  #endif // HAVE_VULKAN
  
      void forwardVkCom(std::vector<Ptr<BackendWrapper> > &outputs, const Ptr<BackendNode>& node);
  
      bool haveVulkan();
  }  // namespace dnn
  }  // namespace cv
  
  #endif  // OPENCV_DNN_OP_VKCOM_HPP