react-native-vision-camera-spoof-detector 1.4.1 → 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.
- package/README.md +42 -46
- package/VisionCameraSpoofDetector.podspec +12 -2
- package/android/build.gradle +0 -13
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofPackage.kt +1 -3
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +78 -925
- package/android/src/main/java/com/lengdev/livenessdetector/LivenessDetector.kt +228 -0
- package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +17 -31
- package/android/src/main/jniLibs/arm64-v8a/libliveness_detector.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libliveness_detector.so +0 -0
- package/index.d.ts +2 -9
- package/index.js +6 -6
- package/ios/FaceAntiSpoofModule.m +3 -2
- package/ios/HybridSpoofDetectorOutput.swift +73 -158
- package/ios/NcnnLivenessDetector.h +24 -0
- package/ios/NcnnLivenessDetector.mm +248 -0
- package/ios/ncnn.xcframework/Info.plist +27 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/A/ncnn +0 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/allocator.h +433 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/benchmark.h +28 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/blob.h +33 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/c_api.h +401 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/command.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/cpu.h +177 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/datareader.h +111 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/expression.h +17 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/gpu.h +566 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer.h +212 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type.h +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_shader_type_enum.h +5 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type.h +19 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/layer_type_enum.h +115 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/mat.h +1868 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/modelbin.h +69 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/ncnn_export.h +43 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/net.h +252 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/option.h +151 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/paramdict.h +66 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipeline.h +101 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/pipelinecache.h +71 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/platform.h +372 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplemath.h +98 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleocv.h +492 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simpleomp.h +42 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplestl.h +598 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/simplevk.h +2196 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Headers/ncnn/vulkan_header_fix.h +1674 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/Resources/Info.plist +18 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/Versions/Current/ncnn +0 -0
- package/ios/ncnn.xcframework/ios-arm64/ncnn.framework/ncnn +0 -0
- package/ios/openmp.xcframework/Info.plist +27 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/A/openmp +0 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/omp.h +521 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Headers/ompx.h +165 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/Resources/Info.plist +18 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/Versions/Current/openmp +0 -0
- package/ios/openmp.xcframework/ios-arm64/openmp.framework/openmp +0 -0
- package/lib/assets/live/config.json +1 -0
- package/lib/assets/live/model_1.bin +0 -0
- package/lib/assets/live/model_1.param +214 -0
- package/lib/assets/live/model_2.bin +0 -0
- package/lib/assets/live/model_2.param +238 -0
- package/nitrogen/generated/android/c++/JSpoofDetectorOutputOptions.hpp +1 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/SpoofDetectorOutputOptions.kt +4 -14
- package/nitrogen/generated/ios/swift/SpoofDetectorOutputOptions.swift +1 -37
- package/nitrogen/generated/shared/c++/SpoofDetectorOutputOptions.hpp +1 -9
- package/package.json +1 -2
- package/src/specs/SpoofDetectorFactory.nitro.ts +0 -2
- package/android/fix-prefab.gradle +0 -4
- package/android/src/main/java/com/faceantispoof/AcceleratorConfig.kt +0 -97
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofModule.kt +0 -242
- package/android/src/main/res/values/strings.xml +0 -3
- package/lib/assets/FaceAntiSpoofing.tflite +0 -0
- package/lib/assets/model_spec.json +0 -16
|
@@ -0,0 +1,1868 @@
|
|
|
1
|
+
// Copyright 2017 Tencent
|
|
2
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
+
|
|
4
|
+
#ifndef NCNN_MAT_H
|
|
5
|
+
#define NCNN_MAT_H
|
|
6
|
+
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
#if __ARM_NEON
|
|
10
|
+
#include <arm_neon.h>
|
|
11
|
+
#endif
|
|
12
|
+
#if __SSE2__
|
|
13
|
+
#include <emmintrin.h>
|
|
14
|
+
#if __AVX__
|
|
15
|
+
#include <immintrin.h>
|
|
16
|
+
#endif
|
|
17
|
+
#endif
|
|
18
|
+
#if __mips_msa
|
|
19
|
+
#include <msa.h>
|
|
20
|
+
#endif
|
|
21
|
+
#if __loongarch_sx
|
|
22
|
+
#include <lsxintrin.h>
|
|
23
|
+
#endif
|
|
24
|
+
#if __riscv_vector
|
|
25
|
+
#include <riscv_vector.h>
|
|
26
|
+
#include "cpu.h" // cpu_riscv_vlenb()
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#include "allocator.h"
|
|
30
|
+
#include "option.h"
|
|
31
|
+
#include "platform.h"
|
|
32
|
+
|
|
33
|
+
#if NCNN_PIXEL
|
|
34
|
+
#if NCNN_PLATFORM_API
|
|
35
|
+
#if __ANDROID_API__ >= 9
|
|
36
|
+
#include <android/bitmap.h>
|
|
37
|
+
#include <jni.h>
|
|
38
|
+
#endif // __ANDROID_API__ >= 9
|
|
39
|
+
#endif // NCNN_PLATFORM_API
|
|
40
|
+
#endif // NCNN_PIXEL
|
|
41
|
+
|
|
42
|
+
namespace ncnn {
|
|
43
|
+
|
|
44
|
+
#if NCNN_VULKAN
|
|
45
|
+
class VkMat;
|
|
46
|
+
class VkImageMat;
|
|
47
|
+
#endif // NCNN_VULKAN
|
|
48
|
+
|
|
49
|
+
// the three dimension matrix
|
|
50
|
+
class NCNN_EXPORT Mat
|
|
51
|
+
{
|
|
52
|
+
public:
|
|
53
|
+
// empty
|
|
54
|
+
Mat();
|
|
55
|
+
// vec
|
|
56
|
+
Mat(int w, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
57
|
+
// image
|
|
58
|
+
Mat(int w, int h, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
59
|
+
// dim
|
|
60
|
+
Mat(int w, int h, int c, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
61
|
+
// cube
|
|
62
|
+
Mat(int w, int h, int d, int c, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
63
|
+
// packed vec
|
|
64
|
+
Mat(int w, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
65
|
+
// packed image
|
|
66
|
+
Mat(int w, int h, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
67
|
+
// packed dim
|
|
68
|
+
Mat(int w, int h, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
69
|
+
// packed cube
|
|
70
|
+
Mat(int w, int h, int d, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
71
|
+
// copy
|
|
72
|
+
Mat(const Mat& m);
|
|
73
|
+
// external vec
|
|
74
|
+
Mat(int w, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
75
|
+
// external image
|
|
76
|
+
Mat(int w, int h, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
77
|
+
// external dim
|
|
78
|
+
Mat(int w, int h, int c, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
79
|
+
// external cube
|
|
80
|
+
Mat(int w, int h, int d, int c, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
81
|
+
// external packed vec
|
|
82
|
+
Mat(int w, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
83
|
+
// external packed image
|
|
84
|
+
Mat(int w, int h, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
85
|
+
// external packed dim
|
|
86
|
+
Mat(int w, int h, int c, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
87
|
+
// external packed cube
|
|
88
|
+
Mat(int w, int h, int d, int c, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
89
|
+
// release
|
|
90
|
+
~Mat();
|
|
91
|
+
// assign
|
|
92
|
+
Mat& operator=(const Mat& m);
|
|
93
|
+
// set all
|
|
94
|
+
void fill(float v);
|
|
95
|
+
void fill(int v);
|
|
96
|
+
#if __ARM_NEON
|
|
97
|
+
void fill(float32x4_t _v);
|
|
98
|
+
void fill(uint16x4_t _v);
|
|
99
|
+
#if !defined(_MSC_VER)
|
|
100
|
+
void fill(int32x4_t _v);
|
|
101
|
+
#endif
|
|
102
|
+
void fill(int32x4_t _v0, int32x4_t _v1);
|
|
103
|
+
#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
|
|
104
|
+
#if !defined(_MSC_VER)
|
|
105
|
+
void fill(float16x4_t _v);
|
|
106
|
+
void fill(float16x8_t _v);
|
|
107
|
+
#endif
|
|
108
|
+
#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
|
|
109
|
+
#endif // __ARM_NEON
|
|
110
|
+
#if __SSE2__
|
|
111
|
+
#if __AVX__
|
|
112
|
+
#if __AVX512F__
|
|
113
|
+
void fill(const __m512& _v);
|
|
114
|
+
#endif // __AVX512F__
|
|
115
|
+
void fill(const __m256& _v, int i = 0);
|
|
116
|
+
#endif // __AVX__
|
|
117
|
+
void fill(const __m128& _v);
|
|
118
|
+
void fill(const __m128i& _v);
|
|
119
|
+
#endif // __SSE2__
|
|
120
|
+
#if __mips_msa
|
|
121
|
+
void fill(v4f32 _v);
|
|
122
|
+
#endif // __mips_msa
|
|
123
|
+
#if __loongarch_sx
|
|
124
|
+
void fill(__m128 _v);
|
|
125
|
+
#endif //__loongarch_sx
|
|
126
|
+
#if __riscv_vector
|
|
127
|
+
void fill(vfloat32m1_t _v);
|
|
128
|
+
void fill(vuint16m1_t _v);
|
|
129
|
+
void fill(vint8m1_t _v);
|
|
130
|
+
#if __riscv_zvfh
|
|
131
|
+
void fill(vfloat16m1_t _v);
|
|
132
|
+
#endif // __riscv_zvfh
|
|
133
|
+
#endif // __riscv_vector
|
|
134
|
+
template<typename T>
|
|
135
|
+
void fill(T v);
|
|
136
|
+
// deep copy
|
|
137
|
+
Mat clone(Allocator* allocator = 0) const;
|
|
138
|
+
// deep copy from other mat, inplace
|
|
139
|
+
void clone_from(const ncnn::Mat& mat, Allocator* allocator = 0);
|
|
140
|
+
// reshape vec
|
|
141
|
+
Mat reshape(int w, Allocator* allocator = 0) const;
|
|
142
|
+
// reshape image
|
|
143
|
+
Mat reshape(int w, int h, Allocator* allocator = 0) const;
|
|
144
|
+
// reshape dim
|
|
145
|
+
Mat reshape(int w, int h, int c, Allocator* allocator = 0) const;
|
|
146
|
+
// reshape cube
|
|
147
|
+
Mat reshape(int w, int h, int d, int c, Allocator* allocator = 0) const;
|
|
148
|
+
// allocate vec
|
|
149
|
+
void create(int w, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
150
|
+
// allocate image
|
|
151
|
+
void create(int w, int h, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
152
|
+
// allocate dim
|
|
153
|
+
void create(int w, int h, int c, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
154
|
+
// allocate cube
|
|
155
|
+
void create(int w, int h, int d, int c, size_t elemsize = 4u, Allocator* allocator = 0);
|
|
156
|
+
// allocate packed vec
|
|
157
|
+
void create(int w, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
158
|
+
// allocate packed image
|
|
159
|
+
void create(int w, int h, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
160
|
+
// allocate packed dim
|
|
161
|
+
void create(int w, int h, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
162
|
+
// allocate packed cube
|
|
163
|
+
void create(int w, int h, int d, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
|
|
164
|
+
// allocate like
|
|
165
|
+
void create_like(const Mat& m, Allocator* allocator = 0);
|
|
166
|
+
#if NCNN_VULKAN
|
|
167
|
+
// allocate like
|
|
168
|
+
void create_like(const VkMat& m, Allocator* allocator = 0);
|
|
169
|
+
// allocate like
|
|
170
|
+
void create_like(const VkImageMat& im, Allocator* allocator = 0);
|
|
171
|
+
#endif // NCNN_VULKAN
|
|
172
|
+
// refcount++
|
|
173
|
+
void addref();
|
|
174
|
+
// refcount--
|
|
175
|
+
void release();
|
|
176
|
+
|
|
177
|
+
bool empty() const;
|
|
178
|
+
size_t total() const;
|
|
179
|
+
|
|
180
|
+
// bits per element
|
|
181
|
+
int elembits() const;
|
|
182
|
+
|
|
183
|
+
// shape only
|
|
184
|
+
Mat shape() const;
|
|
185
|
+
|
|
186
|
+
// data reference
|
|
187
|
+
Mat channel(int c);
|
|
188
|
+
const Mat channel(int c) const;
|
|
189
|
+
Mat depth(int z);
|
|
190
|
+
const Mat depth(int z) const;
|
|
191
|
+
float* row(int y);
|
|
192
|
+
const float* row(int y) const;
|
|
193
|
+
template<typename T>
|
|
194
|
+
T* row(int y);
|
|
195
|
+
template<typename T>
|
|
196
|
+
const T* row(int y) const;
|
|
197
|
+
|
|
198
|
+
// range reference
|
|
199
|
+
Mat channel_range(int c, int channels);
|
|
200
|
+
const Mat channel_range(int c, int channels) const;
|
|
201
|
+
Mat depth_range(int z, int depths);
|
|
202
|
+
const Mat depth_range(int z, int depths) const;
|
|
203
|
+
Mat row_range(int y, int rows);
|
|
204
|
+
const Mat row_range(int y, int rows) const;
|
|
205
|
+
Mat range(int x, int n);
|
|
206
|
+
const Mat range(int x, int n) const;
|
|
207
|
+
|
|
208
|
+
// access raw data
|
|
209
|
+
template<typename T>
|
|
210
|
+
operator T*();
|
|
211
|
+
template<typename T>
|
|
212
|
+
operator const T*() const;
|
|
213
|
+
|
|
214
|
+
// convenient access float vec element
|
|
215
|
+
float& operator[](size_t i);
|
|
216
|
+
const float& operator[](size_t i) const;
|
|
217
|
+
|
|
218
|
+
#if NCNN_PIXEL
|
|
219
|
+
enum PixelType
|
|
220
|
+
{
|
|
221
|
+
PIXEL_CONVERT_SHIFT = 16,
|
|
222
|
+
PIXEL_FORMAT_MASK = 0x0000ffff,
|
|
223
|
+
PIXEL_CONVERT_MASK = 0xffff0000,
|
|
224
|
+
|
|
225
|
+
PIXEL_RGB = 1,
|
|
226
|
+
PIXEL_BGR = 2,
|
|
227
|
+
PIXEL_GRAY = 3,
|
|
228
|
+
PIXEL_RGBA = 4,
|
|
229
|
+
PIXEL_BGRA = 5,
|
|
230
|
+
|
|
231
|
+
PIXEL_RGB2BGR = PIXEL_RGB | (PIXEL_BGR << PIXEL_CONVERT_SHIFT),
|
|
232
|
+
PIXEL_RGB2GRAY = PIXEL_RGB | (PIXEL_GRAY << PIXEL_CONVERT_SHIFT),
|
|
233
|
+
PIXEL_RGB2RGBA = PIXEL_RGB | (PIXEL_RGBA << PIXEL_CONVERT_SHIFT),
|
|
234
|
+
PIXEL_RGB2BGRA = PIXEL_RGB | (PIXEL_BGRA << PIXEL_CONVERT_SHIFT),
|
|
235
|
+
|
|
236
|
+
PIXEL_BGR2RGB = PIXEL_BGR | (PIXEL_RGB << PIXEL_CONVERT_SHIFT),
|
|
237
|
+
PIXEL_BGR2GRAY = PIXEL_BGR | (PIXEL_GRAY << PIXEL_CONVERT_SHIFT),
|
|
238
|
+
PIXEL_BGR2RGBA = PIXEL_BGR | (PIXEL_RGBA << PIXEL_CONVERT_SHIFT),
|
|
239
|
+
PIXEL_BGR2BGRA = PIXEL_BGR | (PIXEL_BGRA << PIXEL_CONVERT_SHIFT),
|
|
240
|
+
|
|
241
|
+
PIXEL_GRAY2RGB = PIXEL_GRAY | (PIXEL_RGB << PIXEL_CONVERT_SHIFT),
|
|
242
|
+
PIXEL_GRAY2BGR = PIXEL_GRAY | (PIXEL_BGR << PIXEL_CONVERT_SHIFT),
|
|
243
|
+
PIXEL_GRAY2RGBA = PIXEL_GRAY | (PIXEL_RGBA << PIXEL_CONVERT_SHIFT),
|
|
244
|
+
PIXEL_GRAY2BGRA = PIXEL_GRAY | (PIXEL_BGRA << PIXEL_CONVERT_SHIFT),
|
|
245
|
+
|
|
246
|
+
PIXEL_RGBA2RGB = PIXEL_RGBA | (PIXEL_RGB << PIXEL_CONVERT_SHIFT),
|
|
247
|
+
PIXEL_RGBA2BGR = PIXEL_RGBA | (PIXEL_BGR << PIXEL_CONVERT_SHIFT),
|
|
248
|
+
PIXEL_RGBA2GRAY = PIXEL_RGBA | (PIXEL_GRAY << PIXEL_CONVERT_SHIFT),
|
|
249
|
+
PIXEL_RGBA2BGRA = PIXEL_RGBA | (PIXEL_BGRA << PIXEL_CONVERT_SHIFT),
|
|
250
|
+
|
|
251
|
+
PIXEL_BGRA2RGB = PIXEL_BGRA | (PIXEL_RGB << PIXEL_CONVERT_SHIFT),
|
|
252
|
+
PIXEL_BGRA2BGR = PIXEL_BGRA | (PIXEL_BGR << PIXEL_CONVERT_SHIFT),
|
|
253
|
+
PIXEL_BGRA2GRAY = PIXEL_BGRA | (PIXEL_GRAY << PIXEL_CONVERT_SHIFT),
|
|
254
|
+
PIXEL_BGRA2RGBA = PIXEL_BGRA | (PIXEL_RGBA << PIXEL_CONVERT_SHIFT),
|
|
255
|
+
};
|
|
256
|
+
// convenient construct from pixel data
|
|
257
|
+
static Mat from_pixels(const unsigned char* pixels, int type, int w, int h, Allocator* allocator = 0);
|
|
258
|
+
// convenient construct from pixel data with stride(bytes-per-row) parameter
|
|
259
|
+
static Mat from_pixels(const unsigned char* pixels, int type, int w, int h, int stride, Allocator* allocator = 0);
|
|
260
|
+
// convenient construct from pixel data and resize to specific size
|
|
261
|
+
static Mat from_pixels_resize(const unsigned char* pixels, int type, int w, int h, int target_width, int target_height, Allocator* allocator = 0);
|
|
262
|
+
// convenient construct from pixel data and resize to specific size with stride(bytes-per-row) parameter
|
|
263
|
+
static Mat from_pixels_resize(const unsigned char* pixels, int type, int w, int h, int stride, int target_width, int target_height, Allocator* allocator = 0);
|
|
264
|
+
// convenient construct from pixel data roi
|
|
265
|
+
static Mat from_pixels_roi(const unsigned char* pixels, int type, int w, int h, int roix, int roiy, int roiw, int roih, Allocator* allocator = 0);
|
|
266
|
+
// convenient construct from pixel data roi with stride(bytes-per-row) parameter
|
|
267
|
+
static Mat from_pixels_roi(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, Allocator* allocator = 0);
|
|
268
|
+
// convenient construct from pixel data roi and resize to specific size
|
|
269
|
+
static Mat from_pixels_roi_resize(const unsigned char* pixels, int type, int w, int h, int roix, int roiy, int roiw, int roih, int target_width, int target_height, Allocator* allocator = 0);
|
|
270
|
+
// convenient construct from pixel data roi and resize to specific size with stride(bytes-per-row) parameter
|
|
271
|
+
static Mat from_pixels_roi_resize(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, int target_width, int target_height, Allocator* allocator = 0);
|
|
272
|
+
|
|
273
|
+
// convenient export to pixel data
|
|
274
|
+
void to_pixels(unsigned char* pixels, int type) const;
|
|
275
|
+
// convenient export to pixel data with stride(bytes-per-row) parameter
|
|
276
|
+
void to_pixels(unsigned char* pixels, int type, int stride) const;
|
|
277
|
+
// convenient export to pixel data and resize to specific size
|
|
278
|
+
void to_pixels_resize(unsigned char* pixels, int type, int target_width, int target_height) const;
|
|
279
|
+
// convenient export to pixel data and resize to specific size with stride(bytes-per-row) parameter
|
|
280
|
+
void to_pixels_resize(unsigned char* pixels, int type, int target_width, int target_height, int target_stride) const;
|
|
281
|
+
|
|
282
|
+
#if NCNN_PLATFORM_API
|
|
283
|
+
#if __ANDROID_API__ >= 9
|
|
284
|
+
// convenient construct from android Bitmap
|
|
285
|
+
static Mat from_android_bitmap(JNIEnv* env, jobject bitmap, int type_to, Allocator* allocator = 0);
|
|
286
|
+
// convenient construct from android Bitmap and resize to specific size
|
|
287
|
+
static Mat from_android_bitmap_resize(JNIEnv* env, jobject bitmap, int type_to, int target_width, int target_height, Allocator* allocator = 0);
|
|
288
|
+
// convenient construct from android Bitmap roi
|
|
289
|
+
static Mat from_android_bitmap_roi(JNIEnv* env, jobject bitmap, int type_to, int roix, int roiy, int roiw, int roih, Allocator* allocator = 0);
|
|
290
|
+
// convenient construct from android Bitmap roi and resize to specific size
|
|
291
|
+
static Mat from_android_bitmap_roi_resize(JNIEnv* env, jobject bitmap, int type_to, int roix, int roiy, int roiw, int roih, int target_width, int target_height, Allocator* allocator = 0);
|
|
292
|
+
// convenient export to android Bitmap and resize to the android Bitmap size
|
|
293
|
+
void to_android_bitmap(JNIEnv* env, jobject bitmap, int type_from) const;
|
|
294
|
+
#endif // __ANDROID_API__ >= 9
|
|
295
|
+
#endif // NCNN_PLATFORM_API
|
|
296
|
+
#endif // NCNN_PIXEL
|
|
297
|
+
|
|
298
|
+
// substract channel-wise mean values, then multiply by normalize values, pass 0 to skip
|
|
299
|
+
void substract_mean_normalize(const float* mean_vals, const float* norm_vals);
|
|
300
|
+
|
|
301
|
+
// convenient construct from half precision floating point data
|
|
302
|
+
static Mat from_float16(const unsigned short* data, int size);
|
|
303
|
+
|
|
304
|
+
// pointer to the data
|
|
305
|
+
void* data;
|
|
306
|
+
|
|
307
|
+
// pointer to the reference counter
|
|
308
|
+
// when points to user-allocated data, the pointer is NULL
|
|
309
|
+
int* refcount;
|
|
310
|
+
|
|
311
|
+
// element size in bytes
|
|
312
|
+
// 4 = float32/int32
|
|
313
|
+
// 2 = float16
|
|
314
|
+
// 1 = int8/uint8
|
|
315
|
+
// 0 = empty
|
|
316
|
+
size_t elemsize;
|
|
317
|
+
|
|
318
|
+
// packed count inside element
|
|
319
|
+
// c/1-d-h-w-1 c/1-h-w-1 h/1-w-1 w/1-1 scalar
|
|
320
|
+
// c/4-d-h-w-4 c/4-h-w-4 h/4-w-4 w/4-4 sse/neon
|
|
321
|
+
// c/8-d-h-w-8 c/8-h-w-8 h/8-w-8 w/8-8 avx/fp16
|
|
322
|
+
int elempack;
|
|
323
|
+
|
|
324
|
+
// the allocator
|
|
325
|
+
Allocator* allocator;
|
|
326
|
+
|
|
327
|
+
// the dimension rank
|
|
328
|
+
int dims;
|
|
329
|
+
|
|
330
|
+
int w;
|
|
331
|
+
int h;
|
|
332
|
+
int d;
|
|
333
|
+
int c;
|
|
334
|
+
|
|
335
|
+
size_t cstep;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
#if NCNN_VULKAN
|
|
339
|
+
|
|
340
|
+
// the three dimension matrix, vulkan version
|
|
341
|
+
class NCNN_EXPORT VkMat
|
|
342
|
+
{
|
|
343
|
+
public:
|
|
344
|
+
// empty
|
|
345
|
+
VkMat();
|
|
346
|
+
// vec
|
|
347
|
+
VkMat(int w, size_t elemsize, VkAllocator* allocator);
|
|
348
|
+
// image
|
|
349
|
+
VkMat(int w, int h, size_t elemsize, VkAllocator* allocator);
|
|
350
|
+
// dim
|
|
351
|
+
VkMat(int w, int h, int c, size_t elemsize, VkAllocator* allocator);
|
|
352
|
+
// cube
|
|
353
|
+
VkMat(int w, int h, int d, int c, size_t elemsize, VkAllocator* allocator);
|
|
354
|
+
// packed vec
|
|
355
|
+
VkMat(int w, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
356
|
+
// packed image
|
|
357
|
+
VkMat(int w, int h, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
358
|
+
// packed dim
|
|
359
|
+
VkMat(int w, int h, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
360
|
+
// packed cube
|
|
361
|
+
VkMat(int w, int h, int d, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
362
|
+
// copy
|
|
363
|
+
VkMat(const VkMat& m);
|
|
364
|
+
// external vec
|
|
365
|
+
VkMat(int w, VkBufferMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
366
|
+
// external image
|
|
367
|
+
VkMat(int w, int h, VkBufferMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
368
|
+
// external dim
|
|
369
|
+
VkMat(int w, int h, int c, VkBufferMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
370
|
+
// external cube
|
|
371
|
+
VkMat(int w, int h, int d, int c, VkBufferMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
372
|
+
// external packed vec
|
|
373
|
+
VkMat(int w, VkBufferMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
374
|
+
// external packed image
|
|
375
|
+
VkMat(int w, int h, VkBufferMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
376
|
+
// external packed dim
|
|
377
|
+
VkMat(int w, int h, int c, VkBufferMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
378
|
+
// external packed cube
|
|
379
|
+
VkMat(int w, int h, int d, int c, VkBufferMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
380
|
+
// release
|
|
381
|
+
~VkMat();
|
|
382
|
+
// assign
|
|
383
|
+
VkMat& operator=(const VkMat& m);
|
|
384
|
+
// allocate vec
|
|
385
|
+
void create(int w, size_t elemsize, VkAllocator* allocator);
|
|
386
|
+
// allocate image
|
|
387
|
+
void create(int w, int h, size_t elemsize, VkAllocator* allocator);
|
|
388
|
+
// allocate dim
|
|
389
|
+
void create(int w, int h, int c, size_t elemsize, VkAllocator* allocator);
|
|
390
|
+
// allocate cube
|
|
391
|
+
void create(int w, int h, int d, int c, size_t elemsize, VkAllocator* allocator);
|
|
392
|
+
// allocate packed vec
|
|
393
|
+
void create(int w, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
394
|
+
// allocate packed image
|
|
395
|
+
void create(int w, int h, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
396
|
+
// allocate packed dim
|
|
397
|
+
void create(int w, int h, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
398
|
+
// allocate packed cube
|
|
399
|
+
void create(int w, int h, int d, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
400
|
+
// allocate like
|
|
401
|
+
void create_like(const Mat& m, VkAllocator* allocator);
|
|
402
|
+
// allocate like
|
|
403
|
+
void create_like(const VkMat& m, VkAllocator* allocator);
|
|
404
|
+
// allocate like
|
|
405
|
+
void create_like(const VkImageMat& im, VkAllocator* allocator);
|
|
406
|
+
|
|
407
|
+
// mapped
|
|
408
|
+
Mat mapped() const;
|
|
409
|
+
void* mapped_ptr() const;
|
|
410
|
+
|
|
411
|
+
// refcount++
|
|
412
|
+
void addref();
|
|
413
|
+
// refcount--
|
|
414
|
+
void release();
|
|
415
|
+
|
|
416
|
+
bool empty() const;
|
|
417
|
+
size_t total() const;
|
|
418
|
+
|
|
419
|
+
// bits per element
|
|
420
|
+
int elembits() const;
|
|
421
|
+
|
|
422
|
+
// shape only
|
|
423
|
+
Mat shape() const;
|
|
424
|
+
|
|
425
|
+
// low-level reference
|
|
426
|
+
VkBuffer buffer() const;
|
|
427
|
+
size_t buffer_offset() const;
|
|
428
|
+
size_t buffer_capacity() const;
|
|
429
|
+
|
|
430
|
+
// device buffer
|
|
431
|
+
VkBufferMemory* data;
|
|
432
|
+
|
|
433
|
+
// pointer to the reference counter
|
|
434
|
+
// when points to user-allocated data, the pointer is NULL
|
|
435
|
+
int* refcount;
|
|
436
|
+
|
|
437
|
+
// element size in bytes
|
|
438
|
+
// 4 = float32/int32
|
|
439
|
+
// 2 = float16
|
|
440
|
+
// 1 = int8/uint8
|
|
441
|
+
// 0 = empty
|
|
442
|
+
size_t elemsize;
|
|
443
|
+
|
|
444
|
+
// packed count inside element
|
|
445
|
+
// c/1-d-h-w-1 c/1-h-w-1 h/1-w-1 w/1-1 scalar
|
|
446
|
+
// c/4-d-h-w-4 c/4-h-w-4 h/4-w-4 w/4-4 sse/neon
|
|
447
|
+
// c/8-d-h-w-8 c/8-h-w-8 h/8-w-8 w/8-8 avx/fp16
|
|
448
|
+
int elempack;
|
|
449
|
+
|
|
450
|
+
// the allocator
|
|
451
|
+
VkAllocator* allocator;
|
|
452
|
+
|
|
453
|
+
// the dimension rank
|
|
454
|
+
int dims;
|
|
455
|
+
|
|
456
|
+
int w;
|
|
457
|
+
int h;
|
|
458
|
+
int d;
|
|
459
|
+
int c;
|
|
460
|
+
|
|
461
|
+
size_t cstep;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
class NCNN_EXPORT VkImageMat
|
|
465
|
+
{
|
|
466
|
+
public:
|
|
467
|
+
// empty
|
|
468
|
+
VkImageMat();
|
|
469
|
+
// vec
|
|
470
|
+
VkImageMat(int w, size_t elemsize, VkAllocator* allocator);
|
|
471
|
+
// image
|
|
472
|
+
VkImageMat(int w, int h, size_t elemsize, VkAllocator* allocator);
|
|
473
|
+
// dim
|
|
474
|
+
VkImageMat(int w, int h, int c, size_t elemsize, VkAllocator* allocator);
|
|
475
|
+
// cube
|
|
476
|
+
VkImageMat(int w, int h, int d, int c, size_t elemsize, VkAllocator* allocator);
|
|
477
|
+
// packed vec
|
|
478
|
+
VkImageMat(int w, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
479
|
+
// packed image
|
|
480
|
+
VkImageMat(int w, int h, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
481
|
+
// packed dim
|
|
482
|
+
VkImageMat(int w, int h, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
483
|
+
// packed cube
|
|
484
|
+
VkImageMat(int w, int h, int d, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
485
|
+
// copy
|
|
486
|
+
VkImageMat(const VkImageMat& m);
|
|
487
|
+
// external vec
|
|
488
|
+
VkImageMat(int w, VkImageMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
489
|
+
// external image
|
|
490
|
+
VkImageMat(int w, int h, VkImageMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
491
|
+
// external dim
|
|
492
|
+
VkImageMat(int w, int h, int c, VkImageMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
493
|
+
// external cube
|
|
494
|
+
VkImageMat(int w, int h, int d, int c, VkImageMemory* data, size_t elemsize, VkAllocator* allocator);
|
|
495
|
+
// external packed vec
|
|
496
|
+
VkImageMat(int w, VkImageMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
497
|
+
// external packed image
|
|
498
|
+
VkImageMat(int w, int h, VkImageMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
499
|
+
// external packed dim
|
|
500
|
+
VkImageMat(int w, int h, int c, VkImageMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
501
|
+
// external packed cube
|
|
502
|
+
VkImageMat(int w, int h, int d, int c, VkImageMemory* data, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
503
|
+
// release
|
|
504
|
+
~VkImageMat();
|
|
505
|
+
// assign
|
|
506
|
+
VkImageMat& operator=(const VkImageMat& m);
|
|
507
|
+
// allocate vec
|
|
508
|
+
void create(int w, size_t elemsize, VkAllocator* allocator);
|
|
509
|
+
// allocate image
|
|
510
|
+
void create(int w, int h, size_t elemsize, VkAllocator* allocator);
|
|
511
|
+
// allocate dim
|
|
512
|
+
void create(int w, int h, int c, size_t elemsize, VkAllocator* allocator);
|
|
513
|
+
// allocate cube
|
|
514
|
+
void create(int w, int h, int d, int c, size_t elemsize, VkAllocator* allocator);
|
|
515
|
+
// allocate packed vec
|
|
516
|
+
void create(int w, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
517
|
+
// allocate packed image
|
|
518
|
+
void create(int w, int h, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
519
|
+
// allocate packed dim
|
|
520
|
+
void create(int w, int h, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
521
|
+
// allocate packed cube
|
|
522
|
+
void create(int w, int h, int d, int c, size_t elemsize, int elempack, VkAllocator* allocator);
|
|
523
|
+
// allocate like
|
|
524
|
+
void create_like(const Mat& m, VkAllocator* allocator);
|
|
525
|
+
// allocate like
|
|
526
|
+
void create_like(const VkMat& m, VkAllocator* allocator);
|
|
527
|
+
// allocate like
|
|
528
|
+
void create_like(const VkImageMat& im, VkAllocator* allocator);
|
|
529
|
+
|
|
530
|
+
// mapped
|
|
531
|
+
Mat mapped() const;
|
|
532
|
+
void* mapped_ptr() const;
|
|
533
|
+
|
|
534
|
+
// refcount++
|
|
535
|
+
void addref();
|
|
536
|
+
// refcount--
|
|
537
|
+
void release();
|
|
538
|
+
|
|
539
|
+
bool empty() const;
|
|
540
|
+
size_t total() const;
|
|
541
|
+
|
|
542
|
+
// bits per element
|
|
543
|
+
int elembits() const;
|
|
544
|
+
|
|
545
|
+
// shape only
|
|
546
|
+
Mat shape() const;
|
|
547
|
+
|
|
548
|
+
// low-level reference
|
|
549
|
+
VkImage image() const;
|
|
550
|
+
VkImageView imageview() const;
|
|
551
|
+
|
|
552
|
+
#if NCNN_PLATFORM_API
|
|
553
|
+
#if __ANDROID_API__ >= 26
|
|
554
|
+
// convenient construct from android hardware buffer
|
|
555
|
+
static VkImageMat from_android_hardware_buffer(VkAndroidHardwareBufferImageAllocator* allocator);
|
|
556
|
+
#endif // __ANDROID_API__ >= 26
|
|
557
|
+
#endif // NCNN_PLATFORM_API
|
|
558
|
+
|
|
559
|
+
// device image
|
|
560
|
+
VkImageMemory* data;
|
|
561
|
+
|
|
562
|
+
// pointer to the reference counter
|
|
563
|
+
// when points to user-allocated data, the pointer is NULL
|
|
564
|
+
int* refcount;
|
|
565
|
+
|
|
566
|
+
// element size in bytes
|
|
567
|
+
// 4 = float32/int32
|
|
568
|
+
// 2 = float16
|
|
569
|
+
// 1 = int8/uint8
|
|
570
|
+
// 0 = empty
|
|
571
|
+
size_t elemsize;
|
|
572
|
+
|
|
573
|
+
// packed count inside element
|
|
574
|
+
// c/1-d-h-w-1 c/1-h-w-1 h/1-w-1 w/1-1 scalar
|
|
575
|
+
// c/4-d-h-w-4 c/4-h-w-4 h/4-w-4 w/4-4 sse/neon
|
|
576
|
+
// c/8-d-h-w-8 c/8-h-w-8 h/8-w-8 w/8-8 avx/fp16
|
|
577
|
+
int elempack;
|
|
578
|
+
|
|
579
|
+
// the allocator
|
|
580
|
+
VkAllocator* allocator;
|
|
581
|
+
|
|
582
|
+
// the dimension rank
|
|
583
|
+
int dims;
|
|
584
|
+
|
|
585
|
+
int w;
|
|
586
|
+
int h;
|
|
587
|
+
int d;
|
|
588
|
+
int c;
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// type for vulkan specialization constant and push constant
|
|
592
|
+
union vk_specialization_type
|
|
593
|
+
{
|
|
594
|
+
int i;
|
|
595
|
+
float f;
|
|
596
|
+
uint32_t u32;
|
|
597
|
+
};
|
|
598
|
+
union vk_constant_type
|
|
599
|
+
{
|
|
600
|
+
int i;
|
|
601
|
+
float f;
|
|
602
|
+
uint32_t u32;
|
|
603
|
+
};
|
|
604
|
+
#endif // NCNN_VULKAN
|
|
605
|
+
|
|
606
|
+
// misc function
|
|
607
|
+
#if NCNN_PIXEL
|
|
608
|
+
// convert yuv420sp(nv21) to rgb, the fast approximate version
|
|
609
|
+
NCNN_EXPORT void yuv420sp2rgb(const unsigned char* yuv420sp, int w, int h, unsigned char* rgb);
|
|
610
|
+
// convert yuv420sp(nv12) to rgb, the fast approximate version
|
|
611
|
+
NCNN_EXPORT void yuv420sp2rgb_nv12(const unsigned char* yuv420sp, int w, int h, unsigned char* rgb);
|
|
612
|
+
// convert yuv420sp(nv21) to rgb with half resize, the faster approximate version
|
|
613
|
+
NCNN_EXPORT void yuv420sp2rgb_half(const unsigned char* yuv420sp, int w, int h, unsigned char* rgb);
|
|
614
|
+
// image pixel bilinear resize
|
|
615
|
+
NCNN_EXPORT void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h);
|
|
616
|
+
NCNN_EXPORT void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h);
|
|
617
|
+
NCNN_EXPORT void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h);
|
|
618
|
+
NCNN_EXPORT void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h);
|
|
619
|
+
// image pixel bilinear resize with stride(bytes-per-row) parameter
|
|
620
|
+
NCNN_EXPORT void resize_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride);
|
|
621
|
+
NCNN_EXPORT void resize_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride);
|
|
622
|
+
NCNN_EXPORT void resize_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride);
|
|
623
|
+
NCNN_EXPORT void resize_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride);
|
|
624
|
+
// image pixel bilinear resize, convenient wrapper for yuv420sp(nv21/nv12)
|
|
625
|
+
NCNN_EXPORT void resize_bilinear_yuv420sp(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h);
|
|
626
|
+
#endif // NCNN_PIXEL
|
|
627
|
+
#if NCNN_PIXEL_ROTATE
|
|
628
|
+
// type is the from type, 6 means rotating from 6 to 1
|
|
629
|
+
//
|
|
630
|
+
// 1 2 3 4 5 6 7 8
|
|
631
|
+
//
|
|
632
|
+
// 888888 888888 88 88 8888888888 88 88 8888888888
|
|
633
|
+
// 88 88 88 88 88 88 88 88 88 88 88 88
|
|
634
|
+
// 8888 8888 8888 8888 88 8888888888 8888888888 88
|
|
635
|
+
// 88 88 88 88
|
|
636
|
+
// 88 88 888888 888888
|
|
637
|
+
//
|
|
638
|
+
// ref http://sylvana.net/jpegcrop/exif_orientation.html
|
|
639
|
+
// image pixel kanna rotate
|
|
640
|
+
NCNN_EXPORT void kanna_rotate_c1(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
|
|
641
|
+
NCNN_EXPORT void kanna_rotate_c2(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
|
|
642
|
+
NCNN_EXPORT void kanna_rotate_c3(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
|
|
643
|
+
NCNN_EXPORT void kanna_rotate_c4(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
|
|
644
|
+
// image pixel kanna rotate with stride(bytes-per-row) parameter
|
|
645
|
+
NCNN_EXPORT void kanna_rotate_c1(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type);
|
|
646
|
+
NCNN_EXPORT void kanna_rotate_c2(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type);
|
|
647
|
+
NCNN_EXPORT void kanna_rotate_c3(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type);
|
|
648
|
+
NCNN_EXPORT void kanna_rotate_c4(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, int type);
|
|
649
|
+
// image pixel kanna rotate, convenient wrapper for yuv420sp(nv21/nv12)
|
|
650
|
+
NCNN_EXPORT void kanna_rotate_yuv420sp(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
|
|
651
|
+
#endif // NCNN_PIXEL_ROTATE
|
|
652
|
+
#if NCNN_PIXEL_AFFINE
|
|
653
|
+
// resolve affine transform matrix from rotation angle, scale factor and x y offset
|
|
654
|
+
NCNN_EXPORT void get_rotation_matrix(float angle, float scale, float dx, float dy, float* tm);
|
|
655
|
+
// resolve affine transform matrix from two set of points, num_point must be >= 2
|
|
656
|
+
NCNN_EXPORT void get_affine_transform(const float* points_from, const float* points_to, int num_point, float* tm);
|
|
657
|
+
// resolve the inversion affine transform matrix
|
|
658
|
+
NCNN_EXPORT void invert_affine_transform(const float* tm, float* tm_inv);
|
|
659
|
+
// image pixel bilinear warpaffine inverse transform, set -233 for transparent border color, the color RGBA is little-endian encoded
|
|
660
|
+
NCNN_EXPORT void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int type = 0, unsigned int v = 0);
|
|
661
|
+
NCNN_EXPORT void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int type = 0, unsigned int v = 0);
|
|
662
|
+
NCNN_EXPORT void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int type = 0, unsigned int v = 0);
|
|
663
|
+
NCNN_EXPORT void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int type = 0, unsigned int v = 0);
|
|
664
|
+
// image pixel bilinear warpaffine inverse transform with stride(bytes-per-row) parameter, set -233 for transparent border color, the color RGBA is little-endian encoded
|
|
665
|
+
NCNN_EXPORT void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int type = 0, unsigned int v = 0);
|
|
666
|
+
NCNN_EXPORT void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int type = 0, unsigned int v = 0);
|
|
667
|
+
NCNN_EXPORT void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int type = 0, unsigned int v = 0);
|
|
668
|
+
NCNN_EXPORT void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int type = 0, unsigned int v = 0);
|
|
669
|
+
// image pixel bilinear warpaffine, convenient wrapper for yuv420sp(nv21/nv12), set -233 for transparent border color, the color YUV_ is little-endian encoded
|
|
670
|
+
NCNN_EXPORT void warpaffine_bilinear_yuv420sp(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int type = 0, unsigned int v = 0);
|
|
671
|
+
#endif // NCNN_PIXEL_AFFINE
|
|
672
|
+
#if NCNN_PIXEL_DRAWING
|
|
673
|
+
// draw rectangle, set thickness -1 for filled rectangle, the color RGBA is little-endian encoded
|
|
674
|
+
NCNN_EXPORT void draw_rectangle_c1(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
675
|
+
NCNN_EXPORT void draw_rectangle_c2(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
676
|
+
NCNN_EXPORT void draw_rectangle_c3(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
677
|
+
NCNN_EXPORT void draw_rectangle_c4(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
678
|
+
// draw rectangle with stride(bytes-per-row) parameter, set thickness -1 for filled rectangle, the color RGBA is little-endian encoded
|
|
679
|
+
NCNN_EXPORT void draw_rectangle_c1(unsigned char* pixels, int w, int h, int stride, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
680
|
+
NCNN_EXPORT void draw_rectangle_c2(unsigned char* pixels, int w, int h, int stride, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
681
|
+
NCNN_EXPORT void draw_rectangle_c3(unsigned char* pixels, int w, int h, int stride, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
682
|
+
NCNN_EXPORT void draw_rectangle_c4(unsigned char* pixels, int w, int h, int stride, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
683
|
+
// draw rectangle, convenient wrapper for yuv420sp(nv21/nv12), set thickness -1 for filled rectangle, the color YUV_ is little-endian encoded
|
|
684
|
+
NCNN_EXPORT void draw_rectangle_yuv420sp(unsigned char* yuv420sp, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness);
|
|
685
|
+
// draw circle, set thickness -1 for filled circle, the color RGBA is little-endian encoded
|
|
686
|
+
NCNN_EXPORT void draw_circle_c1(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
687
|
+
NCNN_EXPORT void draw_circle_c2(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
688
|
+
NCNN_EXPORT void draw_circle_c3(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
689
|
+
NCNN_EXPORT void draw_circle_c4(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
690
|
+
// draw circle with stride(bytes-per-row) parameter, set thickness -1 for filled circle, the color RGBA is little-endian encoded
|
|
691
|
+
NCNN_EXPORT void draw_circle_c1(unsigned char* pixels, int w, int h, int stride, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
692
|
+
NCNN_EXPORT void draw_circle_c2(unsigned char* pixels, int w, int h, int stride, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
693
|
+
NCNN_EXPORT void draw_circle_c3(unsigned char* pixels, int w, int h, int stride, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
694
|
+
NCNN_EXPORT void draw_circle_c4(unsigned char* pixels, int w, int h, int stride, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
695
|
+
// draw circle, convenient wrapper for yuv420sp(nv21/nv12), set thickness -1 for filled circle, the color YUV_ is little-endian encoded
|
|
696
|
+
NCNN_EXPORT void draw_circle_yuv420sp(unsigned char* yuv420sp, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness);
|
|
697
|
+
// draw line, the color RGBA is little-endian encoded
|
|
698
|
+
NCNN_EXPORT void draw_line_c1(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
699
|
+
NCNN_EXPORT void draw_line_c2(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
700
|
+
NCNN_EXPORT void draw_line_c3(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
701
|
+
NCNN_EXPORT void draw_line_c4(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
702
|
+
// draw line with stride(bytes-per-row) parameter, the color RGBA is little-endian encoded
|
|
703
|
+
NCNN_EXPORT void draw_line_c1(unsigned char* pixels, int w, int h, int stride, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
704
|
+
NCNN_EXPORT void draw_line_c2(unsigned char* pixels, int w, int h, int stride, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
705
|
+
NCNN_EXPORT void draw_line_c3(unsigned char* pixels, int w, int h, int stride, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
706
|
+
NCNN_EXPORT void draw_line_c4(unsigned char* pixels, int w, int h, int stride, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
707
|
+
// draw line, convenient wrapper for yuv420sp(nv21/nv12), the color YUV_ is little-endian encoded
|
|
708
|
+
NCNN_EXPORT void draw_line_yuv420sp(unsigned char* yuv420sp, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness);
|
|
709
|
+
// resolve text bounding box size
|
|
710
|
+
NCNN_EXPORT void get_text_drawing_size(const char* text, int fontpixelsize, int* w, int* h);
|
|
711
|
+
// draw ascii printables and newline, the color RGBA is little-endian encoded
|
|
712
|
+
NCNN_EXPORT void draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
713
|
+
NCNN_EXPORT void draw_text_c2(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
714
|
+
NCNN_EXPORT void draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
715
|
+
NCNN_EXPORT void draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
716
|
+
// draw ascii printables and newline with stride(bytes-per-row) parameter, the color RGBA is little-endian encoded
|
|
717
|
+
NCNN_EXPORT void draw_text_c1(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
718
|
+
NCNN_EXPORT void draw_text_c2(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
719
|
+
NCNN_EXPORT void draw_text_c3(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
720
|
+
NCNN_EXPORT void draw_text_c4(unsigned char* pixels, int w, int h, int stride, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
721
|
+
// draw ascii printables and newline, convenient wrapper for yuv420sp(nv21/nv12), the color YUV_ is little-endian encoded
|
|
722
|
+
NCNN_EXPORT void draw_text_yuv420sp(unsigned char* yuv420sp, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color);
|
|
723
|
+
#endif // NCNN_PIXEL_DRAWING
|
|
724
|
+
|
|
725
|
+
// type conversion
|
|
726
|
+
// convert float to half precision floating point
|
|
727
|
+
NCNN_EXPORT unsigned short float32_to_float16(float value);
|
|
728
|
+
// convert half precision floating point to float
|
|
729
|
+
NCNN_EXPORT float float16_to_float32(unsigned short value);
|
|
730
|
+
// convert float to brain half
|
|
731
|
+
NCNN_EXPORT NCNN_FORCEINLINE unsigned short float32_to_bfloat16(float value)
|
|
732
|
+
{
|
|
733
|
+
// 16 : 16
|
|
734
|
+
union
|
|
735
|
+
{
|
|
736
|
+
unsigned int u;
|
|
737
|
+
float f;
|
|
738
|
+
} tmp;
|
|
739
|
+
tmp.f = value;
|
|
740
|
+
return tmp.u >> 16;
|
|
741
|
+
}
|
|
742
|
+
// convert brain half to float
|
|
743
|
+
NCNN_EXPORT NCNN_FORCEINLINE float bfloat16_to_float32(unsigned short value)
|
|
744
|
+
{
|
|
745
|
+
// 16 : 16
|
|
746
|
+
union
|
|
747
|
+
{
|
|
748
|
+
unsigned int u;
|
|
749
|
+
float f;
|
|
750
|
+
} tmp;
|
|
751
|
+
tmp.u = value << 16;
|
|
752
|
+
return tmp.f;
|
|
753
|
+
}
|
|
754
|
+
// convert float16 to float8 e4m3
|
|
755
|
+
NCNN_EXPORT unsigned char float16_to_float8(unsigned short value);
|
|
756
|
+
// convert float8 e4m3 to float16
|
|
757
|
+
NCNN_EXPORT unsigned short float8_to_float16(unsigned char value);
|
|
758
|
+
// convert float16 to bfloat8 e5m2
|
|
759
|
+
NCNN_EXPORT NCNN_FORCEINLINE unsigned char float16_to_bfloat8(unsigned short value)
|
|
760
|
+
{
|
|
761
|
+
// 1 : 5 : 10 -> 1 : 5 : 2
|
|
762
|
+
// direct truncation for bfloat8 e5m2, similar to bfloat16
|
|
763
|
+
return value >> 8;
|
|
764
|
+
}
|
|
765
|
+
// convert bfloat8 e5m2 to float16
|
|
766
|
+
NCNN_EXPORT NCNN_FORCEINLINE unsigned short bfloat8_to_float16(unsigned char value)
|
|
767
|
+
{
|
|
768
|
+
// 1 : 5 : 2 -> 1 : 5 : 10
|
|
769
|
+
// direct extension for bfloat8 e5m2, similar to bfloat16
|
|
770
|
+
return value << 8;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// mat process
|
|
774
|
+
enum BorderType
|
|
775
|
+
{
|
|
776
|
+
BORDER_CONSTANT = 0,
|
|
777
|
+
BORDER_REPLICATE = 1,
|
|
778
|
+
BORDER_REFLECT = 2,
|
|
779
|
+
BORDER_TRANSPARENT = -233,
|
|
780
|
+
};
|
|
781
|
+
NCNN_EXPORT void copy_make_border(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int type, float v, const Option& opt = Option());
|
|
782
|
+
NCNN_EXPORT void copy_make_border_3d(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int front, int behind, int type, float v, const Option& opt = Option());
|
|
783
|
+
NCNN_EXPORT void copy_cut_border(const Mat& src, Mat& dst, int top, int bottom, int left, int right, const Option& opt = Option());
|
|
784
|
+
NCNN_EXPORT void copy_cut_border_3d(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int front, int behind, const Option& opt = Option());
|
|
785
|
+
NCNN_EXPORT void resize_nearest(const Mat& src, Mat& dst, int w, int h, const Option& opt = Option());
|
|
786
|
+
NCNN_EXPORT void resize_bilinear(const Mat& src, Mat& dst, int w, int h, const Option& opt = Option());
|
|
787
|
+
NCNN_EXPORT void resize_bicubic(const Mat& src, Mat& dst, int w, int h, const Option& opt = Option());
|
|
788
|
+
NCNN_EXPORT void convert_packing(const Mat& src, Mat& dst, int elempack, const Option& opt = Option());
|
|
789
|
+
NCNN_EXPORT void flatten(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
790
|
+
NCNN_EXPORT void cast_float32_to_float16(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
791
|
+
NCNN_EXPORT void cast_float16_to_float32(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
792
|
+
NCNN_EXPORT void cast_int8_to_float32(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
793
|
+
NCNN_EXPORT void cast_float32_to_bfloat16(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
794
|
+
NCNN_EXPORT void cast_bfloat16_to_float32(const Mat& src, Mat& dst, const Option& opt = Option());
|
|
795
|
+
NCNN_EXPORT void quantize_to_int8(const Mat& src, Mat& dst, const Mat& scale_data, const Option& opt = Option());
|
|
796
|
+
NCNN_EXPORT void dequantize_from_int32(const Mat& src, Mat& dst, const Mat& scale_data, const Mat& bias_data, const Option& opt = Option());
|
|
797
|
+
NCNN_EXPORT void requantize_from_int32_to_int8(const Mat& src, Mat& dst, const Mat& scale_in_data, const Mat& scale_out_data, const Mat& bias_data, int activation_type, const Mat& activation_params, const Option& opt = Option());
|
|
798
|
+
|
|
799
|
+
NCNN_FORCEINLINE Mat::Mat()
|
|
800
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
801
|
+
{
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, size_t _elemsize, Allocator* _allocator)
|
|
805
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
806
|
+
{
|
|
807
|
+
create(_w, _elemsize, _allocator);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, size_t _elemsize, Allocator* _allocator)
|
|
811
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
812
|
+
{
|
|
813
|
+
create(_w, _h, _elemsize, _allocator);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _c, size_t _elemsize, Allocator* _allocator)
|
|
817
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
818
|
+
{
|
|
819
|
+
create(_w, _h, _c, _elemsize, _allocator);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _d, int _c, size_t _elemsize, Allocator* _allocator)
|
|
823
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
824
|
+
{
|
|
825
|
+
create(_w, _h, _d, _c, _elemsize, _allocator);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
829
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
830
|
+
{
|
|
831
|
+
create(_w, _elemsize, _elempack, _allocator);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
835
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
836
|
+
{
|
|
837
|
+
create(_w, _h, _elemsize, _elempack, _allocator);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _c, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
841
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
842
|
+
{
|
|
843
|
+
create(_w, _h, _c, _elemsize, _elempack, _allocator);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _d, int _c, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
847
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
848
|
+
{
|
|
849
|
+
create(_w, _h, _d, _c, _elemsize, _elempack, _allocator);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
NCNN_FORCEINLINE Mat::Mat(const Mat& m)
|
|
853
|
+
: data(m.data), refcount(m.refcount), elemsize(m.elemsize), elempack(m.elempack), allocator(m.allocator), dims(m.dims), w(m.w), h(m.h), d(m.d), c(m.c), cstep(m.cstep)
|
|
854
|
+
{
|
|
855
|
+
addref();
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, void* _data, size_t _elemsize, Allocator* _allocator)
|
|
859
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
860
|
+
{
|
|
861
|
+
cstep = alignSize(w * elemsize, 16) / elemsize;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, void* _data, size_t _elemsize, Allocator* _allocator)
|
|
865
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
866
|
+
{
|
|
867
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _c, void* _data, size_t _elemsize, Allocator* _allocator)
|
|
871
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
872
|
+
{
|
|
873
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _d, int _c, void* _data, size_t _elemsize, Allocator* _allocator)
|
|
877
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
878
|
+
{
|
|
879
|
+
cstep = alignSize((size_t)w * h * d * elemsize, 16) / elemsize;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, void* _data, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
883
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
884
|
+
{
|
|
885
|
+
cstep = alignSize(w * elemsize, 16) / elemsize;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, void* _data, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
889
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
890
|
+
{
|
|
891
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _c, void* _data, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
895
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
896
|
+
{
|
|
897
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _d, int _c, void* _data, size_t _elemsize, int _elempack, Allocator* _allocator)
|
|
901
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
902
|
+
{
|
|
903
|
+
cstep = alignSize((size_t)w * h * d * elemsize, 16) / elemsize;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
NCNN_FORCEINLINE Mat::~Mat()
|
|
907
|
+
{
|
|
908
|
+
release();
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
NCNN_FORCEINLINE void Mat::fill(float _v)
|
|
912
|
+
{
|
|
913
|
+
int size = (int)total();
|
|
914
|
+
float* ptr = (float*)data;
|
|
915
|
+
|
|
916
|
+
int i = 0;
|
|
917
|
+
#if __ARM_NEON
|
|
918
|
+
float32x4_t _c = vdupq_n_f32(_v);
|
|
919
|
+
for (; i + 3 < size; i += 4)
|
|
920
|
+
{
|
|
921
|
+
vst1q_f32(ptr, _c);
|
|
922
|
+
ptr += 4;
|
|
923
|
+
}
|
|
924
|
+
#endif // __ARM_NEON
|
|
925
|
+
for (; i < size; i++)
|
|
926
|
+
{
|
|
927
|
+
*ptr++ = _v;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
NCNN_FORCEINLINE void Mat::fill(int _v)
|
|
932
|
+
{
|
|
933
|
+
int size = (int)total();
|
|
934
|
+
int* ptr = (int*)data;
|
|
935
|
+
|
|
936
|
+
int i = 0;
|
|
937
|
+
#if __ARM_NEON
|
|
938
|
+
int32x4_t _c = vdupq_n_s32(_v);
|
|
939
|
+
for (; i + 3 < size; i += 4)
|
|
940
|
+
{
|
|
941
|
+
vst1q_s32(ptr, _c);
|
|
942
|
+
ptr += 4;
|
|
943
|
+
}
|
|
944
|
+
#endif // __ARM_NEON
|
|
945
|
+
for (; i < size; i++)
|
|
946
|
+
{
|
|
947
|
+
*ptr++ = _v;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
#if __ARM_NEON
|
|
952
|
+
NCNN_FORCEINLINE void Mat::fill(float32x4_t _v)
|
|
953
|
+
{
|
|
954
|
+
int size = (int)total();
|
|
955
|
+
float* ptr = (float*)data;
|
|
956
|
+
for (int i = 0; i < size; i++)
|
|
957
|
+
{
|
|
958
|
+
vst1q_f32(ptr, _v);
|
|
959
|
+
ptr += 4;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
NCNN_FORCEINLINE void Mat::fill(uint16x4_t _v)
|
|
964
|
+
{
|
|
965
|
+
int size = (int)total();
|
|
966
|
+
unsigned short* ptr = (unsigned short*)data;
|
|
967
|
+
for (int i = 0; i < size; i++)
|
|
968
|
+
{
|
|
969
|
+
vst1_u16(ptr, _v);
|
|
970
|
+
ptr += 4;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
#if !defined(_MSC_VER)
|
|
975
|
+
NCNN_FORCEINLINE void Mat::fill(int32x4_t _v)
|
|
976
|
+
{
|
|
977
|
+
int size = (int)total();
|
|
978
|
+
int* ptr = (int*)data;
|
|
979
|
+
for (int i = 0; i < size; i++)
|
|
980
|
+
{
|
|
981
|
+
vst1q_s32(ptr, _v);
|
|
982
|
+
ptr += 4;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
#endif
|
|
986
|
+
|
|
987
|
+
NCNN_FORCEINLINE void Mat::fill(int32x4_t _v0, int32x4_t _v1)
|
|
988
|
+
{
|
|
989
|
+
int size = (int)total();
|
|
990
|
+
int* ptr = (int*)data;
|
|
991
|
+
for (int i = 0; i < size; i++)
|
|
992
|
+
{
|
|
993
|
+
vst1q_s32(ptr, _v0);
|
|
994
|
+
vst1q_s32(ptr + 4, _v1);
|
|
995
|
+
ptr += 8;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
|
|
999
|
+
#if !defined(_MSC_VER)
|
|
1000
|
+
NCNN_FORCEINLINE void Mat::fill(float16x4_t _v)
|
|
1001
|
+
{
|
|
1002
|
+
int size = (int)total();
|
|
1003
|
+
__fp16* ptr = (__fp16*)data;
|
|
1004
|
+
for (int i = 0; i < size; i++)
|
|
1005
|
+
{
|
|
1006
|
+
vst1_f16(ptr, _v);
|
|
1007
|
+
ptr += 4;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
NCNN_FORCEINLINE void Mat::fill(float16x8_t _v)
|
|
1012
|
+
{
|
|
1013
|
+
int size = (int)total();
|
|
1014
|
+
__fp16* ptr = (__fp16*)data;
|
|
1015
|
+
for (int i = 0; i < size; i++)
|
|
1016
|
+
{
|
|
1017
|
+
vst1q_f16(ptr, _v);
|
|
1018
|
+
ptr += 8;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
#endif
|
|
1022
|
+
#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
|
|
1023
|
+
#endif // __ARM_NEON
|
|
1024
|
+
|
|
1025
|
+
#if __SSE2__
|
|
1026
|
+
#if __AVX__
|
|
1027
|
+
#if __AVX512F__
|
|
1028
|
+
NCNN_FORCEINLINE void Mat::fill(const __m512& _v)
|
|
1029
|
+
{
|
|
1030
|
+
int size = (int)total();
|
|
1031
|
+
float* ptr = (float*)data;
|
|
1032
|
+
for (int i = 0; i < size; i++)
|
|
1033
|
+
{
|
|
1034
|
+
_mm512_storeu_ps(ptr, _v);
|
|
1035
|
+
ptr += 16;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
#endif // __AVX512F__
|
|
1039
|
+
NCNN_FORCEINLINE void Mat::fill(const __m256& _v, int _i)
|
|
1040
|
+
{
|
|
1041
|
+
// old gcc cannot overload __m128 and __m256 type
|
|
1042
|
+
// add a dummy int parameter for different mangled function symbol
|
|
1043
|
+
(void)_i;
|
|
1044
|
+
int size = (int)total();
|
|
1045
|
+
float* ptr = (float*)data;
|
|
1046
|
+
for (int i = 0; i < size; i++)
|
|
1047
|
+
{
|
|
1048
|
+
_mm256_storeu_ps(ptr, _v);
|
|
1049
|
+
ptr += 8;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
#endif // __AVX__
|
|
1053
|
+
NCNN_FORCEINLINE void Mat::fill(const __m128& _v)
|
|
1054
|
+
{
|
|
1055
|
+
int size = (int)total();
|
|
1056
|
+
float* ptr = (float*)data;
|
|
1057
|
+
for (int i = 0; i < size; i++)
|
|
1058
|
+
{
|
|
1059
|
+
_mm_storeu_ps(ptr, _v);
|
|
1060
|
+
ptr += 4;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
NCNN_FORCEINLINE void Mat::fill(const __m128i& _v)
|
|
1064
|
+
{
|
|
1065
|
+
int size = (int)total();
|
|
1066
|
+
unsigned short* ptr = (unsigned short*)data;
|
|
1067
|
+
for (int i = 0; i < size; i++)
|
|
1068
|
+
{
|
|
1069
|
+
_mm_store_si128((__m128i*)ptr, _v);
|
|
1070
|
+
ptr += 8;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
#endif // __SSE2__
|
|
1074
|
+
|
|
1075
|
+
#if __mips_msa
|
|
1076
|
+
NCNN_FORCEINLINE void Mat::fill(v4f32 _v)
|
|
1077
|
+
{
|
|
1078
|
+
int size = (int)total();
|
|
1079
|
+
float* ptr = (float*)data;
|
|
1080
|
+
for (int i = 0; i < size; i++)
|
|
1081
|
+
{
|
|
1082
|
+
__msa_st_w((v4i32)_v, ptr, 0);
|
|
1083
|
+
ptr += 4;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
#endif // __mips_msa
|
|
1087
|
+
|
|
1088
|
+
#if __loongarch_sx
|
|
1089
|
+
NCNN_FORCEINLINE void Mat::fill(__m128 _v)
|
|
1090
|
+
{
|
|
1091
|
+
int size = (int)total();
|
|
1092
|
+
float* ptr = (float*)data;
|
|
1093
|
+
for (int i = 0; i < size; i++)
|
|
1094
|
+
{
|
|
1095
|
+
__lsx_vst(_v, ptr, 0);
|
|
1096
|
+
ptr += 4;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
#endif // __loongarch_sx
|
|
1100
|
+
|
|
1101
|
+
#if __riscv_vector
|
|
1102
|
+
NCNN_FORCEINLINE void Mat::fill(vfloat32m1_t _v)
|
|
1103
|
+
{
|
|
1104
|
+
const int packn = cpu_riscv_vlenb() / 4;
|
|
1105
|
+
const size_t vl = __riscv_vsetvl_e32m1(packn);
|
|
1106
|
+
|
|
1107
|
+
int size = (int)total();
|
|
1108
|
+
float* ptr = (float*)data;
|
|
1109
|
+
for (int i = 0; i < size; i++)
|
|
1110
|
+
{
|
|
1111
|
+
__riscv_vse32_v_f32m1(ptr, _v, vl);
|
|
1112
|
+
ptr += packn;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
NCNN_FORCEINLINE void Mat::fill(vuint16m1_t _v)
|
|
1117
|
+
{
|
|
1118
|
+
const int packn = cpu_riscv_vlenb() / 2;
|
|
1119
|
+
const size_t vl = __riscv_vsetvl_e16m1(packn);
|
|
1120
|
+
|
|
1121
|
+
int size = (int)total();
|
|
1122
|
+
unsigned short* ptr = (unsigned short*)data;
|
|
1123
|
+
for (int i = 0; i < size; i++)
|
|
1124
|
+
{
|
|
1125
|
+
__riscv_vse16_v_u16m1(ptr, _v, vl);
|
|
1126
|
+
ptr += packn;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
NCNN_FORCEINLINE void Mat::fill(vint8m1_t _v)
|
|
1131
|
+
{
|
|
1132
|
+
const int packn = cpu_riscv_vlenb() / 1;
|
|
1133
|
+
const size_t vl = __riscv_vsetvl_e8m1(packn);
|
|
1134
|
+
|
|
1135
|
+
int size = (int)total();
|
|
1136
|
+
signed char* ptr = (signed char*)data;
|
|
1137
|
+
for (int i = 0; i < size; i++)
|
|
1138
|
+
{
|
|
1139
|
+
__riscv_vse8_v_i8m1(ptr, _v, vl);
|
|
1140
|
+
ptr += packn;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
#if __riscv_zvfh
|
|
1144
|
+
NCNN_FORCEINLINE void Mat::fill(vfloat16m1_t _v)
|
|
1145
|
+
{
|
|
1146
|
+
const int packn = cpu_riscv_vlenb() / 2;
|
|
1147
|
+
const size_t vl = __riscv_vsetvl_e16m1(packn);
|
|
1148
|
+
|
|
1149
|
+
int size = (int)total();
|
|
1150
|
+
__fp16* ptr = (__fp16*)data;
|
|
1151
|
+
for (int i = 0; i < size; i++)
|
|
1152
|
+
{
|
|
1153
|
+
__riscv_vse16_v_f16m1(ptr, _v, vl);
|
|
1154
|
+
ptr += packn;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
#endif // __riscv_zvfh
|
|
1158
|
+
#endif // __riscv_vector
|
|
1159
|
+
|
|
1160
|
+
template<typename T>
|
|
1161
|
+
NCNN_FORCEINLINE void Mat::fill(T _v)
|
|
1162
|
+
{
|
|
1163
|
+
int size = (int)total();
|
|
1164
|
+
T* ptr = (T*)data;
|
|
1165
|
+
for (int i = 0; i < size; i++)
|
|
1166
|
+
{
|
|
1167
|
+
ptr[i] = _v;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
NCNN_FORCEINLINE Mat& Mat::operator=(const Mat& m)
|
|
1172
|
+
{
|
|
1173
|
+
if (this == &m)
|
|
1174
|
+
return *this;
|
|
1175
|
+
|
|
1176
|
+
if (m.refcount)
|
|
1177
|
+
NCNN_XADD(m.refcount, 1);
|
|
1178
|
+
|
|
1179
|
+
release();
|
|
1180
|
+
|
|
1181
|
+
data = m.data;
|
|
1182
|
+
refcount = m.refcount;
|
|
1183
|
+
elemsize = m.elemsize;
|
|
1184
|
+
elempack = m.elempack;
|
|
1185
|
+
allocator = m.allocator;
|
|
1186
|
+
|
|
1187
|
+
dims = m.dims;
|
|
1188
|
+
w = m.w;
|
|
1189
|
+
h = m.h;
|
|
1190
|
+
d = m.d;
|
|
1191
|
+
c = m.c;
|
|
1192
|
+
|
|
1193
|
+
cstep = m.cstep;
|
|
1194
|
+
|
|
1195
|
+
return *this;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
NCNN_FORCEINLINE void Mat::addref()
|
|
1199
|
+
{
|
|
1200
|
+
if (refcount)
|
|
1201
|
+
NCNN_XADD(refcount, 1);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
NCNN_FORCEINLINE void Mat::release()
|
|
1205
|
+
{
|
|
1206
|
+
if (refcount && NCNN_XADD(refcount, -1) == 1)
|
|
1207
|
+
{
|
|
1208
|
+
if (allocator)
|
|
1209
|
+
allocator->fastFree(data);
|
|
1210
|
+
else
|
|
1211
|
+
fastFree(data);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
data = 0;
|
|
1215
|
+
|
|
1216
|
+
elemsize = 0;
|
|
1217
|
+
elempack = 0;
|
|
1218
|
+
|
|
1219
|
+
dims = 0;
|
|
1220
|
+
w = 0;
|
|
1221
|
+
h = 0;
|
|
1222
|
+
d = 0;
|
|
1223
|
+
c = 0;
|
|
1224
|
+
|
|
1225
|
+
cstep = 0;
|
|
1226
|
+
|
|
1227
|
+
refcount = 0;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
NCNN_FORCEINLINE bool Mat::empty() const
|
|
1231
|
+
{
|
|
1232
|
+
return data == 0 || total() == 0;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
NCNN_FORCEINLINE size_t Mat::total() const
|
|
1236
|
+
{
|
|
1237
|
+
return cstep * c;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
NCNN_FORCEINLINE int Mat::elembits() const
|
|
1241
|
+
{
|
|
1242
|
+
return elempack ? static_cast<int>(elemsize * 8) / elempack : 0;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
NCNN_FORCEINLINE Mat Mat::shape() const
|
|
1246
|
+
{
|
|
1247
|
+
if (dims == 1)
|
|
1248
|
+
return Mat(w * elempack, (void*)0);
|
|
1249
|
+
if (dims == 2)
|
|
1250
|
+
return Mat(w, h * elempack, (void*)0);
|
|
1251
|
+
if (dims == 3)
|
|
1252
|
+
return Mat(w, h, c * elempack, (void*)0);
|
|
1253
|
+
if (dims == 4)
|
|
1254
|
+
return Mat(w, h, d, c * elempack, (void*)0);
|
|
1255
|
+
|
|
1256
|
+
return Mat();
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
NCNN_FORCEINLINE Mat Mat::channel(int _c)
|
|
1260
|
+
{
|
|
1261
|
+
Mat m(w, h, d, (unsigned char*)data + cstep * _c * elemsize, elemsize, elempack, allocator);
|
|
1262
|
+
m.dims = dims - 1;
|
|
1263
|
+
if (dims == 4)
|
|
1264
|
+
m.cstep = (size_t)w * h;
|
|
1265
|
+
return m;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
NCNN_FORCEINLINE const Mat Mat::channel(int _c) const
|
|
1269
|
+
{
|
|
1270
|
+
Mat m(w, h, d, (unsigned char*)data + cstep * _c * elemsize, elemsize, elempack, allocator);
|
|
1271
|
+
m.dims = dims - 1;
|
|
1272
|
+
if (dims == 4)
|
|
1273
|
+
m.cstep = (size_t)w * h;
|
|
1274
|
+
return m;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
NCNN_FORCEINLINE Mat Mat::depth(int z)
|
|
1278
|
+
{
|
|
1279
|
+
Mat m(w, h, (unsigned char*)data + (size_t)w * h * z * elemsize, elemsize, elempack, allocator);
|
|
1280
|
+
m.cstep = (size_t)w * h;
|
|
1281
|
+
return m;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
NCNN_FORCEINLINE const Mat Mat::depth(int z) const
|
|
1285
|
+
{
|
|
1286
|
+
Mat m(w, h, (unsigned char*)data + (size_t)w * h * z * elemsize, elemsize, elempack, allocator);
|
|
1287
|
+
m.cstep = (size_t)w * h;
|
|
1288
|
+
return m;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
NCNN_FORCEINLINE float* Mat::row(int y)
|
|
1292
|
+
{
|
|
1293
|
+
return (float*)((unsigned char*)data + (size_t)w * y * elemsize);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
NCNN_FORCEINLINE const float* Mat::row(int y) const
|
|
1297
|
+
{
|
|
1298
|
+
return (const float*)((unsigned char*)data + (size_t)w * y * elemsize);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
template<typename T>
|
|
1302
|
+
NCNN_FORCEINLINE T* Mat::row(int y)
|
|
1303
|
+
{
|
|
1304
|
+
return (T*)((unsigned char*)data + (size_t)w * y * elemsize);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
template<typename T>
|
|
1308
|
+
NCNN_FORCEINLINE const T* Mat::row(int y) const
|
|
1309
|
+
{
|
|
1310
|
+
return (const T*)((unsigned char*)data + (size_t)w * y * elemsize);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
NCNN_FORCEINLINE Mat Mat::channel_range(int _c, int channels)
|
|
1314
|
+
{
|
|
1315
|
+
Mat m(w, h, d, channels, (unsigned char*)data + cstep * _c * elemsize, elemsize, elempack, allocator);
|
|
1316
|
+
m.dims = dims;
|
|
1317
|
+
return m;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
NCNN_FORCEINLINE const Mat Mat::channel_range(int _c, int channels) const
|
|
1321
|
+
{
|
|
1322
|
+
Mat m(w, h, d, channels, (unsigned char*)data + cstep * _c * elemsize, elemsize, elempack, allocator);
|
|
1323
|
+
m.dims = dims;
|
|
1324
|
+
return m;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
NCNN_FORCEINLINE Mat Mat::depth_range(int z, int depths)
|
|
1328
|
+
{
|
|
1329
|
+
Mat m(w, h, depths, (unsigned char*)data + (size_t)w * h * z * elemsize, elemsize, elempack, allocator);
|
|
1330
|
+
m.cstep = (size_t)w * h;
|
|
1331
|
+
return m;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
NCNN_FORCEINLINE const Mat Mat::depth_range(int z, int depths) const
|
|
1335
|
+
{
|
|
1336
|
+
Mat m(w, h, depths, (unsigned char*)data + (size_t)w * h * z * elemsize, elemsize, elempack, allocator);
|
|
1337
|
+
m.cstep = (size_t)w * h;
|
|
1338
|
+
return m;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
NCNN_FORCEINLINE Mat Mat::row_range(int y, int rows)
|
|
1342
|
+
{
|
|
1343
|
+
Mat m(w, rows, (unsigned char*)data + (size_t)w * y * elemsize, elemsize, elempack, allocator);
|
|
1344
|
+
m.cstep = (size_t)w * rows;
|
|
1345
|
+
return m;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
NCNN_FORCEINLINE const Mat Mat::row_range(int y, int rows) const
|
|
1349
|
+
{
|
|
1350
|
+
Mat m(w, rows, (unsigned char*)data + (size_t)w * y * elemsize, elemsize, elempack, allocator);
|
|
1351
|
+
m.cstep = (size_t)w * rows;
|
|
1352
|
+
return m;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
NCNN_FORCEINLINE Mat Mat::range(int x, int n)
|
|
1356
|
+
{
|
|
1357
|
+
Mat m(n, (unsigned char*)data + x * elemsize, elemsize, elempack, allocator);
|
|
1358
|
+
m.cstep = (size_t)n;
|
|
1359
|
+
return m;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
NCNN_FORCEINLINE const Mat Mat::range(int x, int n) const
|
|
1363
|
+
{
|
|
1364
|
+
Mat m(n, (unsigned char*)data + x * elemsize, elemsize, elempack, allocator);
|
|
1365
|
+
m.cstep = (size_t)n;
|
|
1366
|
+
return m;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
template<typename T>
|
|
1370
|
+
NCNN_FORCEINLINE Mat::operator T*()
|
|
1371
|
+
{
|
|
1372
|
+
return (T*)data;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
template<typename T>
|
|
1376
|
+
NCNN_FORCEINLINE Mat::operator const T*() const
|
|
1377
|
+
{
|
|
1378
|
+
return (const T*)data;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
NCNN_FORCEINLINE float& Mat::operator[](size_t i)
|
|
1382
|
+
{
|
|
1383
|
+
return ((float*)data)[i];
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
NCNN_FORCEINLINE const float& Mat::operator[](size_t i) const
|
|
1387
|
+
{
|
|
1388
|
+
return ((const float*)data)[i];
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
#if NCNN_VULKAN
|
|
1392
|
+
|
|
1393
|
+
NCNN_FORCEINLINE VkMat::VkMat()
|
|
1394
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1395
|
+
{
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, size_t _elemsize, VkAllocator* _allocator)
|
|
1399
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1400
|
+
{
|
|
1401
|
+
create(_w, _elemsize, _allocator);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, size_t _elemsize, VkAllocator* _allocator)
|
|
1405
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1406
|
+
{
|
|
1407
|
+
create(_w, _h, _elemsize, _allocator);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _c, size_t _elemsize, VkAllocator* _allocator)
|
|
1411
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1412
|
+
{
|
|
1413
|
+
create(_w, _h, _c, _elemsize, _allocator);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _d, int _c, size_t _elemsize, VkAllocator* _allocator)
|
|
1417
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1418
|
+
{
|
|
1419
|
+
create(_w, _h, _d, _c, _elemsize, _allocator);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1423
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1424
|
+
{
|
|
1425
|
+
create(_w, _elemsize, _elempack, _allocator);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1429
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1430
|
+
{
|
|
1431
|
+
create(_w, _h, _elemsize, _elempack, _allocator);
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _c, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1435
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1436
|
+
{
|
|
1437
|
+
create(_w, _h, _c, _elemsize, _elempack, _allocator);
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _d, int _c, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1441
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
|
|
1442
|
+
{
|
|
1443
|
+
create(_w, _h, _d, _c, _elemsize, _elempack, _allocator);
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
NCNN_FORCEINLINE VkMat::VkMat(const VkMat& m)
|
|
1447
|
+
: data(m.data), refcount(m.refcount), elemsize(m.elemsize), elempack(m.elempack), allocator(m.allocator), dims(m.dims), w(m.w), h(m.h), d(m.d), c(m.c)
|
|
1448
|
+
{
|
|
1449
|
+
addref();
|
|
1450
|
+
|
|
1451
|
+
cstep = m.cstep;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, VkBufferMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1455
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
1456
|
+
{
|
|
1457
|
+
cstep = alignSize(w * elemsize, 16) / elemsize;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, VkBufferMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1461
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
1462
|
+
{
|
|
1463
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _c, VkBufferMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1467
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
1468
|
+
{
|
|
1469
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _d, int _c, VkBufferMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1473
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
1474
|
+
{
|
|
1475
|
+
cstep = alignSize((size_t)w * h * d * elemsize, 16) / elemsize;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, VkBufferMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1479
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
1480
|
+
{
|
|
1481
|
+
cstep = alignSize(w * elemsize, 16) / elemsize;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, VkBufferMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1485
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
1486
|
+
{
|
|
1487
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _c, VkBufferMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1491
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
1492
|
+
{
|
|
1493
|
+
cstep = alignSize((size_t)w * h * elemsize, 16) / elemsize;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
NCNN_FORCEINLINE VkMat::VkMat(int _w, int _h, int _d, int _c, VkBufferMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1497
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
1498
|
+
{
|
|
1499
|
+
cstep = alignSize((size_t)w * h * d * elemsize, 16) / elemsize;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
NCNN_FORCEINLINE VkMat::~VkMat()
|
|
1503
|
+
{
|
|
1504
|
+
release();
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
NCNN_FORCEINLINE VkMat& VkMat::operator=(const VkMat& m)
|
|
1508
|
+
{
|
|
1509
|
+
if (this == &m)
|
|
1510
|
+
return *this;
|
|
1511
|
+
|
|
1512
|
+
if (m.refcount)
|
|
1513
|
+
NCNN_XADD(m.refcount, 1);
|
|
1514
|
+
|
|
1515
|
+
release();
|
|
1516
|
+
|
|
1517
|
+
data = m.data;
|
|
1518
|
+
refcount = m.refcount;
|
|
1519
|
+
elemsize = m.elemsize;
|
|
1520
|
+
elempack = m.elempack;
|
|
1521
|
+
allocator = m.allocator;
|
|
1522
|
+
|
|
1523
|
+
dims = m.dims;
|
|
1524
|
+
w = m.w;
|
|
1525
|
+
h = m.h;
|
|
1526
|
+
d = m.d;
|
|
1527
|
+
c = m.c;
|
|
1528
|
+
|
|
1529
|
+
cstep = m.cstep;
|
|
1530
|
+
|
|
1531
|
+
return *this;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
NCNN_FORCEINLINE Mat VkMat::mapped() const
|
|
1535
|
+
{
|
|
1536
|
+
if (!allocator->mappable)
|
|
1537
|
+
return Mat();
|
|
1538
|
+
|
|
1539
|
+
if (dims == 1)
|
|
1540
|
+
return Mat(w, mapped_ptr(), elemsize, elempack, 0);
|
|
1541
|
+
|
|
1542
|
+
if (dims == 2)
|
|
1543
|
+
return Mat(w, h, mapped_ptr(), elemsize, elempack, 0);
|
|
1544
|
+
|
|
1545
|
+
if (dims == 3)
|
|
1546
|
+
return Mat(w, h, c, mapped_ptr(), elemsize, elempack, 0);
|
|
1547
|
+
|
|
1548
|
+
if (dims == 4)
|
|
1549
|
+
return Mat(w, h, d, c, mapped_ptr(), elemsize, elempack, 0);
|
|
1550
|
+
|
|
1551
|
+
return Mat();
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
NCNN_FORCEINLINE void* VkMat::mapped_ptr() const
|
|
1555
|
+
{
|
|
1556
|
+
if (!allocator->mappable)
|
|
1557
|
+
return 0;
|
|
1558
|
+
|
|
1559
|
+
return (unsigned char*)data->mapped_ptr + data->offset;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
NCNN_FORCEINLINE void VkMat::addref()
|
|
1563
|
+
{
|
|
1564
|
+
if (refcount)
|
|
1565
|
+
NCNN_XADD(refcount, 1);
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
NCNN_FORCEINLINE void VkMat::release()
|
|
1569
|
+
{
|
|
1570
|
+
if (refcount && NCNN_XADD(refcount, -1) == 1)
|
|
1571
|
+
{
|
|
1572
|
+
if (allocator && data)
|
|
1573
|
+
{
|
|
1574
|
+
allocator->fastFree(data);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
data = 0;
|
|
1579
|
+
|
|
1580
|
+
elemsize = 0;
|
|
1581
|
+
elempack = 0;
|
|
1582
|
+
|
|
1583
|
+
dims = 0;
|
|
1584
|
+
w = 0;
|
|
1585
|
+
h = 0;
|
|
1586
|
+
d = 0;
|
|
1587
|
+
c = 0;
|
|
1588
|
+
|
|
1589
|
+
cstep = 0;
|
|
1590
|
+
|
|
1591
|
+
refcount = 0;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
NCNN_FORCEINLINE bool VkMat::empty() const
|
|
1595
|
+
{
|
|
1596
|
+
return data == 0 || total() == 0;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
NCNN_FORCEINLINE size_t VkMat::total() const
|
|
1600
|
+
{
|
|
1601
|
+
return cstep * c;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
NCNN_FORCEINLINE int VkMat::elembits() const
|
|
1605
|
+
{
|
|
1606
|
+
return elempack ? static_cast<int>(elemsize) * 8 / elempack : 0;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
NCNN_FORCEINLINE Mat VkMat::shape() const
|
|
1610
|
+
{
|
|
1611
|
+
if (dims == 1)
|
|
1612
|
+
return Mat(w * elempack, (void*)0);
|
|
1613
|
+
if (dims == 2)
|
|
1614
|
+
return Mat(w, h * elempack, (void*)0);
|
|
1615
|
+
if (dims == 3)
|
|
1616
|
+
return Mat(w, h, c * elempack, (void*)0);
|
|
1617
|
+
if (dims == 4)
|
|
1618
|
+
return Mat(w, h, d, c * elempack, (void*)0);
|
|
1619
|
+
|
|
1620
|
+
return Mat();
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
NCNN_FORCEINLINE VkBuffer VkMat::buffer() const
|
|
1624
|
+
{
|
|
1625
|
+
return data->buffer;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
NCNN_FORCEINLINE size_t VkMat::buffer_offset() const
|
|
1629
|
+
{
|
|
1630
|
+
return data->offset;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
NCNN_FORCEINLINE size_t VkMat::buffer_capacity() const
|
|
1634
|
+
{
|
|
1635
|
+
return data->capacity;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat()
|
|
1639
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1640
|
+
{
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, size_t _elemsize, VkAllocator* _allocator)
|
|
1644
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1645
|
+
{
|
|
1646
|
+
create(_w, _elemsize, _allocator);
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, size_t _elemsize, VkAllocator* _allocator)
|
|
1650
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1651
|
+
{
|
|
1652
|
+
create(_w, _h, _elemsize, _allocator);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _c, size_t _elemsize, VkAllocator* _allocator)
|
|
1656
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1657
|
+
{
|
|
1658
|
+
create(_w, _h, _c, _elemsize, _allocator);
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _d, int _c, size_t _elemsize, VkAllocator* _allocator)
|
|
1662
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1663
|
+
{
|
|
1664
|
+
create(_w, _h, _d, _c, _elemsize, _allocator);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1668
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1669
|
+
{
|
|
1670
|
+
create(_w, _elemsize, _elempack, _allocator);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1674
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1675
|
+
{
|
|
1676
|
+
create(_w, _h, _elemsize, _elempack, _allocator);
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _c, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1680
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1681
|
+
{
|
|
1682
|
+
create(_w, _h, _c, _elemsize, _elempack, _allocator);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _d, int _c, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1686
|
+
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0)
|
|
1687
|
+
{
|
|
1688
|
+
create(_w, _h, _d, _c, _elemsize, _elempack, _allocator);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(const VkImageMat& m)
|
|
1692
|
+
: data(m.data), refcount(m.refcount), elemsize(m.elemsize), elempack(m.elempack), allocator(m.allocator), dims(m.dims), w(m.w), h(m.h), d(m.d), c(m.c)
|
|
1693
|
+
{
|
|
1694
|
+
addref();
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, VkImageMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1698
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
1699
|
+
{
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, VkImageMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1703
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
1704
|
+
{
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _c, VkImageMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1708
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
1709
|
+
{
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _d, int _c, VkImageMemory* _data, size_t _elemsize, VkAllocator* _allocator)
|
|
1713
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(1), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
1714
|
+
{
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, VkImageMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1718
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(1), w(_w), h(1), d(1), c(1)
|
|
1719
|
+
{
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, VkImageMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1723
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(2), w(_w), h(_h), d(1), c(1)
|
|
1724
|
+
{
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _c, VkImageMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1728
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(3), w(_w), h(_h), d(1), c(_c)
|
|
1729
|
+
{
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
NCNN_FORCEINLINE VkImageMat::VkImageMat(int _w, int _h, int _d, int _c, VkImageMemory* _data, size_t _elemsize, int _elempack, VkAllocator* _allocator)
|
|
1733
|
+
: data(_data), refcount(0), elemsize(_elemsize), elempack(_elempack), allocator(_allocator), dims(4), w(_w), h(_h), d(_d), c(_c)
|
|
1734
|
+
{
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
NCNN_FORCEINLINE VkImageMat::~VkImageMat()
|
|
1738
|
+
{
|
|
1739
|
+
release();
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
NCNN_FORCEINLINE VkImageMat& VkImageMat::operator=(const VkImageMat& m)
|
|
1743
|
+
{
|
|
1744
|
+
if (this == &m)
|
|
1745
|
+
return *this;
|
|
1746
|
+
|
|
1747
|
+
if (m.refcount)
|
|
1748
|
+
NCNN_XADD(m.refcount, 1);
|
|
1749
|
+
|
|
1750
|
+
release();
|
|
1751
|
+
|
|
1752
|
+
data = m.data;
|
|
1753
|
+
refcount = m.refcount;
|
|
1754
|
+
elemsize = m.elemsize;
|
|
1755
|
+
elempack = m.elempack;
|
|
1756
|
+
allocator = m.allocator;
|
|
1757
|
+
|
|
1758
|
+
dims = m.dims;
|
|
1759
|
+
w = m.w;
|
|
1760
|
+
h = m.h;
|
|
1761
|
+
d = m.d;
|
|
1762
|
+
c = m.c;
|
|
1763
|
+
|
|
1764
|
+
return *this;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
NCNN_FORCEINLINE Mat VkImageMat::mapped() const
|
|
1768
|
+
{
|
|
1769
|
+
if (!allocator->mappable || !data->mapped_ptr)
|
|
1770
|
+
return Mat();
|
|
1771
|
+
|
|
1772
|
+
if (dims == 1)
|
|
1773
|
+
return Mat(w, mapped_ptr(), elemsize, elempack, 0);
|
|
1774
|
+
|
|
1775
|
+
if (dims == 2)
|
|
1776
|
+
return Mat(w, h, mapped_ptr(), elemsize, elempack, 0);
|
|
1777
|
+
|
|
1778
|
+
if (dims == 3)
|
|
1779
|
+
return Mat(w, h, c, mapped_ptr(), elemsize, elempack, 0);
|
|
1780
|
+
|
|
1781
|
+
if (dims == 4)
|
|
1782
|
+
return Mat(w, h, d, c, mapped_ptr(), elemsize, elempack, 0);
|
|
1783
|
+
|
|
1784
|
+
return Mat();
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
NCNN_FORCEINLINE void* VkImageMat::mapped_ptr() const
|
|
1788
|
+
{
|
|
1789
|
+
if (!allocator->mappable || !data->mapped_ptr)
|
|
1790
|
+
return 0;
|
|
1791
|
+
|
|
1792
|
+
return (unsigned char*)data->mapped_ptr + data->bind_offset;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
NCNN_FORCEINLINE void VkImageMat::addref()
|
|
1796
|
+
{
|
|
1797
|
+
if (refcount)
|
|
1798
|
+
NCNN_XADD(refcount, 1);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
NCNN_FORCEINLINE void VkImageMat::release()
|
|
1802
|
+
{
|
|
1803
|
+
if (refcount && NCNN_XADD(refcount, -1) == 1)
|
|
1804
|
+
{
|
|
1805
|
+
if (allocator && data)
|
|
1806
|
+
{
|
|
1807
|
+
allocator->fastFree(data);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
data = 0;
|
|
1812
|
+
|
|
1813
|
+
elemsize = 0;
|
|
1814
|
+
elempack = 0;
|
|
1815
|
+
|
|
1816
|
+
dims = 0;
|
|
1817
|
+
w = 0;
|
|
1818
|
+
h = 0;
|
|
1819
|
+
d = 0;
|
|
1820
|
+
c = 0;
|
|
1821
|
+
|
|
1822
|
+
refcount = 0;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
NCNN_FORCEINLINE bool VkImageMat::empty() const
|
|
1826
|
+
{
|
|
1827
|
+
return data == 0 || total() == 0;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
NCNN_FORCEINLINE size_t VkImageMat::total() const
|
|
1831
|
+
{
|
|
1832
|
+
return w * h * d * c;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
NCNN_FORCEINLINE int VkImageMat::elembits() const
|
|
1836
|
+
{
|
|
1837
|
+
return elempack ? static_cast<int>(elemsize) * 8 / elempack : 0;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
NCNN_FORCEINLINE Mat VkImageMat::shape() const
|
|
1841
|
+
{
|
|
1842
|
+
if (dims == 1)
|
|
1843
|
+
return Mat(w * elempack, (void*)0);
|
|
1844
|
+
if (dims == 2)
|
|
1845
|
+
return Mat(w, h * elempack, (void*)0);
|
|
1846
|
+
if (dims == 3)
|
|
1847
|
+
return Mat(w, h, c * elempack, (void*)0);
|
|
1848
|
+
if (dims == 4)
|
|
1849
|
+
return Mat(w, h, d, c * elempack, (void*)0);
|
|
1850
|
+
|
|
1851
|
+
return Mat();
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
NCNN_FORCEINLINE VkImage VkImageMat::image() const
|
|
1855
|
+
{
|
|
1856
|
+
return data->image;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
NCNN_FORCEINLINE VkImageView VkImageMat::imageview() const
|
|
1860
|
+
{
|
|
1861
|
+
return data->imageview;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
#endif // NCNN_VULKAN
|
|
1865
|
+
|
|
1866
|
+
} // namespace ncnn
|
|
1867
|
+
|
|
1868
|
+
#endif // NCNN_MAT_H
|