react-native-vision-camera-spoof-detector 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +33 -24
  2. package/VisionCameraSpoofDetector.podspec +12 -2
  3. package/ios/HybridSpoofDetectorOutput.swift +72 -157
  4. package/ios/NcnnLivenessDetector.h +24 -0
  5. package/ios/NcnnLivenessDetector.mm +248 -0
  6. package/ios/ncnn.xcframework/Info.plist +27 -0
  7. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/allocator.h +433 -0
  8. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/benchmark.h +28 -0
  9. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/blob.h +33 -0
  10. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/c_api.h +401 -0
  11. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/command.h +111 -0
  12. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/cpu.h +177 -0
  13. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/datareader.h +111 -0
  14. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/expression.h +17 -0
  15. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/gpu.h +566 -0
  16. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer.h +212 -0
  17. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type.h +18 -0
  18. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type_enum.h +5 -0
  19. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type.h +19 -0
  20. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type_enum.h +115 -0
  21. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/mat.h +1868 -0
  22. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/modelbin.h +69 -0
  23. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/ncnn_export.h +43 -0
  24. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/net.h +252 -0
  25. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/option.h +151 -0
  26. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/paramdict.h +66 -0
  27. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipeline.h +101 -0
  28. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipelinecache.h +71 -0
  29. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/platform.h +372 -0
  30. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplemath.h +98 -0
  31. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleocv.h +492 -0
  32. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleomp.h +42 -0
  33. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplestl.h +598 -0
  34. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplevk.h +2196 -0
  35. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/vulkan_header_fix.h +1674 -0
  36. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Resources/Info.plist +18 -0
  37. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/allocator.h +433 -0
  38. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/benchmark.h +28 -0
  39. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/blob.h +33 -0
  40. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/c_api.h +401 -0
  41. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/command.h +111 -0
  42. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/cpu.h +177 -0
  43. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/datareader.h +111 -0
  44. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/expression.h +17 -0
  45. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/gpu.h +566 -0
  46. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer.h +212 -0
  47. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type.h +18 -0
  48. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type_enum.h +5 -0
  49. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type.h +19 -0
  50. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type_enum.h +115 -0
  51. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/mat.h +1868 -0
  52. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/modelbin.h +69 -0
  53. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/ncnn_export.h +43 -0
  54. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/net.h +252 -0
  55. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/option.h +151 -0
  56. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/paramdict.h +66 -0
  57. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipeline.h +101 -0
  58. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipelinecache.h +71 -0
  59. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/platform.h +372 -0
  60. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplemath.h +98 -0
  61. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleocv.h +492 -0
  62. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleomp.h +42 -0
  63. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplestl.h +598 -0
  64. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplevk.h +2196 -0
  65. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/vulkan_header_fix.h +1674 -0
  66. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Resources/Info.plist +18 -0
  67. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/ncnn +0 -0
  68. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/allocator.h +433 -0
  69. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/benchmark.h +28 -0
  70. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/blob.h +33 -0
  71. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/c_api.h +401 -0
  72. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/command.h +111 -0
  73. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/cpu.h +177 -0
  74. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/datareader.h +111 -0
  75. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/expression.h +17 -0
  76. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/gpu.h +566 -0
  77. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer.h +212 -0
  78. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type.h +18 -0
  79. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type_enum.h +5 -0
  80. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type.h +19 -0
  81. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type_enum.h +115 -0
  82. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/mat.h +1868 -0
  83. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/modelbin.h +69 -0
  84. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/ncnn_export.h +43 -0
  85. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/net.h +252 -0
  86. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/option.h +151 -0
  87. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/paramdict.h +66 -0
  88. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipeline.h +101 -0
  89. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipelinecache.h +71 -0
  90. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/platform.h +372 -0
  91. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplemath.h +98 -0
  92. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleocv.h +492 -0
  93. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleomp.h +42 -0
  94. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplestl.h +598 -0
  95. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplevk.h +2196 -0
  96. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/vulkan_header_fix.h +1674 -0
  97. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Resources/Info.plist +18 -0
  98. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/ncnn +0 -0
  99. package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/ncnn +0 -0
  100. package/ios/openmp.xcframework/Info.plist +27 -0
  101. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/omp.h +521 -0
  102. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/ompx.h +165 -0
  103. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Resources/Info.plist +18 -0
  104. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/omp.h +521 -0
  105. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/ompx.h +165 -0
  106. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Resources/Info.plist +18 -0
  107. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/openmp +0 -0
  108. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/omp.h +521 -0
  109. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/ompx.h +165 -0
  110. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Resources/Info.plist +18 -0
  111. package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/openmp +0 -0
  112. package/ios/openmp.xcframework/ios-arm64/openmp.framework/openmp +0 -0
  113. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleName</key>
