Skip to content

Commit 4854c8d

Browse files
Add .clang-format config, provide to super-linter, and apply formatting to codebase (#439)
* Add .clang-format configuration file .clang-format configuration file added to allow standardisation of formatting across the repository. The configuration was obtained from PyTorch. The PyTorch license file is included as a comment in the file, to ensure copyright holders are given attribution. * Update super-linter in CI, and provide it with .clang-format Updating super-linter gives a significantly newer version of clang-format (17.0.6 -> 19.1.4). Linking .clang-format to .github/config/lint/.clang-format allows super-linter to use the configured rules for linting. * Apply clang-format to codebase This commit extends the work done in 55b6bf7. clang-format (version 19.1.7) is applied to the whole Gloo codebase. The config used is the .clang-format file provided in the previous commit, so that a consistent format can be used for all contributors going forward.
1 parent 46c3aed commit 4854c8d

File tree

16 files changed

+296
-61
lines changed

16 files changed

+296
-61
lines changed

.clang-format

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# From https://github.com/pytorch/pytorch/blob/379bbef23c144aba4ae6e01d9e1247c4a44b3e74/.clang-format
2+
# License:
3+
# From PyTorch:
4+
#
5+
# Copyright (c) 2016- Facebook, Inc (Adam Paszke)
6+
# Copyright (c) 2014- Facebook, Inc (Soumith Chintala)
7+
# Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
8+
# Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
9+
# Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
10+
# Copyright (c) 2011-2013 NYU (Clement Farabet)
11+
# Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
12+
# Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
13+
# Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
14+
#
15+
# From Caffe2:
16+
#
17+
# Copyright (c) 2016-present, Facebook Inc. All rights reserved.
18+
#
19+
# All contributions by Facebook:
20+
# Copyright (c) 2016 Facebook Inc.
21+
#
22+
# All contributions by Google:
23+
# Copyright (c) 2015 Google Inc.
24+
# All rights reserved.
25+
#
26+
# All contributions by Yangqing Jia:
27+
# Copyright (c) 2015 Yangqing Jia
28+
# All rights reserved.
29+
#
30+
# All contributions by Kakao Brain:
31+
# Copyright 2019-2020 Kakao Brain
32+
#
33+
# All contributions by Cruise LLC:
34+
# Copyright (c) 2022 Cruise LLC.
35+
# All rights reserved.
36+
#
37+
# All contributions by Tri Dao:
38+
# Copyright (c) 2024 Tri Dao.
39+
# All rights reserved.
40+
#
41+
# All contributions by Arm:
42+
# Copyright (c) 2021, 2023-2024 Arm Limited and/or its affiliates
43+
#
44+
# All contributions from Caffe:
45+
# Copyright(c) 2013, 2014, 2015, the respective contributors
46+
# All rights reserved.
47+
#
48+
# All other contributions:
49+
# Copyright(c) 2015, 2016 the respective contributors
50+
# All rights reserved.
51+
#
52+
# Caffe2 uses a copyright model similar to Caffe: each contributor holds
53+
# copyright over their contributions to Caffe2. The project versioning records
54+
# all such contribution and copyright details. If a contributor wants to further
55+
# mark their specific copyright on a particular contribution, they should
56+
# indicate their copyright solely in the commit message of the change when it is
57+
# committed.
58+
#
59+
# All rights reserved.
60+
#
61+
# Redistribution and use in source and binary forms, with or without
62+
# modification, are permitted provided that the following conditions are met:
63+
#
64+
# 1. Redistributions of source code must retain the above copyright
65+
# notice, this list of conditions and the following disclaimer.
66+
#
67+
# 2. Redistributions in binary form must reproduce the above copyright
68+
# notice, this list of conditions and the following disclaimer in the
69+
# documentation and/or other materials provided with the distribution.
70+
#
71+
# 3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories America
72+
# and IDIAP Research Institute nor the names of its contributors may be
73+
# used to endorse or promote products derived from this software without
74+
# specific prior written permission.
75+
#
76+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
77+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
80+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
81+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
82+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
83+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
84+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
85+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
86+
# POSSIBILITY OF SUCH DAMAGE.
87+
88+
---
89+
AccessModifierOffset: -1
90+
AlignAfterOpenBracket: AlwaysBreak
91+
AlignConsecutiveAssignments: false
92+
AlignConsecutiveDeclarations: false
93+
AlignEscapedNewlinesLeft: true
94+
AlignOperands: false
95+
AlignTrailingComments: false
96+
AllowAllParametersOfDeclarationOnNextLine: false
97+
AllowShortBlocksOnASingleLine: false
98+
AllowShortCaseLabelsOnASingleLine: false
99+
AllowShortFunctionsOnASingleLine: Empty
100+
AllowShortIfStatementsOnASingleLine: false
101+
AllowShortLoopsOnASingleLine: false
102+
AlwaysBreakAfterReturnType: None
103+
AlwaysBreakBeforeMultilineStrings: true
104+
AlwaysBreakTemplateDeclarations: true
105+
BinPackArguments: false
106+
BinPackParameters: false
107+
BraceWrapping:
108+
AfterClass: false
109+
AfterControlStatement: false
110+
AfterEnum: false
111+
AfterFunction: false
112+
AfterNamespace: false
113+
AfterObjCDeclaration: false
114+
AfterStruct: false
115+
AfterUnion: false
116+
BeforeCatch: false
117+
BeforeElse: false
118+
IndentBraces: false
119+
BreakBeforeBinaryOperators: None
120+
BreakBeforeBraces: Attach
121+
BreakBeforeTernaryOperators: true
122+
BreakConstructorInitializersBeforeComma: false
123+
BreakAfterJavaFieldAnnotations: false
124+
BreakStringLiterals: false
125+
ColumnLimit: 80
126+
CompactNamespaces: false
127+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
128+
ConstructorInitializerIndentWidth: 4
129+
ContinuationIndentWidth: 4
130+
Cpp11BracedListStyle: true
131+
DerivePointerAlignment: false
132+
DisableFormat: false
133+
IncludeCategories:
134+
- Regex: '^<.*\.h(pp)?>'
135+
Priority: 1
136+
- Regex: '^<.*'
137+
Priority: 2
138+
- Regex: '.*'
139+
Priority: 3
140+
IndentCaseLabels: true
141+
IndentWidth: 2
142+
IndentWrappedFunctionNames: false
143+
KeepEmptyLinesAtTheStartOfBlocks: false
144+
MaxEmptyLinesToKeep: 1
145+
NamespaceIndentation: None
146+
PenaltyBreakBeforeFirstCallParameter: 1
147+
PenaltyBreakComment: 300
148+
PenaltyBreakFirstLessLess: 120
149+
PenaltyBreakString: 1000
150+
PenaltyExcessCharacter: 1000000
151+
PenaltyReturnTypeOnItsOwnLine: 2000000
152+
PointerAlignment: Left
153+
ReflowComments: true
154+
SortIncludes: true
155+
SpaceAfterCStyleCast: false
156+
SpaceBeforeAssignmentOperators: true
157+
SpaceBeforeParens: ControlStatements
158+
SpaceInEmptyParentheses: false
159+
SpacesBeforeTrailingComments: 1
160+
SpacesInAngles: false
161+
SpacesInContainerLiterals: true
162+
SpacesInCStyleCastParentheses: false
163+
SpacesInParentheses: false
164+
SpacesInSquareBrackets: false
165+
Standard: c++17
166+
TabWidth: 8
167+
UseTab: Never
168+
---

.github/config/lint/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../.clang-format

.github/workflows/super-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# within `super-linter`
2626
fetch-depth: 0
2727
- name: Super-linter
28-
uses: super-linter/super-linter@v7.2.1 # x-release-please-version
28+
uses: super-linter/super-linter@v7.3.0 # x-release-please-version
2929
env:
3030
LINTER_RULES_PATH: .github/config/lint
3131
# To report GitHub Actions status checks

gloo/allreduce_bcube.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ class Group {
217217
* @count The total number of elements to be processed by this node
218218
* @return The number of elements to be processed by this group
219219
*/
220-
static int
221-
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) {
222225
int groupCount =
223226
(0 == step) ? count : firstNode.getNumElemsPerStep(step - 1);
224227
return std::max(groupCount, peers);
@@ -229,8 +232,11 @@ class Group {
229232
* group
230233
* @return List of ranks of nodes in the group
231234
*/
232-
std::vector<int>
233-
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 {
234240
std::vector<int> groupPeers;
235241
for (int i = 0; i < base; ++i) {
236242
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

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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ class Fixture<float16> {
287287
}
288288
}
289289

290-
void
291-
checkBroadcastResult(Fixture<float16>& fixture, int root, int rootPointer) {
290+
void checkBroadcastResult(
291+
Fixture<float16>& fixture,
292+
int root,
293+
int rootPointer) {
292294
// Expected is set to the expected value at ptr[0]
293295
const auto expected = root * fixture.srcs.size() + rootPointer;
294296
// Stride is difference between values at subsequent indices
@@ -398,8 +400,10 @@ class Fixture<float> {
398400
}
399401
}
400402

401-
void
402-
checkBroadcastResult(Fixture<float>& fixture, int root, int rootPointer) {
403+
void checkBroadcastResult(
404+
Fixture<float>& fixture,
405+
int root,
406+
int rootPointer) {
403407
// Expected is set to the expected value at ptr[0]
404408
const auto expected = root * fixture.srcs.size() + rootPointer;
405409
// Stride is difference between values at subsequent indices

gloo/transport/ibverbs/pair.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ void Pair::postReceive() {
301301
}
302302
}
303303

304-
std::unique_ptr<::gloo::transport::Buffer>
305-
Pair::createSendBuffer(int slot, void* ptr, size_t size) {
304+
std::unique_ptr<::gloo::transport::Buffer> Pair::createSendBuffer(
305+
int slot,
306+
void* ptr,
307+
size_t size) {
306308
std::unique_lock<std::mutex> lock(m_);
307309
GLOO_ENFORCE_EQ(sendCompletionHandlers_.count(slot), 0);
308310
auto buffer = new Buffer(this, slot, ptr, size);
@@ -313,8 +315,10 @@ Pair::createSendBuffer(int slot, void* ptr, size_t size) {
313315
return std::unique_ptr<::gloo::transport::Buffer>(buffer);
314316
}
315317

316-
std::unique_ptr<::gloo::transport::Buffer>
317-
Pair::createRecvBuffer(int slot, void* ptr, size_t size) {
318+
std::unique_ptr<::gloo::transport::Buffer> Pair::createRecvBuffer(
319+
int slot,
320+
void* ptr,
321+
size_t size) {
318322
std::unique_lock<std::mutex> lock(m_);
319323
GLOO_ENFORCE_EQ(recvCompletionHandlers_.count(slot), 0);
320324
auto buffer = new Buffer(this, slot, ptr, size);

0 commit comments

Comments
 (0)