-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmmmmmmmmmmmmm_windows.txt
299 lines (187 loc) · 8.73 KB
/
mmmmmmmmmmmmmm_windows.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
原文连接:
https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-windows-x64-using-visual-studio-community-2017
(1)
安装vs2017,https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/#visual-studio-2017-and-other-products
需要登录后下载,建议下载Community社区版。在安装时需要在工作负荷一栏中勾选 使用C++的桌面开发 和 通用Windows平台开发,
并在语言包一栏中选择 英语。
(2)
解压protobuf-3.4.0.zip到D://下,
桌面左下角点放大镜,搜索x64 Native Tools Command Prompt for VS 2017,右键以管理员身份运行
输入以下命令编译安装protobuf-3.4.0,
(注意,本压缩包protobuf-3.4.0.zip已经编译安装过,如果想重新编译安装,删除build文件夹再运行以下命令)
d:
cd D://protobuf-3.4.0
mkdir build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../cmake
nmake
nmake install
(3)
解压opencv.zip到D://下,
(4)
解压MinGW (gcc9.2.0-2) 只安装了gnu 四个编译器.rar到D://下,
添加环境变量
MinGW_PATH=D:\MinGW
PATH后接
%MinGW_PATH%\bin
%MinGW_PATH%\include
%MinGW_PATH%\lib
gcc --version
输出版本信息表示安装成功。
(5)
双击VulkanSDK-1.3.204.1-Installer.exe,可选的组件全部都不勾选,安装路径选择D:\VulkanSDK\1.3.204.1
添加环境变量
VULKAN_SDK=D:\VulkanSDK\1.3.204.1
VK_SDK_PATH=D:\VulkanSDK\1.3.204.1
PATH后接
%VULKAN_SDK%\Bin
必须要关掉上面打开的x64 Native Tools Command Prompt for VS 2017终端,
重新以管理员身份运行这个终端,环境变量才生效。
(6)
构建ncnn库
桌面左下角点放大镜,搜索x64 Native Tools Command Prompt for VS 2017,右键以管理员身份运行
(其中的cmake命令有3处要指定protobuf的安装路径为D://protobuf-3.4.0,根据实际安装路径修改
其中的cmake命令有1处要指定opencv库中OpenCVConfig.cmake文件的路径,即-DOpenCV_DIR=D://opencv/build,根据实际安装路径修改
)
d:
cd D://GitHub/ncnn
cd D://GitHub/ncnn2
mkdir -p build
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=D://protobuf-3.4.0/build/install/include -DProtobuf_LIBRARIES=D://protobuf-3.4.0/build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=D://protobuf-3.4.0/build/install/bin/protoc.exe -DOpenCV_DIR=D://opencv/build -DNCNN_VULKAN=ON ..
nmake
nmake install
d:
cd D://GitHub/ncnn2
cd build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=D://protobuf-3.4.0/build/install/include -DProtobuf_LIBRARIES=D://protobuf-3.4.0/build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=D://protobuf-3.4.0/build/install/bin/protoc.exe -DOpenCV_DIR=D://opencv/build -DNCNN_VULKAN=ON ..
nmake
nmake install
https://blog.csdn.net/wangxingxing2006/article/details/78649756
Merge官方ncnn的代码进fork的ncnn
右键Git Bash Here
git checkout master
git remote add orgmaster https://github.com/Tencent/ncnn.git
git fetch orgmaster
git merge orgmaster/master
git push -u origin master
git remote -v
git branch -av
看算子是否是x86平台的:
printf("xxxxxxxxxxxxxxxxxxxxxxxxxxx86\n");
如果nmake报错
ncnn\src\mat.h(18): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory
include_directories(D:\MinGW\include)
如果nmake报错
ncnn\glslang\glslang\genericcodegen\../Include/Common.h(40): fatal error C1083: Cannot open include file: 'algorithm': No such file or directory
include_directories(D:\MinGW\lib\gcc\mingw32\9.2.0\include\c++\experimental)
include_directories(D:\MinGW\lib\gcc\mingw32\9.2.0\include)
(6.5)
https://zhuanlan.zhihu.com/p/431833958
编译pnnx
cd ..
cd tools/pnnx
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=install -DTorch_INSTALL_DIR="D://libtorch" ..
cmake --build . --config Release -j 2
cmake --build . --config Release --target install
(6.6)
https://github.com/Tencent/ncnn/pull/3828
测试torch.norm
cd tools/pnnx/tests/ncnn
../../build/install/bin/pnnx test_torch_norm.pt inputshape=[1,3,16],[1,5,9,11],[14,8,5,9,10]
(7)
运行示例(在pycharm的普通终端输入):
cd build/examples
.\squeezenet ../../images/256-ncnn.png ../../examples/squeezenet_v1.1.param ../../examples/squeezenet_v1.1.bin
重新编译(在x64 Native Tools Command Prompt for VS 2017终端输入)
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%cd%/install -DProtobuf_INCLUDE_DIR=D://protobuf-3.4.0/build/install/include -DProtobuf_LIBRARIES=D://protobuf-3.4.0/build/install/lib/libprotobuf.lib -DProtobuf_PROTOC_EXECUTABLE=D://protobuf-3.4.0/build/install/bin/protoc.exe -DOpenCV_DIR=D://opencv/build -DNCNN_VULKAN=ON ..
nmake
nmake install
cd ../benchmark
.\../build/benchmark/benchncnn 10 $(nproc) 0 0
---------------------------------------------------------------
源码解读:
squeezenet.load_param(param_path);调用的是
src/net.cpp的
int Net::load_param(const char* protopath)
最后调用
int Net::load_param(const DataReader& dr)
解读模型结构。
squeezenet_v1.1.param文件内容:
7767517
75 83
Input data 0 1 data 0=227 1=227 2=3
Convolution conv1 1 1 data conv1 0=64 1=3 2=1 3=2 4=0 5=1 6=1728
ReLU relu_conv1 1 1 conv1 conv1_relu_conv1 0=0.000000
...
第1行的7767517是版本号?反正当前版本就是这个固定的值。
第2行的75表示层的数量layer_count,83表示张量的数量blob_count,
第3行依次是层的类型layer_type、层的名字layer_name、输入张量数量bottom_count、输出张量数量top_count,再之后,先是所有输入张量的名字,再是所有输出张量的名字;
最后,带有"="的是层的属性。比如,Input层的0=227 1=227 2=3表示(源码在src/layer/input.cpp)
w = pd.get(0, 0);
h = pd.get(1, 0);
d = pd.get(11, 0);
c = pd.get(2, 0);
Convolution层的0=64 1=3 2=1 3=2 4=0 5=1 6=1728表示(源码在src/layer/convolution.cpp)
num_output = pd.get(0, 0);
kernel_w = pd.get(1, 0);
kernel_h = pd.get(11, kernel_w);
dilation_w = pd.get(2, 1);
dilation_h = pd.get(12, dilation_w);
stride_w = pd.get(3, 1);
stride_h = pd.get(13, stride_w);
pad_left = pd.get(4, 0);
pad_right = pd.get(15, pad_left);
pad_top = pd.get(14, pad_left);
pad_bottom = pd.get(16, pad_top);
pad_value = pd.get(18, 0.f);
bias_term = pd.get(5, 0);
weight_data_size = pd.get(6, 0);
int8_scale_term = pd.get(8, 0);
activation_type = pd.get(9, 0);
activation_params = pd.get(10, Mat());
dynamic_weight = pd.get(19, 0);
6=1728=64*3*3*3=weight_data_size=权重w的元素数量
SCAN_VALUE("%d", magic) 表示的是扫描下一个的值(作为整型)赋值给magic。
char bottom_name[256];
SCAN_VALUE("%255s", bottom_name) 表示的是扫描下一个的值(作为字符串)赋值给bottom_name,最大长度为255,不足的在字符串s左边补空格。
src/layer.h的表示了层类Layer,它有这些属性:
// 这个层的输入张量的下标
std::vector<int> bottoms;
// 这个层的输出张量的下标
std::vector<int> tops;
------------------------------ 各种处理器架构 ---------------------------------
ARM平台下NEON使用方法详解
https://blog.csdn.net/Selenitic_G/article/details/106565566
ARMv7 NEON 指令集架构具有 16 个 128 位的向量寄存器,命名为 q0~q15
这 16 个寄存器又可以拆分成 32 个 64 位寄存器,命名为 d0~d31
这 16 个寄存器又可以拆分成 64 个 32 位寄存器,命名为 s0~s63
https://aijishu.com/a/1060000000005301
内嵌汇编
https://blog.csdn.net/matao5566/article/details/45190719
ld1指令
https://blog.csdn.net/leelitian3/article/details/121670938
__aarch64__
.4s .16b 排列说明符的意义
https://qa.1r1g.com/sf/ask/4010627071/
absval_arm.cpp源码,1个寄存器存4个浮点数,用4个寄存器"v0", "v1", "v2", "v3",一次能处理16个浮点数,所以i+=16
指针ptr自增64的原因:
汇编里的指针,都是当做 char*,一次移动8bit(1B)
一个float,elemsize是4,单位是B(字节)
else // __aarch64__
asm volatile(
"pld [%0, #512] \n"
"vldm %0, {d0-d7} \n"
"vabs.f32 q0, q0 \n"
"vabs.f32 q1, q1 \n"
"vabs.f32 q2, q2 \n"
"vabs.f32 q3, q3 \n"
"vstm %0!, {d0-d7} \n"
: "=r"(ptr) // %0
: "0"(ptr)
: "memory", "q0", "q1", "q2", "q3");
#endif // __aarch64__
这里指针ptr没有自增?
感叹号,代表自动自增