Skip to content

Commit 3ef995e

Browse files
authored
format code style and setup restyled.io (#1840)
1 parent b27d507 commit 3ef995e

File tree

349 files changed

+44934
-43958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+44934
-43958
lines changed

.astylerc

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# astyle -n -r "benchmark/*.h,*.cpp" "src/*.h,*.cpp" "tests/*.h,*.cpp" "tools/*.h,*.cpp" "examples/*.h,*.cpp"
2+
3+
# brace style
4+
--style=allman
5+
6+
# tab
7+
--attach-namespaces
8+
--attach-extern-c
9+
--attach-closing-while
10+
11+
# indentation
12+
--indent-preproc-define
13+
--indent-col1-comments
14+
--min-conditional-indent=0
15+
--max-continuation-indent=120
16+
17+
# padding
18+
--pad-oper
19+
--pad-comma
20+
--pad-header
21+
--align-pointer=type
22+
--align-reference=type
23+
24+
# formatting
25+
--break-closing-braces
26+
--attach-return-type
27+
--attach-return-type-decl
28+
--keep-one-line-blocks
29+
--keep-one-line-statements
30+
--convert-tabs
31+
--max-code-length=200
32+
--mode=c
33+
34+
# other
35+
--lineend=linux

.clang-format

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# find src/ tools/ tests/ examples/ benchmark/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs -i clang-format -i {}
2+
3+
# need clang-format >= 10.0
4+
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: Align
7+
AlignConsecutiveAssignments: false
8+
# AlignConsecutiveBitFields: true
9+
AlignConsecutiveDeclarations: false
10+
AlignConsecutiveMacros: true
11+
AlignEscapedNewlines: Left
12+
# AlignOperands: AlignAfterOperator
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllConstructorInitializersOnNextLine: true
16+
AllowAllParametersOfDeclarationOnNextLine: true
17+
AllowShortBlocksOnASingleLine: Always
18+
AllowShortCaseLabelsOnASingleLine: true
19+
# AllowShortEnumsOnASingleLine: true
20+
AllowShortFunctionsOnASingleLine: None
21+
AllowShortIfStatementsOnASingleLine: WithoutElse
22+
AllowShortLambdasOnASingleLine: All
23+
AllowShortLoopsOnASingleLine: true
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: Yes
27+
BinPackArguments: true
28+
BinPackParameters: true
29+
BraceWrapping:
30+
AfterCaseLabel: true
31+
AfterClass: true
32+
AfterControlStatement: Always
33+
AfterEnum: true
34+
AfterFunction: true
35+
AfterNamespace: false
36+
AfterObjCDeclaration: false
37+
AfterStruct: true
38+
AfterUnion: true
39+
AfterExternBlock: false
40+
BeforeCatch: true
41+
BeforeElse: true
42+
# BeforeLambdaBody: false
43+
# BeforeWhile: false
44+
IndentBraces: false
45+
SplitEmptyFunction: true
46+
SplitEmptyRecord: true
47+
SplitEmptyNamespace: false
48+
BreakAfterJavaFieldAnnotations: true
49+
BreakBeforeBinaryOperators: All
50+
BreakBeforeBraces: Custom
51+
BreakBeforeTernaryOperators: true
52+
BreakConstructorInitializers: BeforeColon
53+
BreakInheritanceList: BeforeColon
54+
BreakStringLiterals: false
55+
ColumnLimit: 0
56+
# CommentPragmas:
57+
CompactNamespaces: false
58+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
59+
ConstructorInitializerIndentWidth: 4
60+
ContinuationIndentWidth: 4
61+
Cpp11BracedListStyle: true
62+
DeriveLineEnding: false
63+
DerivePointerAlignment: false
64+
# DisableFormat:
65+
# ExperimentalAutoDetectBinPacking:
66+
FixNamespaceComments: true
67+
# ForEachMacros:
68+
IncludeBlocks: Regroup
69+
# IncludeCategories:
70+
# IncludeIsMainRegex:
71+
# IncludeIsMainSourceRegex:
72+
# IndentCaseBlocks: false
73+
IndentCaseLabels: false
74+
# IndentExternBlock: NoIndent
75+
IndentGotoLabels: false
76+
IndentPPDirectives: None
77+
IndentWidth: 4
78+
# IndentWrappedFunctionNames: 4
79+
# InsertTrailingCommas: None
80+
# JavaImportGroups:
81+
# JavaScriptQuotes
82+
# JavaScriptWrapImports:
83+
KeepEmptyLinesAtTheStartOfBlocks: false
84+
Language: Cpp
85+
# MacroBlockBegin:
86+
# MacroBlockEnd:
87+
MaxEmptyLinesToKeep: 1
88+
NamespaceIndentation: None
89+
# NamespaceMacros:
90+
# ObjCBinPackProtocolList:
91+
# ObjCBlockIndentWidth:
92+
# ObjCBreakBeforeNestedBlockParam:
93+
# ObjCSpaceAfterProperty:
94+
# ObjCSpaceBeforeProtocolList:
95+
# PenaltyBreakAssignment:
96+
# PenaltyBreakBeforeFirstCallParameter:
97+
# PenaltyBreakComment:
98+
# PenaltyBreakFirstLessLess:
99+
# PenaltyBreakString:
100+
# PenaltyBreakTemplateDeclaration:
101+
# PenaltyExcessCharacter:
102+
# PenaltyReturnTypeOnItsOwnLine:
103+
PointerAlignment: Left
104+
# RawStringFormats:
105+
ReflowComments: false
106+
SortIncludes: false
107+
SortUsingDeclarations: true
108+
SpaceAfterCStyleCast: false
109+
SpaceAfterLogicalNot: false
110+
SpaceAfterTemplateKeyword: false
111+
SpaceBeforeAssignmentOperators: true
112+
SpaceBeforeCpp11BracedList: false
113+
SpaceBeforeCtorInitializerColon: true
114+
SpaceBeforeInheritanceColon: true
115+
SpaceBeforeParens: ControlStatements
116+
SpaceBeforeRangeBasedForLoopColon: true
117+
SpaceBeforeSquareBrackets: false
118+
SpaceInEmptyBlock: false
119+
SpaceInEmptyParentheses: false
120+
SpacesBeforeTrailingComments: 1
121+
SpacesInAngles: false
122+
SpacesInCStyleCastParentheses: false
123+
SpacesInConditionalStatement: false
124+
SpacesInContainerLiterals: false
125+
SpacesInParentheses: false
126+
SpacesInSquareBrackets: false
127+
Standard: c++03
128+
#StatementMacros:
129+
TabWidth: 4
130+
# TypenameMacros:
131+
UseCRLF: false
132+
UseTab: Never

.restyled.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# See https://github.com/restyled-io/restyled.io/wiki/Configuring-Restyled
2+
3+
enabled: false
4+
5+
pull_requests: true
6+
7+
statuses:
8+
differences: true
9+
no_differences: true
10+
error: true
11+
12+
restylers:
13+
- clang-format
14+
- astyle
15+
- clang-format
16+
- astyle

benchmark/benchncnn.cpp

+31-19
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
class GlobalGpuInstance
3535
{
3636
public:
37-
GlobalGpuInstance() { ncnn::create_gpu_instance(); }
38-
~GlobalGpuInstance() { ncnn::destroy_gpu_instance(); }
37+
GlobalGpuInstance()
38+
{
39+
ncnn::create_gpu_instance();
40+
}
41+
~GlobalGpuInstance()
42+
{
43+
ncnn::destroy_gpu_instance();
44+
}
3945
};
4046
// initialize vulkan runtime before main()
4147
GlobalGpuInstance g_global_gpu_instance;
@@ -44,8 +50,15 @@ GlobalGpuInstance g_global_gpu_instance;
4450
class DataReaderFromEmpty : public ncnn::DataReader
4551
{
4652
public:
47-
virtual int scan(const char* format, void* p) const { return 0; }
48-
virtual size_t read(void* buf, size_t size) const { memset(buf, 0, size); return size; }
53+
virtual int scan(const char* format, void* p) const
54+
{
55+
return 0;
56+
}
57+
virtual size_t read(void* buf, size_t size) const
58+
{
59+
memset(buf, 0, size);
60+
return size;
61+
}
4962
};
5063

5164
static int g_warmup_loop_count = 8;
@@ -108,7 +121,7 @@ void benchmark(const char* comment, const ncnn::Mat& _in, const ncnn::Option& op
108121
ncnn::Mat out;
109122

110123
// warm up
111-
for (int i=0; i<g_warmup_loop_count; i++)
124+
for (int i = 0; i < g_warmup_loop_count; i++)
112125
{
113126
ncnn::Extractor ex = net.create_extractor();
114127
ex.input("data", in);
@@ -119,7 +132,7 @@ void benchmark(const char* comment, const ncnn::Mat& _in, const ncnn::Option& op
119132
double time_max = -DBL_MAX;
120133
double time_avg = 0;
121134

122-
for (int i=0; i<g_loop_count; i++)
135+
for (int i = 0; i < g_loop_count; i++)
123136
{
124137
double start = ncnn::get_current_time();
125138

@@ -235,7 +248,7 @@ int main(int argc, char** argv)
235248
if (!use_vulkan_compute)
236249
#endif // NCNN_VULKAN
237250
{
238-
benchmark("squeezenet_int8", ncnn::Mat(227, 227, 3), opt);
251+
benchmark("squeezenet_int8", ncnn::Mat(227, 227, 3), opt);
239252
}
240253

241254
benchmark("mobilenet", ncnn::Mat(224, 224, 3), opt);
@@ -244,15 +257,15 @@ int main(int argc, char** argv)
244257
if (!use_vulkan_compute)
245258
#endif // NCNN_VULKAN
246259
{
247-
benchmark("mobilenet_int8", ncnn::Mat(224, 224, 3), opt);
260+
benchmark("mobilenet_int8", ncnn::Mat(224, 224, 3), opt);
248261
}
249262

250263
benchmark("mobilenet_v2", ncnn::Mat(224, 224, 3), opt);
251264

252-
// #if NCNN_VULKAN
253-
// if (!use_vulkan_compute)
254-
// #endif // NCNN_VULKAN
255-
// benchmark("mobilenet_v2_int8", ncnn::Mat(224, 224, 3), opt);
265+
// #if NCNN_VULKAN
266+
// if (!use_vulkan_compute)
267+
// #endif // NCNN_VULKAN
268+
// benchmark("mobilenet_v2_int8", ncnn::Mat(224, 224, 3), opt);
256269

257270
benchmark("mobilenet_v3", ncnn::Mat(224, 224, 3), opt);
258271

@@ -276,7 +289,7 @@ int main(int argc, char** argv)
276289
if (!use_vulkan_compute)
277290
#endif // NCNN_VULKAN
278291
{
279-
benchmark("googlenet_int8", ncnn::Mat(224, 224, 3), opt);
292+
benchmark("googlenet_int8", ncnn::Mat(224, 224, 3), opt);
280293
}
281294

282295
benchmark("resnet18", ncnn::Mat(224, 224, 3), opt);
@@ -285,7 +298,7 @@ int main(int argc, char** argv)
285298
if (!use_vulkan_compute)
286299
#endif // NCNN_VULKAN
287300
{
288-
benchmark("resnet18_int8", ncnn::Mat(224, 224, 3), opt);
301+
benchmark("resnet18_int8", ncnn::Mat(224, 224, 3), opt);
289302
}
290303

291304
benchmark("alexnet", ncnn::Mat(227, 227, 3), opt);
@@ -296,7 +309,7 @@ int main(int argc, char** argv)
296309
if (!use_vulkan_compute)
297310
#endif // NCNN_VULKAN
298311
{
299-
benchmark("vgg16_int8", ncnn::Mat(224, 224, 3), opt);
312+
benchmark("vgg16_int8", ncnn::Mat(224, 224, 3), opt);
300313
}
301314

302315
benchmark("resnet50", ncnn::Mat(224, 224, 3), opt);
@@ -305,7 +318,7 @@ int main(int argc, char** argv)
305318
if (!use_vulkan_compute)
306319
#endif // NCNN_VULKAN
307320
{
308-
benchmark("resnet50_int8", ncnn::Mat(224, 224, 3), opt);
321+
benchmark("resnet50_int8", ncnn::Mat(224, 224, 3), opt);
309322
}
310323

311324
benchmark("squeezenet_ssd", ncnn::Mat(300, 300, 3), opt);
@@ -314,17 +327,16 @@ int main(int argc, char** argv)
314327
if (!use_vulkan_compute)
315328
#endif // NCNN_VULKAN
316329
{
317-
benchmark("squeezenet_ssd_int8", ncnn::Mat(300, 300, 3), opt);
330+
benchmark("squeezenet_ssd_int8", ncnn::Mat(300, 300, 3), opt);
318331
}
319332

320333
benchmark("mobilenet_ssd", ncnn::Mat(300, 300, 3), opt);
321334

322-
323335
#if NCNN_VULKAN
324336
if (!use_vulkan_compute)
325337
#endif // NCNN_VULKAN
326338
{
327-
benchmark("mobilenet_ssd_int8", ncnn::Mat(300, 300, 3), opt);
339+
benchmark("mobilenet_ssd_int8", ncnn::Mat(300, 300, 3), opt);
328340
}
329341

330342
benchmark("mobilenet_yolo", ncnn::Mat(416, 416, 3), opt);

codeformat.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# we run clang-format and astyle twice to get stable format output
4+
5+
find src/ tools/ tests/ examples/ benchmark/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs -i clang-format -i {}
6+
astyle -n -r "benchmark/*.h,*.cpp" "src/*.h,*.cpp" "tests/*.h,*.cpp" "tools/*.h,*.cpp" "examples/*.h,*.cpp"
7+
8+
find src/ tools/ tests/ examples/ benchmark/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs -i clang-format -i {}
9+
astyle -n -r "benchmark/*.h,*.cpp" "src/*.h,*.cpp" "tests/*.h,*.cpp" "tools/*.h,*.cpp" "examples/*.h,*.cpp"

0 commit comments

Comments
 (0)