Skip to content

Commit 64f98a3

Browse files
committed
Add clang format
1 parent 79cf76b commit 64f98a3

File tree

8 files changed

+248
-131
lines changed

8 files changed

+248
-131
lines changed

.clang-format

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: true
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Left
8+
AlignOperands: false
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: false
11+
AllowShortBlocksOnASingleLine: true
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: All
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: false
19+
AlwaysBreakTemplateDeclarations: true
20+
BinPackArguments: true
21+
BinPackParameters: false
22+
BraceWrapping:
23+
AfterClass: true
24+
AfterControlStatement: true
25+
AfterEnum: true
26+
AfterFunction: true
27+
AfterNamespace: true
28+
AfterObjCDeclaration: true
29+
AfterStruct: true
30+
AfterUnion: true
31+
AfterExternBlock: true
32+
BeforeCatch: true
33+
BeforeElse: true
34+
IndentBraces: false
35+
SplitEmptyFunction: false
36+
SplitEmptyRecord: false
37+
SplitEmptyNamespace: false
38+
BreakBeforeBinaryOperators: None
39+
BreakBeforeBraces: Custom
40+
BreakBeforeInheritanceComma: false
41+
BreakBeforeTernaryOperators: true
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakConstructorInitializers: BeforeColon
44+
BreakAfterJavaFieldAnnotations: false
45+
BreakStringLiterals: true
46+
ColumnLimit: 120
47+
CommentPragmas: '^ IWYU pragma:'
48+
CompactNamespaces: false
49+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
50+
ConstructorInitializerIndentWidth: 4
51+
ContinuationIndentWidth: 4
52+
Cpp11BracedListStyle: true
53+
DerivePointerAlignment: false
54+
DisableFormat: false
55+
ExperimentalAutoDetectBinPacking: false
56+
FixNamespaceComments: true
57+
ForEachMacros:
58+
- foreach
59+
- Q_FOREACH
60+
- BOOST_FOREACH
61+
IncludeBlocks: Preserve
62+
IncludeCategories:
63+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
64+
Priority: 2
65+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
66+
Priority: 3
67+
- Regex: '.*'
68+
Priority: 1
69+
IncludeIsMainRegex: '(Test)?$'
70+
IndentCaseLabels: false
71+
IndentPPDirectives: None
72+
IndentWidth: 2
73+
IndentWrappedFunctionNames: true
74+
JavaScriptQuotes: Leave
75+
JavaScriptWrapImports: true
76+
KeepEmptyLinesAtTheStartOfBlocks: false
77+
MacroBlockBegin: ''
78+
MacroBlockEnd: ''
79+
MaxEmptyLinesToKeep: 2
80+
NamespaceIndentation: None
81+
ObjCBlockIndentWidth: 2
82+
ObjCSpaceAfterProperty: false
83+
ObjCSpaceBeforeProtocolList: true
84+
PenaltyBreakAssignment: 2
85+
PenaltyBreakBeforeFirstCallParameter: 30000
86+
PenaltyBreakComment: 300
87+
PenaltyBreakFirstLessLess: 120
88+
PenaltyBreakString: 1000
89+
PenaltyExcessCharacter: 1000000
90+
PenaltyReturnTypeOnItsOwnLine: 10000
91+
PointerAlignment: Left
92+
ReflowComments: false
93+
SortIncludes: false
94+
SortUsingDeclarations: true
95+
SpaceAfterCStyleCast: false
96+
SpaceAfterTemplateKeyword: false
97+
SpaceBeforeAssignmentOperators: true
98+
SpaceBeforeParens: ControlStatements
99+
SpaceInEmptyParentheses: false
100+
SpacesBeforeTrailingComments: 1
101+
SpacesInAngles: false
102+
SpacesInContainerLiterals: true
103+
SpaceBeforeCtorInitializerColon: true
104+
SpaceBeforeInheritanceColon: true
105+
SpaceBeforeRangeBasedForLoopColon: true
106+
SpaceInEmptyParentheses: false
107+
SpacesInCStyleCastParentheses: false
108+
SpacesInParentheses: false
109+
SpacesInSquareBrackets: false
110+
Standard: Cpp11
111+
TabWidth: 8
112+
UseTab: Never
113+
...
114+

