Skip to content

Commit 135057c

Browse files
c-p-i-ofacebook-github-bot
authored andcommitted
Formatting changes + fix windows OSS build (#406)
Summary: Add .clang-format. This is copied from https://github.com/pytorch/pytorch/blob/main/.clang-format Reviewed By: wconstab, fduwjj Differential Revision: D69275930
1 parent b67ecd8 commit 135057c

File tree

18 files changed

+398
-70
lines changed

18 files changed

+398
-70
lines changed

.github/config/lint/.clang-format

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 80
39+
CommentPragmas: '^ IWYU pragma:'
40+
CompactNamespaces: false
41+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
42+
ConstructorInitializerIndentWidth: 4
43+
ContinuationIndentWidth: 4
44+
Cpp11BracedListStyle: true
45+
DerivePointerAlignment: false
46+
DisableFormat: false
47+
ForEachMacros:
48+
- FOR_EACH_RANGE
49+
- FOR_EACH
50+
IncludeCategories:
51+
- Regex: '^<.*\.h(pp)?>'
52+
Priority: 1
53+
- Regex: '^<.*'
54+
Priority: 2
55+
- Regex: '.*'
56+
Priority: 3
57+
IndentCaseLabels: true
58+
IndentWidth: 2
59+
IndentWrappedFunctionNames: false
60+
KeepEmptyLinesAtTheStartOfBlocks: false
61+
MacroBlockBegin: ''
62+
MacroBlockEnd: ''
63+
Macros:
64+
- >-
65+
PyObject_HEAD_INIT(type)={
66+
/* this is not exactly match with PyObject_HEAD_INIT in Python source code
67+
* but it is enough for clang-format */
68+
{ 0xFFFFFFFF },
69+
(type)
70+
},
71+
- >-
72+
PyVarObject_HEAD_INIT(type, size)={
73+
{
74+
/* manually expand PyObject_HEAD_INIT(type) above
75+
* because clang-format do not support recursive expansion */
76+
{ 0xFFFFFFFF },
77+
(type)
78+
},
79+
(size)
80+
},
81+
MaxEmptyLinesToKeep: 1
82+
NamespaceIndentation: None
83+
PenaltyBreakBeforeFirstCallParameter: 1
84+
PenaltyBreakComment: 300
85+
PenaltyBreakFirstLessLess: 120
86+
PenaltyBreakString: 1000
87+
PenaltyExcessCharacter: 1000000
88+
PenaltyReturnTypeOnItsOwnLine: 2000000
89+
PointerAlignment: Left
90+
ReflowComments: true
91+
SortIncludes: true
92+
SpaceAfterCStyleCast: false
93+
SpaceBeforeAssignmentOperators: true
94+
SpaceBeforeParens: ControlStatements
95+
SpaceInEmptyParentheses: false
96+
SpacesBeforeTrailingComments: 1
97+
SpacesInAngles: false
98+
SpacesInContainerLiterals: true
99+
SpacesInCStyleCastParentheses: false
100+
SpacesInParentheses: false
101+
SpacesInSquareBrackets: false
102+
Standard: c++17
103+
StatementMacros:
104+
- C10_DEFINE_bool
105+
- C10_DEFINE_int
106+
- C10_DEFINE_int32
107+
- C10_DEFINE_int64
108+
- C10_DEFINE_string
109+
- C10_DEFINE_REGISTRY_WITHOUT_WARNING
110+
- C10_REGISTER_CREATOR
111+
- DEFINE_BINARY
112+
- PyObject_HEAD
113+
- PyObject_VAR_HEAD
114+
- PyException_HEAD
115+
- TORCH_DECLARE_bool
116+
117+
TabWidth: 8
118+
UseTab: Never
119+
---
120+
Language: ObjC
121+
ColumnLimit: 120
122+
AlignAfterOpenBracket: Align
123+
ObjCBlockIndentWidth: 2
124+
ObjCSpaceAfterProperty: false
125+
ObjCSpaceBeforeProtocolList: false
126+
...

.github/workflows/build-windows.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ jobs:
4949
cd libuv-v1.38.0
5050
mkdir -p build
5151
cd build
52-
mkdir -p ${{ env.gtest_lib_path }}
52+
mkdir -p ${{ env.libuv_path }}
5353
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.libuv_path }}
5454
msbuild INSTALL.vcxproj
5555
- name: Install googletest
5656
run: |
5757
conda activate py376_build
58-
curl https://codeload.github.com/google/googletest/tar.gz/release-1.10.0 --output `
59-
googletest-release-1.10.0.tar.gz
60-
tar xzvf googletest-release-1.10.0.tar.gz
61-
cd googletest-release-1.10.0
58+
curl -L https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz `
59+
--output googletest-1.15.2.tar.gz
60+
tar xzvf googletest-1.15.2.tar.gz
61+
cd googletest-1.15.2
6262
mkdir -p build
6363
cd build
6464
if (Test-Path -Path ${{ env.gtest_lib_path }}) {
6565
echo "Directory already exists"
6666
} else {
67-
mkdir ${{ env.gtest_lib_path }}
67+
mkdir -p ${{ env.gtest_lib_path }}
6868
}
6969
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.gtest_lib_path }} -Dgtest_force_shared_crt=ON
7070
msbuild INSTALL.vcxproj
@@ -76,9 +76,9 @@ jobs:
7676
mkdir -p build
7777
cd build
7878
cmake .. -DBUILD_TEST=ON -Dlibuv_ROOT=${{ env.libuv_path }} `
79-
-DGTEST_LIBRARY=${{ env.gtest_lib_path }}/lib/gtestd.lib `
79+
-DGTEST_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest.lib `
8080
-DGTEST_INCLUDE_DIR=${{ env.gtest_lib_path }}/include `
81-
-DGTEST_MAIN_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest_maind.lib
81+
-DGTEST_MAIN_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest_main.lib
8282
msbuild ALL_BUILD.vcxproj
8383
- name: Test
8484
run: |

.github/workflows/super-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Super-linter
2828
uses: super-linter/[email protected] # x-release-please-version
2929
env:
30-
LINTER_RULES_PATH: .github/config/lint
30+
LINTER_RULES_PATH: gloo
3131
# To report GitHub Actions status checks
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3333
VALIDATE_ALL_CODEBASE: false

gloo/.clang-format

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 80
39+
CommentPragmas: '^ IWYU pragma:'
40+
CompactNamespaces: false
41+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
42+
ConstructorInitializerIndentWidth: 4
43+
ContinuationIndentWidth: 4
44+
Cpp11BracedListStyle: true
45+
DerivePointerAlignment: false
46+
DisableFormat: false
47+
ForEachMacros:
48+
- FOR_EACH_RANGE
49+
- FOR_EACH
50+
IncludeCategories:
51+
- Regex: '^<.*\.h(pp)?>'
52+
Priority: 1
53+
- Regex: '^<.*'
54+
Priority: 2
55+
- Regex: '.*'
56+
Priority: 3
57+
IndentCaseLabels: true
58+
IndentWidth: 2
59+
IndentWrappedFunctionNames: false
60+
KeepEmptyLinesAtTheStartOfBlocks: false
61+
MacroBlockBegin: ''
62+
MacroBlockEnd: ''
63+
Macros:
64+
- >-
65+
PyObject_HEAD_INIT(type)={
66+
/* this is not exactly match with PyObject_HEAD_INIT in Python source code
67+
* but it is enough for clang-format */
68+
{ 0xFFFFFFFF },
69+
(type)
70+
},
71+
- >-
72+
PyVarObject_HEAD_INIT(type, size)={
73+
{
74+
/* manually expand PyObject_HEAD_INIT(type) above
75+
* because clang-format do not support recursive expansion */
76+
{ 0xFFFFFFFF },
77+
(type)
78+
},
79+
(size)
80+
},
81+
MaxEmptyLinesToKeep: 1
82+
NamespaceIndentation: None
83+
PenaltyBreakBeforeFirstCallParameter: 1
84+
PenaltyBreakComment: 300
85+
PenaltyBreakFirstLessLess: 120
86+
PenaltyBreakString: 1000
87+
PenaltyExcessCharacter: 1000000
88+
PenaltyReturnTypeOnItsOwnLine: 2000000
89+
PointerAlignment: Left
90+
ReflowComments: true
91+
SortIncludes: true
92+
SpaceAfterCStyleCast: false
93+
SpaceBeforeAssignmentOperators: true
94+
SpaceBeforeParens: ControlStatements
95+
SpaceInEmptyParentheses: false
96+
SpacesBeforeTrailingComments: 1
97+
SpacesInAngles: false
98+
SpacesInContainerLiterals: true
99+
SpacesInCStyleCastParentheses: false
100+
SpacesInParentheses: false
101+
SpacesInSquareBrackets: false
102+
Standard: c++17
103+
StatementMacros:
104+
- C10_DEFINE_bool
105+
- C10_DEFINE_int
106+
- C10_DEFINE_int32
107+
- C10_DEFINE_int64
108+
- C10_DEFINE_string
109+
- C10_DEFINE_REGISTRY_WITHOUT_WARNING
110+
- C10_REGISTER_CREATOR
111+
- DEFINE_BINARY
112+
- PyObject_HEAD
113+
- PyObject_VAR_HEAD
114+
- PyException_HEAD
115+
- TORCH_DECLARE_bool
116+
117+
TabWidth: 8
118+
UseTab: Never
119+
---
120+
Language: ObjC
121+
ColumnLimit: 120
122+
AlignAfterOpenBracket: Align
123+
ObjCBlockIndentWidth: 2
124+
ObjCSpaceAfterProperty: false
125+
ObjCSpaceBeforeProtocolList: false
126+
...

gloo/.yaml-lint.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
# 120 chars should be enough, but don't fail if a line is longer
6+
line-length:
7+
max: 120
8+
level: warning
9+
comments:
10+
min-spaces-from-content: 2

gloo/allreduce_bcube.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ class Group {
214214
* @count The total number of elements to be processed by this node
215215
* @return The number of elements to be processed by this group
216216
*/
217-
static int
218-
computeNumElems(int step, const Node& firstNode, int peers, int count) {
217+
static int computeNumElems(
218+
int step,
219+
const Node& firstNode,
220+
int peers,
221+
int count) {
219222
int groupCount =
220223
(0 == step) ? count : firstNode.getNumElemsPerStep(step - 1);
221224
return std::max(groupCount, peers);
@@ -226,8 +229,11 @@ class Group {
226229
* group
227230
* @return List of ranks of nodes in the group
228231
*/
229-
std::vector<int>
230-
getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const {
232+
std::vector<int> getNodeRanks(
233+
int firstNodeRank,
234+
int peerDistance,
235+
int base,
236+
int nodes) const {
231237
std::vector<int> groupPeers;
232238
for (int i = 0; i < base; ++i) {
233239
int peerRank = firstNodeRank + i * peerDistance;

gloo/alltoallv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ class AlltoallvOptions {
7878
size_t elementSize);
7979

8080
// Untemplated implementation of setInput on opaque pointer.
81-
void
82-
setInput(void* ptr, std::vector<int64_t> elementsPerRank, size_t elementSize);
81+
void setInput(
82+
void* ptr,
83+
std::vector<int64_t> elementsPerRank,
84+
size_t elementSize);
8385

8486
// Untemplated implementation of setOutput on unbound buffer.
8587
void setOutput(

gloo/common/string.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ inline void MakeStringInternal(
2828
}
2929

3030
template <typename T, typename... Args>
31-
inline void
32-
MakeStringInternal(std::stringstream& ss, const T& t, const Args&... args) {
31+
inline void MakeStringInternal(
32+
std::stringstream& ss,
33+
const T& t,
34+
const Args&... args) {
3335
MakeStringInternal(ss, t);
3436
MakeStringInternal(ss, args...);
3537
}

gloo/cuda_allreduce_bcube.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,22 @@ class Group {
389389
* @count The total number of elements to be processed by this node
390390
* @return The number of elements to be processed by this group
391391
*/
392-
static int
393-
computeNumElems(int step, const Node& firstNode, int peers, int count);
392+
static int computeNumElems(
393+
int step,
394+
const Node& firstNode,
395+
int peers,
396+
int count);
394397
/**
395398
* Determines all the nodes in a group in a particular step
396399
* @param peerDistance This is the distance between rank of each peer in the
397400
* group
398401
* @return List of ranks of nodes in the group
399402
*/
400-
std::vector<int>
401-
getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const;
403+
std::vector<int> getNodeRanks(
404+
int firstNodeRank,
405+
int peerDistance,
406+
int base,
407+
int nodes) const;
402408
};
403409

404410
} // namespace bcube

0 commit comments

Comments
 (0)