Elffuss BraidHub

kikocis/ncnn public

d7a5f98c0f60 · 4.6 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#ifndef NCNN_COMMAND_H
16#define NCNN_COMMAND_H
17
18#include "platform.h"
19
20#if NCNN_VULKAN
21
22#include "mat.h"
23
24namespace ncnn {
25
26class Pipeline;
27#if NCNN_PLATFORM_API
28#if __ANDROID_API__ >= 26
29class ImportAndroidHardwareBufferPipeline;
30#endif // __ANDROID_API__ >= 26
31#endif // NCNN_PLATFORM_API
32class VkComputePrivate;
33class NCNN_EXPORT VkCompute
34{
35public:
36 explicit VkCompute(const VulkanDevice* vkdev);
37 virtual ~VkCompute();
38
39public:
40 void record_upload(const Mat& src, VkMat& dst, const Option& opt);
41
42 void record_upload(const Mat& src, VkImageMat& dst, const Option& opt);
43
44 void record_download(const VkMat& src, Mat& dst, const Option& opt);
45
46 void record_download(const VkImageMat& src, Mat& dst, const Option& opt);
47
48 void record_buffer_to_image(const VkMat& src, VkImageMat& dst, const Option& opt);
49
50 void record_image_to_buffer(const VkImageMat& src, VkMat& dst, const Option& opt);
51
52 void record_clone(const Mat& src, VkMat& dst, const Option& opt);
53
54 void record_clone(const Mat& src, VkImageMat& dst, const Option& opt);
55
56 void record_clone(const VkMat& src, Mat& dst, const Option& opt);
57
58 void record_clone(const VkImageMat& src, Mat& dst, const Option& opt);
59
60 void record_clone(const VkMat& src, VkMat& dst, const Option& opt);
61
62 void record_clone(const VkImageMat& src, VkImageMat& dst, const Option& opt);
63
64 void record_clone(const VkMat& src, VkImageMat& dst, const Option& opt);
65
66 void record_clone(const VkImageMat& src, VkMat& dst, const Option& opt);
67
68 void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& bindings, const std::vector<vk_constant_type>& constants, const VkMat& dispatcher);
69
70 void record_pipeline(const Pipeline* pipeline, const std::vector<VkImageMat>& bindings, const std::vector<vk_constant_type>& constants, const VkImageMat& dispatcher);
71
72 void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const VkMat& dispatcher);
73 void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const VkImageMat& dispatcher);
74 void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& buffer_bindings, const std::vector<VkImageMat>& image_bindings, const std::vector<vk_constant_type>& constants, const Mat& dispatcher);
75
76#if NCNN_BENCHMARK
77 void record_write_timestamp(uint32_t query);
78#endif // NCNN_BENCHMARK
79
80#if NCNN_PLATFORM_API
81#if __ANDROID_API__ >= 26
82 void record_import_android_hardware_buffer(const ImportAndroidHardwareBufferPipeline* pipeline, const VkImageMat& src, const VkMat& dst);
83
84 void record_import_android_hardware_buffer(const ImportAndroidHardwareBufferPipeline* pipeline, const VkImageMat& src, const VkImageMat& dst);
85#endif // __ANDROID_API__ >= 26
86#endif // NCNN_PLATFORM_API
87
88 int submit_and_wait();
89
90 int reset();
91
92#if NCNN_BENCHMARK
93 int create_query_pool(uint32_t query_count);
94
95 int get_query_pool_results(uint32_t first_query, uint32_t query_count, std::vector<uint64_t>& results);
96#endif // NCNN_BENCHMARK
97
98protected:
99 const VulkanDevice* vkdev;
100
101 void barrier_readwrite(const VkMat& binding);
102 void barrier_readwrite(const VkImageMat& binding);
103 void barrier_readonly(const VkImageMat& binding);
104
105private:
106 VkComputePrivate* const d;
107};
108
109class VkTransferPrivate;
110class NCNN_EXPORT VkTransfer
111{
112public:
113 explicit VkTransfer(const VulkanDevice* vkdev);
114 virtual ~VkTransfer();
115
116public:
117 void record_upload(const Mat& src, VkMat& dst, const Option& opt, bool flatten = true);
118
119 void record_upload(const Mat& src, VkImageMat& dst, const Option& opt);
120
121 int submit_and_wait();
122
123protected:
124 const VulkanDevice* vkdev;
125
126private:
127 VkTransferPrivate* const d;
128};
129
130} // namespace ncnn
131
132#endif // NCNN_VULKAN
133
134#endif // NCNN_COMMAND_H