hands-on/gemv/1-gemv-omp/gemv-omp.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
#define N 8192
22
#include "timer.h"
33

4-
template <typename T>
4+
template<typename T>
55
void gemv(int n, T alpha, const T* __restrict__ A, const T* __restrict__ V, T* __restrict__ Vout)
66
{
7-
#pragma omp parallel for
8-
for(int row=0; row<n; row++)
7+
#pragma omp parallel for
8+
for (int row = 0; row < n; row++)
99
{
10-
T sum = T(0);
11-
const T *__restrict__ A_row = A+row*n;
12-
for(int col=0; col<n; col++)
13-
sum += A_row[col]*V[col];
14-
Vout[row] = sum*alpha;
10+
T sum = T(0);
11+
const T* __restrict__ A_row = A + row * n;
12+
for (int col = 0; col < n; col++)
13+
sum += A_row[col] * V[col];
14+
Vout[row] = sum * alpha;
1515
}
1616
}
1717

18-
template <class T>
18+
template<class T>
1919
T* allocate(size_t n)
2020
{
2121
T* ptr = new T[n];
2222
std::fill_n(ptr, n, T(1));
2323
return ptr;
2424
}
2525

26-
template <class T>
26+
template<class T>
2727
void deallocate(T* ptr, size_t n)
2828
{
2929
delete[] ptr;
3030
}
3131

3232
int main()
3333
{
34-
auto* A = allocate<float>(N*N);
35-
auto* V = allocate<float>(N);
34+
auto* A = allocate<float>(N * N);
35+
auto* V = allocate<float>(N);
3636
auto* Vout = allocate<float>(N);
3737

3838
{
3939
Timer local("GEMV");
4040
gemv(N, 1.0f, A, V, Vout);
4141
}
4242

43-
for(int i=0; i<N; i++)
44-
if(Vout[i]!=N)
43+
for (int i = 0; i < N; i++)
44+
if (Vout[i] != N)
4545
{
46-
std::cerr << "Vout[" << i <<"] != " << N << ", wrong value is " << Vout[i] << std::endl;
46+
std::cerr << "Vout[" << i << "] != " << N << ", wrong value is " << Vout[i] << std::endl;
4747
break;
4848
}
4949

50-
deallocate(A, N*N);
50+
deallocate(A, N * N);
5151
deallocate(V, N);
5252
deallocate(Vout, N);
5353
}
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
#define N 8192
22
#include "timer.h"
33

4-
template <typename T>
4+
template<typename T>
55
void gemv(int n, T alpha, const T* __restrict__ A, const T* __restrict__ V, T* __restrict__ Vout)
66
{
7-
#pragma omp target parallel for map(to:A[:n*n], V[:n]) map(from:Vout[:n])
8-
for(int row=0; row<n; row++)
7+
#pragma omp target parallel for map(to : A[:n * n], V[:n]) map(from : Vout[:n])
8+
for (int row = 0; row < n; row++)
99
{
10-
T sum = T(0);
11-
const T *__restrict__ A_row = A+row*n;
12-
for(int col=0; col<n; col++)
13-
sum += A_row[col]*V[col];
14-
Vout[row] = sum*alpha;
10+
T sum = T(0);
11+
const T* __restrict__ A_row = A + row * n;
12+
for (int col = 0; col < n; col++)
13+
sum += A_row[col] * V[col];
14+
Vout[row] = sum * alpha;
1515
}
1616
}
1717

18-
template <class T>
18+
template<class T>
1919
T* allocate(size_t n)
2020
{
2121
T* ptr = new T[n];
2222
std::fill_n(ptr, n, T(1));
2323
return ptr;
2424
}
2525

