Skip to content

Commit 34dae16

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 34dae16

File tree

17 files changed

+284
-74
lines changed

17 files changed

+284
-74
lines changed

.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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ 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
3434
DEFAULT_BRANCH: "main"
3535
# disable JSCPD (copy-paste checker)
3636
VALIDATE_JSCPD: false
37+
# disable CPP
38+
VALIDATE_CPP: false

gloo/.clang-format

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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: 120
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+
PPIndentWidth: 0
91+
ReflowComments: true
92+
SortIncludes: true
93+
SpaceAfterCStyleCast: false
94+
SpaceBeforeAssignmentOperators: true
95+
SpaceBeforeParens: ControlStatements
96+
SpaceInEmptyParentheses: false
97+
SpacesBeforeTrailingComments: 1
98+
SpacesInAngles: false
99+
SpacesInContainerLiterals: true
100+
SpacesInCStyleCastParentheses: false
101+
SpacesInParentheses: false
102+
SpacesInSquareBrackets: false
103+
Standard: c++17
104+
StatementMacros:
105+
- C10_DEFINE_bool
106+
- C10_DEFINE_int
107+
- C10_DEFINE_int32
108+
- C10_DEFINE_int64
109+
- C10_DEFINE_string
110+
- C10_DEFINE_REGISTRY_WITHOUT_WARNING
111+
- C10_REGISTER_CREATOR
112+
- DEFINE_BINARY
113+
- PyObject_HEAD
114+
- PyObject_VAR_HEAD
115+
- PyException_HEAD
116+
- TORCH_DECLARE_bool
117+
118+
TabWidth: 8
119+
UseTab: Never
120+
---
121+
Language: ObjC
122+
ColumnLimit: 120
123+
AlignAfterOpenBracket: Align
124+
ObjCBlockIndentWidth: 2
125+
ObjCSpaceAfterProperty: false
126+
ObjCSpaceBeforeProtocolList: false
127+
...

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: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
#include <cstring>
1616
#include <iomanip>
1717
#include <iostream>
18+
#include <memory>
19+
#include <string>
1820
#include <unordered_map>
21+
#include <vector>
1922

2023
#include "gloo/algorithm.h"
2124
#include "gloo/common/error.h"
@@ -214,8 +217,11 @@ class Group {
214217
* @count The total number of elements to be processed by this node
215218
* @return The number of elements to be processed by this group
216219
*/
217-
static int
218-
computeNumElems(int step, const Node& firstNode, int peers, int count) {
220+
static int computeNumElems(
221+
int step,
222+
const Node& firstNode,
223+
int peers,
224+
int count) {
219225
int groupCount =
220226
(0 == step) ? count : firstNode.getNumElemsPerStep(step - 1);
221227
return std::max(groupCount, peers);
@@ -226,8 +232,11 @@ class Group {
226232
* group
227233
* @return List of ranks of nodes in the group
228234
*/
229-
std::vector<int>
230-
getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const {
235+
std::vector<int> getNodeRanks(
236+
int firstNodeRank,
237+
int peerDistance,
238+
int base,
239+
int nodes) const {
231240
std::vector<int> groupPeers;
232241
for (int i = 0; i < base; ++i) {
233242
int peerRank = firstNodeRank + i * peerDistance;
@@ -589,8 +598,10 @@ class AllreduceBcube : public Algorithm {
589598
int count,
590599
int start = 0) {
591600
if (printCheck(myRank_)) {
592-
std::cout << stage << ": step (" << step << ") " << "srcRank (" << srcRank
593-
<< ") -> " << "destRank (" << destRank << "): ";
601+
std::cout << stage << ": step (" << step << ") "
602+
<< "srcRank (" << srcRank
603+
<< ") -> "
604+
<< "destRank (" << destRank << "): ";
594605
printElems(p, count, start);
595606
std::cout << std::endl;
596607
}

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

gloo/math.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,35 @@ inline uint32_t log2ceil(uint32_t value) {
9898

9999
template <>
100100
void sum<float16>(void* c, const void* a, const void* b, size_t n);
101-
extern template void
102-
sum<float16>(void* c, const void* a, const void* b, size_t n);
101+
extern template void sum<float16>(
102+
void* c,
103+
const void* a,
104+
const void* b,
105+
size_t n);
103106

104107
template <>
105108
void product<float16>(void* c, const void* a, const void* b, size_t n);
106-
extern template void
107-
product<float16>(void* c, const void* a, const void* b, size_t n);
109+
extern template void product<float16>(
110+
void* c,
111+
const void* a,
112+
const void* b,
113+
size_t n);
108114

109115
template <>
110116
void max<float16>(void* c, const void* a, const void* b, size_t n);
111-
extern template void
112-
max<float16>(void* c, const void* a, const void* b, size_t n);
117+
extern template void max<float16>(
118+
void* c,
119+
const void* a,
120+
const void* b,
121+
size_t n);
113122

114123
template <>
115124
void min<float16>(void* c, const void* a, const void* b, size_t n);
116-
extern template void
117-
min<float16>(void* c, const void* a, const void* b, size_t n);
125+
extern template void min<float16>(
126+
void* c,
127+
const void* a,
128+
const void* b,
129+
size_t n);
118130

119131
#endif
120132

gloo/test/base_test.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ enum Transport {
6666
};
6767

6868
// Transports that instantiated algorithms can be tested against.
69-
const std::vector<Transport> kTransportsForClassAlgorithms{
69+
const std::vector<Transport> kTransportsForClassAlgorithms = {
7070
Transport::TCP,
7171
#if GLOO_HAVE_TRANSPORT_TCP_TLS
7272
Transport::TCP_TLS,
@@ -76,7 +76,7 @@ const std::vector<Transport> kTransportsForClassAlgorithms{
7676
// Transports that function algorithms can be tested against.
7777
// This is the new style of calling collectives and must be
7878
// preferred over the instantiated style.
79-
const std::vector<Transport> kTransportsForFunctionAlgorithms{
79+
const std::vector<Transport> kTransportsForFunctionAlgorithms = {
8080
Transport::TCP,
8181
#if GLOO_HAVE_TRANSPORT_TCP_TLS
8282
Transport::TCP_TLS,
@@ -296,8 +296,10 @@ class Fixture<float16> {
296296
}
297297
}
298298

299-
void
300-
checkBroadcastResult(Fixture<float16>& fixture, int root, int rootPointer) {
299+
void checkBroadcastResult(
300+
Fixture<float16>& fixture,
301+
int root,
302+
int rootPointer) {
301303
// Expected is set to the expected value at ptr[0]
302304
const auto expected = root * fixture.srcs.size() + rootPointer;
303305
// Stride is difference between values at subsequent indices
@@ -407,8 +409,10 @@ class Fixture<float> {
407409
}
408410
}
409411

410-
void
411-
checkBroadcastResult(Fixture<float>& fixture, int root, int rootPointer) {
412+
void checkBroadcastResult(
413+
Fixture<float>& fixture,
414+
int root,
415+
int rootPointer) {
412416
// Expected is set to the expected value at ptr[0]
413417
const auto expected = root * fixture.srcs.size() + rootPointer;
414418
// Stride is difference between values at subsequent indices

0 commit comments

Comments
 (0)