Elffuss BraidHub

kikocis/ncnn public

a0f3eab9f8a0 · 4.3 KiBRawPermalink
1/* Tencent is pleased to support the open source community by making ncnn available.
2 *
3 * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
4 *
5 * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 * in compliance with the License. You may obtain a copy of the License at
7 *
8 * https://opensource.org/licenses/BSD-3-Clause
9 *
10 * Unless required by applicable law or agreed to in writing, software distributed
11 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 * specific language governing permissions and limitations under the License.
14 */
15
16#ifndef PYBIND11_NCNN_LAYER_H
17#define PYBIND11_NCNN_LAYER_H
18
19#include <layer.h>
20#include "pybind11_bind.h"
21
22class PyLayer : public ncnn::Layer
23{
24public:
25 virtual int load_param(const ncnn::ParamDict& pd)
26 {
27 PYBIND11_OVERRIDE_REFERENCE(
28 int,
29 ncnn::Layer,
30 load_param,
31 pd);
32 }
33
34 virtual int load_model(const ncnn::ModelBin& mb)
35 {
36 PYBIND11_OVERRIDE_REFERENCE(
37 int,
38 ncnn::Layer,
39 load_model,
40 mb);
41 }
42
43 virtual int create_pipeline(const ncnn::Option& opt)
44 {
45 PYBIND11_OVERRIDE_REFERENCE(
46 int,
47 ncnn::Layer,
48 create_pipeline,
49 opt);
50 }
51
52 virtual int destroy_pipeline(const ncnn::Option& opt)
53 {
54 PYBIND11_OVERRIDE_REFERENCE(
55 int,
56 ncnn::Layer,
57 destroy_pipeline,
58 opt);
59 }
60
61public:
62 virtual int forward(const std::vector<ncnn::Mat>& bottom_blobs, std::vector<ncnn::Mat>& top_blobs, const ncnn::Option& opt) const
63 {
64 PYBIND11_OVERRIDE_REFERENCE(
65 int,
66 ncnn::Layer,
67 forward,
68 bottom_blobs,
69 top_blobs,
70 opt);
71 }
72 virtual int forward(const ncnn::Mat& bottom_blob, ncnn::Mat& top_blob, const ncnn::Option& opt) const
73 {
74 PYBIND11_OVERRIDE_REFERENCE(
75 int,
76 ncnn::Layer,
77 forward,
78 bottom_blob,
79 top_blob,
80 opt);
81 }
82
83 virtual int forward_inplace(std::vector<ncnn::Mat>& bottom_top_blobs, const ncnn::Option& opt) const
84 {
85 PYBIND11_OVERRIDE_REFERENCE(
86 int,
87 ncnn::Layer,
88 forward_inplace,
89 bottom_top_blobs,
90 opt);
91 }
92 virtual int forward_inplace(ncnn::Mat& bottom_top_blob, const ncnn::Option& opt) const
93 {
94 PYBIND11_OVERRIDE_REFERENCE(
95 int,
96 ncnn::Layer,
97 forward_inplace,
98 bottom_top_blob,
99 opt);
100 }
101
102#if NCNN_VULKAN
103public:
104 virtual int upload_model(ncnn::VkTransfer& cmd, const ncnn::Option& opt)
105 {
106 PYBIND11_OVERRIDE_REFERENCE(
107 int,
108 ncnn::Layer,
109 upload_model,
110 cmd,
111 opt);
112 }
113
114public:
115 virtual int forward(const std::vector<ncnn::VkMat>& bottom_blobs, std::vector<ncnn::VkMat>& top_blobs, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
116 {
117 PYBIND11_OVERRIDE_REFERENCE(
118 int,
119 ncnn::Layer,
120 forward,
121 bottom_blobs,
122 top_blobs,
123 cmd,
124 opt);
125 }
126 virtual int forward(const ncnn::VkMat& bottom_blob, ncnn::VkMat& top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
127 {
128 PYBIND11_OVERRIDE_REFERENCE(
129 int,
130 ncnn::Layer,
131 forward,
132 bottom_blob,
133 top_blob,
134 cmd,
135 opt);
136 }
137
138 virtual int forward_inplace(std::vector<ncnn::VkMat>& bottom_top_blobs, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
139 {
140 PYBIND11_OVERRIDE_REFERENCE(
141 int,
142 ncnn::Layer,
143 forward_inplace,
144 bottom_top_blobs,
145 cmd,
146 opt);
147 }
148 virtual int forward_inplace(ncnn::VkMat& bottom_top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
149 {
150 PYBIND11_OVERRIDE_REFERENCE(
151 int,
152 ncnn::Layer,
153 forward_inplace,
154 bottom_top_blob,
155 cmd,
156 opt);
157 }
158#endif // NCNN_VULKAN
159};
160
161#endif