26-
template <class T>
26+
template<class T>
2727
void deallocate(T* ptr, size_t n)
2828
{
2929
delete[] ptr;
3030
}
3131

3232
int main()
3333
{
34-
auto* A = allocate<float>(N*N);
35-
auto* V = allocate<float>(N);
34+
auto* A = allocate<float>(N * N);
35+
auto* V = allocate<float>(N);
3636
auto* Vout = allocate<float>(N);
3737

3838
{
3939
Timer local("GEMV");
4040
gemv(N, 1.0f, A, V, Vout);
4141
}
4242

43-
for(int i=0; i<N; i++)
44-
if(Vout[i]!=N)
43+
for (int i = 0; i < N; i++)
44+
if (Vout[i] != N)
4545
{
46-
std::cerr << "Vout[" << i <<"] != " << N << ", wrong value is " << Vout[i] << std::endl;
46+
std::cerr << "Vout[" << i << "] != " << N << ", wrong value is " << Vout[i] << std::endl;
4747
break;
4848
}
4949

50-
deallocate(A, N*N);
50+
deallocate(A, N * N);
5151
deallocate(V, N);
5252
deallocate(Vout, N);
5353
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#define N 8192
22
#include "timer.h"
33

4-
template <typename T>
4+
template<typename T>
55
void gemv(int n, T alpha, const T* __restrict__ A, const T* __restrict__ V, T* __restrict__ Vout)
66
{
7-
#pragma omp target teams distribute parallel for map(to:A[:n*n], V[:n]) map(from:Vout[:n])
8-
for(int row=0; row<n; row++)
7+
#pragma omp target teams distribute parallel for map(to : A[:n * n], V[:n]) map(from : Vout[:n])
8+
for (int row = 0; row < n; row++)
99
{
10-
T sum = T(0);
11-
const T *__restrict__ A_row = A+row*n;
12-
for(int col=0; col<n; col++)
13-
sum += A_row[col]*V[col];
14-
Vout[row] = sum*alpha;
10+
T sum = T(0);
11+
const T* __restrict__ A_row = A + row * n;
12+
for (int col = 0; col < n; col++)
13+
sum += A_row[col] * V[col];
14+
Vout[row] = sum * alpha;
1515
}
1616
}
1717

18-
template <class T>
18+
template<class T>
1919
T* allocate(size_t n)
2020
{
2121
T* ptr = new T[n];
@@ -24,7 +24,7 @@ T* allocate(size_t n)
2424
return ptr;
2525
}
2626

27-
template <class T>
27+
template<class T>
2828
void deallocate(T* ptr, size_t n)
2929
{
3030
//#pragma omp target exit data map(delete:ptr[:n])
@@ -33,23 +33,23 @@ void deallocate(T* ptr, size_t n)
3333

3434
int main()
3535
{
36-
auto* A = allocate<float>(N*N);
37-
auto* V = allocate<float>(N);
36+
auto* A = allocate<float>(N * N);
37+
auto* V = allocate<float>(N);
3838
auto* Vout = allocate<float>(N);
3939

4040
{
4141
Timer local("GEMV");
4242
gemv(N, 1.0f, A, V, Vout);
4343
}
4444

45-
for(int i=0; i<N; i++)
46-
if(Vout[i]!=N)
45+
for (int i = 0; i < N; i++)
46+
if (Vout[i] != N)
4747
{
48-
std::cerr << "Vout[" << i <<"] != " << N << ", wrong value is " << Vout[i] << std::endl;
48+
std::cerr << "Vout[" << i << "] != " << N << ", wrong value is " << Vout[i] << std::endl;
4949
break;
5050
}
5151

52-
deallocate(A, N*N);
52+
deallocate(A, N * N);
5353
deallocate(V, N);
5454
deallocate(Vout, N);
5555
}

0 commit comments

Comments
 (0)