6
+ <string>ncnn</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>com.tencent.ncnn</string>
9
+ <key>CFBundleVersion</key>
10
+ <string>1.0</string>
11
+ <key>CFBundleShortVersionString</key>
12
+ <string>1.0</string>
13
+ <key>CFBundleSignature</key>
14
+ <string>????</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ </dict>
18
+ </plist>
@@ -0,0 +1,433 @@
1
+ // Copyright 2018 Tencent
2
+ // SPDX-License-Identifier: BSD-3-Clause
3
+
4
+ #ifndef NCNN_ALLOCATOR_H
5
+ #define NCNN_ALLOCATOR_H
6
+
7
+ #ifdef _WIN32
8
+ #define WIN32_LEAN_AND_MEAN
9
+ #include <windows.h>
10
+ #endif
11
+
12
+ #include "platform.h"
13
+
14
+ #include <stdlib.h>
15
+
16
+ #if NCNN_PLATFORM_API
17
+ #if __ANDROID_API__ >= 26
18
+ #include <android/hardware_buffer.h>
19
+ #endif // __ANDROID_API__ >= 26
20
+ #endif // NCNN_PLATFORM_API
21
+
22
+ namespace ncnn {
23
+
24
+ // the alignment of all the allocated buffers
25
+ #if NCNN_AVX512
26
+ #define NCNN_MALLOC_ALIGN 64
27
+ #elif NCNN_AVX
28
+ #define NCNN_MALLOC_ALIGN 32
29
+ #else
30
+ #define NCNN_MALLOC_ALIGN 16
31
+ #endif
32
+
33
+ // we have some optimized kernels that may overread buffer a bit in loop
34
+ // it is common to interleave next-loop data load with arithmetic instructions
35
+ // allocating more bytes keeps us safe from SEGV_ACCERR failure
36
+ #define NCNN_MALLOC_OVERREAD 64
37
+
38
+ // Aligns a pointer to the specified number of bytes
39
+ // ptr Aligned pointer
40
+ // n Alignment size that must be a power of two
41
+ template<typename _Tp>
42
+ static NCNN_FORCEINLINE _Tp* alignPtr(_Tp* ptr, int n = (int)sizeof(_Tp))
43
+ {
44
+ return (_Tp*)(((size_t)ptr + n - 1) & -n);
45
+ }
46
+
47
+ // Aligns a buffer size to the specified number of bytes
48
+ // The function returns the minimum number that is greater or equal to sz and is divisible by n
49
+ // sz Buffer size to align
50
+ // n Alignment size that must be a power of two
51
+ static NCNN_FORCEINLINE size_t alignSize(size_t sz, int n)
52
+ {
53
+ return (sz + n - 1) & -n;
54
+ }
55
+
56
+ static NCNN_FORCEINLINE void* fastMalloc(size_t size)
57
+ {
58
+ #if _MSC_VER
59
+ return _aligned_malloc(size, NCNN_MALLOC_ALIGN);
60
+ #elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
61
+ void* ptr = 0;
62
+ if (posix_memalign(&ptr, NCNN_MALLOC_ALIGN, size + NCNN_MALLOC_OVERREAD))
63
+ ptr = 0;
64
+ return ptr;
65
+ #elif __ANDROID__ && __ANDROID_API__ < 17
66
+ return memalign(NCNN_MALLOC_ALIGN, size + NCNN_MALLOC_OVERREAD);
67
+ #else
68
+ unsigned char* udata = (unsigned char*)malloc(size + sizeof(void*) + NCNN_MALLOC_ALIGN + NCNN_MALLOC_OVERREAD);
69
+ if (!udata)
70
+ return 0;
71
+ unsigned char** adata = alignPtr((unsigned char**)udata + 1, NCNN_MALLOC_ALIGN);
72
+ adata[-1] = udata;
73
+ return adata;
74
+ #endif
75
+ }
76
+
77
+ static NCNN_FORCEINLINE void fastFree(void* ptr)
78
+ {
79
+ if (ptr)
80
+ {
81
+ #if _MSC_VER
82
+ _aligned_free(ptr);
83
+ #elif (defined(__unix__) || defined(__APPLE__)) && _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
84
+ free(ptr);
85
+ #elif __ANDROID__ && __ANDROID_API__ < 17
86
+ free(ptr);
87
+ #else
88
+ unsigned char* udata = ((unsigned char**)ptr)[-1];
89
+ free(udata);
90
+ #endif
91
+ }
92
+ }
93
+
94
+ #if NCNN_THREADS
95
+ // exchange-add operation for atomic operations on reference counters
96
+ #if defined __riscv && !defined __riscv_atomic
97
+ // riscv target without A extension
98
+ static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
99
+ {
100
+ int tmp = *addr;
101
+ *addr += delta;
102
+ return tmp;
103
+ }
104
+ #elif defined __INTEL_COMPILER && !(defined WIN32 || defined _WIN32)
105
+ // atomic increment on the linux version of the Intel(tm) compiler
106
+ #define NCNN_XADD(addr, delta) (int)_InterlockedExchangeAdd(const_cast<void*>(reinterpret_cast<volatile void*>(addr)), delta)
107
+ #elif defined __GNUC__
108
+ #if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
109
+ #ifdef __ATOMIC_ACQ_REL
110
+ #define NCNN_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
111
+ #else
112
+ #define NCNN_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
113
+ #endif
114
+ #else
115
+ #if defined __ATOMIC_ACQ_REL && !defined __clang__
116
+ // version for gcc >= 4.7
117
+ #define NCNN_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
118
+ #else
119
+ #define NCNN_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
120
+ #endif
121
+ #endif
122
+ #elif defined _MSC_VER && !defined RC_INVOKED
123
+ #define NCNN_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
124
+ #else
125
+ // thread-unsafe branch
126
+ static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
127
+ {
128
+ int tmp = *addr;
129
+ *addr += delta;
130
+ return tmp;
131
+ }
132
+ #endif
133
+ #else // NCNN_THREADS
134
+ static NCNN_FORCEINLINE int NCNN_XADD(int* addr, int delta)
135
+ {
136
+ int tmp = *addr;
137
+ *addr += delta;
138
+ return tmp;
139
+ }
140
+ #endif // NCNN_THREADS
141
+
142
+ class NCNN_EXPORT Allocator
143
+ {
144
+ public:
145
+ virtual ~Allocator();
146
+ virtual void* fastMalloc(size_t size) = 0;
147
+ virtual void fastFree(void* ptr) = 0;
148
+ };
149
+
150
+ class PoolAllocatorPrivate;
151
+ class NCNN_EXPORT PoolAllocator : public Allocator
152
+ {
153
+ public:
154
+ PoolAllocator();
155
+ ~PoolAllocator();
156
+
157
+ // ratio range 0 ~ 1
158
+ // default cr = 0
159
+ void set_size_compare_ratio(float scr);
160
+
161
+ // budget drop threshold
162
+ // default threshold = 10
163
+ void set_size_drop_threshold(size_t);
164
+
165
+ // release all budgets immediately
166
+ void clear();
167
+
168
+ virtual void* fastMalloc(size_t size);
169
+ virtual void fastFree(void* ptr);
170
+
171
+ private:
172
+ PoolAllocator(const PoolAllocator&);
173
+ PoolAllocator& operator=(const PoolAllocator&);
174
+
175
+ private:
176
+ PoolAllocatorPrivate* const d;
177
+ };
178
+
179
+ class UnlockedPoolAllocatorPrivate;
180
+ class NCNN_EXPORT UnlockedPoolAllocator : public Allocator
181
+ {
182
+ public:
183
+ UnlockedPoolAllocator();
184
+ ~UnlockedPoolAllocator();
185
+
186
+ // ratio range 0 ~ 1
187
+ // default cr = 0
188
+ void set_size_compare_ratio(float scr);
189
+
190
+ // budget drop threshold
191
+ // default threshold = 10
192
+ void set_size_drop_threshold(size_t);
193
+
194
+ // release all budgets immediately
195
+ void clear();
196
+
197
+ virtual void* fastMalloc(size_t size);
198
+ virtual void fastFree(void* ptr);
199
+
200
+ private:
201
+ UnlockedPoolAllocator(const UnlockedPoolAllocator&);
202
+ UnlockedPoolAllocator& operator=(const UnlockedPoolAllocator&);
203
+
204
+ private:
205
+ UnlockedPoolAllocatorPrivate* const d;
206
+ };
207
+
208
+ #if NCNN_VULKAN
209
+
210
+ class VulkanDevice;
211
+
212
+ class NCNN_EXPORT VkBufferMemory
213
+ {
214
+ public:
215
+ VkBuffer buffer;
216
+
217
+ // the base offset assigned by allocator
218
+ size_t offset;
219
+ size_t capacity;
220
+
221
+ VkDeviceMemory memory;
222
+ void* mapped_ptr;
223
+
224
+ // buffer state, modified by command functions internally
225
+ mutable VkAccessFlags access_flags;
226
+ mutable VkPipelineStageFlags stage_flags;
227
+
228
+ // initialize and modified by mat
229
+ int refcount;
230
+ };
231
+
232
+ class NCNN_EXPORT VkImageMemory
233
+ {
234
+ public:
235
+ VkImage image;
236
+ VkImageView imageview;
237
+
238
+ // underlying info assigned by allocator
239
+ int width;
240
+ int height;
241
+ int depth;
242
+ VkFormat format;
243
+
244
+ VkDeviceMemory memory;
245
+ void* mapped_ptr;
246
+
247
+ // the base offset assigned by allocator
248
+ size_t bind_offset;
249
+ size_t bind_capacity;
250
+
251
+ // image state, modified by command functions internally
252
+ mutable VkAccessFlags access_flags;
253
+ mutable VkImageLayout image_layout;
254
+ mutable VkPipelineStageFlags stage_flags;
255
+
256
+ // in-execution state, modified by command functions internally
257
+ mutable int command_refcount;
258
+
259
+ // initialize and modified by mat
260
+ int refcount;
261
+ };
262
+
263
+ class NCNN_EXPORT VkAllocator
264
+ {
265
+ public:
266
+ explicit VkAllocator(const VulkanDevice* _vkdev);
267
+ virtual ~VkAllocator();
268
+
269
+ virtual void clear();
270
+
271
+ virtual VkBufferMemory* fastMalloc(size_t size) = 0;
272
+ virtual void fastFree(VkBufferMemory* ptr) = 0;
273
+ virtual int flush(VkBufferMemory* ptr);
274
+ virtual int invalidate(VkBufferMemory* ptr);
275
+
276
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack) = 0;
277
+ virtual void fastFree(VkImageMemory* ptr) = 0;
278
+
279
+ public:
280
+ const VulkanDevice* vkdev;
281
+ uint32_t buffer_memory_type_index;
282
+ uint32_t image_memory_type_index;
283
+ uint32_t reserved_type_index;
284
+ bool mappable;
285
+ bool coherent;
286
+
287
+ protected:
288
+ VkBuffer create_buffer(size_t size, VkBufferUsageFlags usage);
289
+ VkDeviceMemory allocate_memory(size_t size, uint32_t memory_type_index);
290
+ VkDeviceMemory allocate_dedicated_memory(size_t size, uint32_t memory_type_index, VkImage image, VkBuffer buffer);
291
+
292
+ VkImage create_image(int width, int height, int depth, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage);
293
+ VkImageView create_imageview(VkImage image, VkFormat format);
294
+ };
295
+
296
+ class VkBlobAllocatorPrivate;
297
+ class NCNN_EXPORT VkBlobAllocator : public VkAllocator
298
+ {
299
+ public:
300
+ explicit VkBlobAllocator(const VulkanDevice* vkdev, size_t preferred_block_size = 16 * 1024 * 1024); // 16M
301
+ virtual ~VkBlobAllocator();
302
+
303
+ public:
304
+ // release all budgets immediately
305
+ virtual void clear();
306
+
307
+ virtual VkBufferMemory* fastMalloc(size_t size);
308
+ virtual void fastFree(VkBufferMemory* ptr);
309
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
310
+ virtual void fastFree(VkImageMemory* ptr);
311
+
312
+ private:
313
+ VkBlobAllocator(const VkBlobAllocator&);
314
+ VkBlobAllocator& operator=(const VkBlobAllocator&);
315
+
316
+ private:
317
+ VkBlobAllocatorPrivate* const d;
318
+ };
319
+
320
+ class VkWeightAllocatorPrivate;
321
+ class NCNN_EXPORT VkWeightAllocator : public VkAllocator
322
+ {
323
+ public:
324
+ explicit VkWeightAllocator(const VulkanDevice* vkdev, size_t preferred_block_size = 8 * 1024 * 1024); // 8M
325
+ virtual ~VkWeightAllocator();
326
+
327
+ public:
328
+ // release all blocks immediately
329
+ virtual void clear();
330
+
331
+ public:
332
+ virtual VkBufferMemory* fastMalloc(size_t size);
333
+ virtual void fastFree(VkBufferMemory* ptr);
334
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
335
+ virtual void fastFree(VkImageMemory* ptr);
336
+
337
+ private:
338
+ VkWeightAllocator(const VkWeightAllocator&);
339
+ VkWeightAllocator& operator=(const VkWeightAllocator&);
340
+
341
+ private:
342
+ VkWeightAllocatorPrivate* const d;
343
+ };
344
+
345
+ class VkStagingAllocatorPrivate;
346
+ class NCNN_EXPORT VkStagingAllocator : public VkAllocator
347
+ {
348
+ public:
349
+ explicit VkStagingAllocator(const VulkanDevice* vkdev);
350
+ virtual ~VkStagingAllocator();
351
+
352
+ public:
353
+ // ratio range 0 ~ 1
354
+ // default cr = 0.75
355
+ void set_size_compare_ratio(float scr);
356
+
357
+ // release all budgets immediately
358
+ virtual void clear();
359
+
360
+ virtual VkBufferMemory* fastMalloc(size_t size);
361
+ virtual void fastFree(VkBufferMemory* ptr);
362
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
363
+ virtual void fastFree(VkImageMemory* ptr);
364
+
365
+ private:
366
+ VkStagingAllocator(const VkStagingAllocator&);
367
+ VkStagingAllocator& operator=(const VkStagingAllocator&);
368
+
369
+ private:
370
+ VkStagingAllocatorPrivate* const d;
371
+ };
372
+
373
+ class VkWeightStagingAllocatorPrivate;
374
+ class NCNN_EXPORT VkWeightStagingAllocator : public VkAllocator
375
+ {
376
+ public:
377
+ explicit VkWeightStagingAllocator(const VulkanDevice* vkdev);
378
+ virtual ~VkWeightStagingAllocator();
379
+
380
+ public:
381
+ virtual VkBufferMemory* fastMalloc(size_t size);
382
+ virtual void fastFree(VkBufferMemory* ptr);
383
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
384
+ virtual void fastFree(VkImageMemory* ptr);
385
+
386
+ private:
387
+ VkWeightStagingAllocator(const VkWeightStagingAllocator&);
388
+ VkWeightStagingAllocator& operator=(const VkWeightStagingAllocator&);
389
+
390
+ private:
391
+ VkWeightStagingAllocatorPrivate* const d;
392
+ };
393
+
394
+ #if NCNN_PLATFORM_API
395
+ #if __ANDROID_API__ >= 26
396
+ class NCNN_EXPORT VkAndroidHardwareBufferImageAllocator : public VkAllocator
397
+ {
398
+ public:
399
+ VkAndroidHardwareBufferImageAllocator(const VulkanDevice* _vkdev, AHardwareBuffer* _hb);
400
+ virtual ~VkAndroidHardwareBufferImageAllocator();
401
+
402
+ public:
403
+ virtual VkBufferMemory* fastMalloc(size_t size);
404
+ virtual void fastFree(VkBufferMemory* ptr);
405
+ virtual VkImageMemory* fastMalloc(int w, int h, int c, size_t elemsize, int elempack);
406
+ virtual void fastFree(VkImageMemory* ptr);
407
+
408
+ private:
409
+ VkAndroidHardwareBufferImageAllocator(const VkAndroidHardwareBufferImageAllocator&);
410
+ VkAndroidHardwareBufferImageAllocator& operator=(const VkAndroidHardwareBufferImageAllocator&);
411
+
412
+ public:
413
+ int init();
414
+
415
+ int width() const;
416
+ int height() const;
417
+ uint64_t external_format() const;
418
+
419
+ public:
420
+ AHardwareBuffer* hb;
421
+ AHardwareBuffer_Desc bufferDesc;
422
+ VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties;
423
+ VkAndroidHardwareBufferPropertiesANDROID bufferProperties;
424
+ VkSamplerYcbcrConversionKHR samplerYcbcrConversion;
425
+ };
426
+ #endif // __ANDROID_API__ >= 26
427
+ #endif // NCNN_PLATFORM_API
428
+
429
+ #endif // NCNN_VULKAN
430
+
431
+ } // namespace ncnn
432
+
433
+ #endif // NCNN_ALLOCATOR_H
@@ -0,0 +1,28 @@
1
+ // Copyright 2017 Tencent
2
+ // SPDX-License-Identifier: BSD-3-Clause
3
+
4
+ #ifndef NCNN_BENCHMARK_H
5
+ #define NCNN_BENCHMARK_H
6
+
7
+ #include "layer.h"
8
+ #include "mat.h"
9
+ #include "platform.h"
10
+
11
+ namespace ncnn {
12
+
13
+ // get now timestamp in ms
14
+ NCNN_EXPORT double get_current_time();
15
+
16
+ // sleep milliseconds
17
+ NCNN_EXPORT void sleep(unsigned long long int milliseconds = 1000);
18
+
19
+ #if NCNN_BENCHMARK
20
+
21
+ NCNN_EXPORT void benchmark(const Layer* layer, double start, double end);
22
+ NCNN_EXPORT void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double start, double end);
23
+
24
+ #endif // NCNN_BENCHMARK
25
+
26
+ } // namespace ncnn
27
+
28
+ #endif // NCNN_BENCHMARK_H
@@ -0,0 +1,33 @@
1
+ // Copyright 2017 Tencent
2
+ // SPDX-License-Identifier: BSD-3-Clause
3
+
4
+ #ifndef NCNN_BLOB_H
5
+ #define NCNN_BLOB_H
6
+
7
+ #include "mat.h"
8
+ #include "platform.h"
9
+
10
+ namespace ncnn {
11
+
12
+ class NCNN_EXPORT Blob
13
+ {
14
+ public:
15
+ // empty
16
+ Blob();
17
+
18
+ public:
19
+ #if NCNN_STRING
20
+ // blob name
21
+ std::string name;
22
+ #endif // NCNN_STRING
23
+ // layer index which produce this blob as output
24
+ int producer;
25
+ // layer index which need this blob as input
26
+ int consumer;
27
+ // shape hint
28
+ Mat shape;
29
+ };
30
+
31
+ } // namespace ncnn
32
+
33
+ #endif // NCNN_BLOB_H