Skip to content

Add .clang-format config, provide to super-linter, and apply formatting to codebase #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# From https://github.com/pytorch/pytorch/blob/379bbef23c144aba4ae6e01d9e1247c4a44b3e74/.clang-format
# License:
# From PyTorch:
#
# Copyright (c) 2016- Facebook, Inc (Adam Paszke)
# Copyright (c) 2014- Facebook, Inc (Soumith Chintala)
# Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
# Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
# Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
# Copyright (c) 2011-2013 NYU (Clement Farabet)
# Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
# Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
# Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
#
# From Caffe2:
#
# Copyright (c) 2016-present, Facebook Inc. All rights reserved.
#
# All contributions by Facebook:
# Copyright (c) 2016 Facebook Inc.
#
# All contributions by Google:
# Copyright (c) 2015 Google Inc.
# All rights reserved.
#
# All contributions by Yangqing Jia:
# Copyright (c) 2015 Yangqing Jia
# All rights reserved.
#
# All contributions by Kakao Brain:
# Copyright 2019-2020 Kakao Brain
#
# All contributions by Cruise LLC:
# Copyright (c) 2022 Cruise LLC.
# All rights reserved.
#
# All contributions by Tri Dao:
# Copyright (c) 2024 Tri Dao.
# All rights reserved.
#
# All contributions by Arm:
# Copyright (c) 2021, 2023-2024 Arm Limited and/or its affiliates
#
# All contributions from Caffe:
# Copyright(c) 2013, 2014, 2015, the respective contributors
# All rights reserved.
#
# All other contributions:
# Copyright(c) 2015, 2016 the respective contributors
# All rights reserved.
#
# Caffe2 uses a copyright model similar to Caffe: each contributor holds
# copyright over their contributions to Caffe2. The project versioning records
# all such contribution and copyright details. If a contributor wants to further
# mark their specific copyright on a particular contribution, they should
# indicate their copyright solely in the commit message of the change when it is
# committed.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories America
# and IDIAP Research Institute nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 2000000
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
TabWidth: 8
UseTab: Never
---
1 change: 1 addition & 0 deletions .github/config/lint/.clang-format
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# within `super-linter`
fetch-depth: 0
- name: Super-linter
uses: super-linter/super-linter@v7.2.1 # x-release-please-version
uses: super-linter/super-linter@v7.3.0 # x-release-please-version
env:
LINTER_RULES_PATH: .github/config/lint
# To report GitHub Actions status checks
Expand Down
14 changes: 10 additions & 4 deletions gloo/allreduce_bcube.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ class Group {
* @count The total number of elements to be processed by this node
* @return The number of elements to be processed by this group
*/
static int
computeNumElems(int step, const Node& firstNode, int peers, int count) {
static int computeNumElems(
int step,
const Node& firstNode,
int peers,
int count) {
int groupCount =
(0 == step) ? count : firstNode.getNumElemsPerStep(step - 1);
return std::max(groupCount, peers);
Expand All @@ -229,8 +232,11 @@ class Group {
* group
* @return List of ranks of nodes in the group
*/
std::vector<int>
getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const {
std::vector<int> getNodeRanks(
int firstNodeRank,
int peerDistance,
int base,
int nodes) const {
std::vector<int> groupPeers;
for (int i = 0; i < base; ++i) {
int peerRank = firstNodeRank + i * peerDistance;
Expand Down
6 changes: 4 additions & 2 deletions gloo/alltoallv.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class AlltoallvOptions {
size_t elementSize);

// Untemplated implementation of setInput on opaque pointer.
void
setInput(void* ptr, std::vector<int64_t> elementsPerRank, size_t elementSize);
void setInput(
void* ptr,
std::vector<int64_t> elementsPerRank,
size_t elementSize);

// Untemplated implementation of setOutput on unbound buffer.
void setOutput(
Expand Down
6 changes: 4 additions & 2 deletions gloo/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ inline void MakeStringInternal(
}

template <typename T, typename... Args>
inline void
MakeStringInternal(std::stringstream& ss, const T& t, const Args&... args) {
inline void MakeStringInternal(
std::stringstream& ss,
const T& t,
const Args&... args) {
MakeStringInternal(ss, t);
MakeStringInternal(ss, args...);
}
Expand Down
14 changes: 10 additions & 4 deletions gloo/cuda_allreduce_bcube.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,22 @@ class Group {
* @count The total number of elements to be processed by this node
* @return The number of elements to be processed by this group
*/
static int
computeNumElems(int step, const Node& firstNode, int peers, int count);
static int computeNumElems(
int step,
const Node& firstNode,
int peers,
int count);
/**
* Determines all the nodes in a group in a particular step
* @param peerDistance This is the distance between rank of each peer in the
* group
* @return List of ranks of nodes in the group
*/
std::vector<int>
getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const;
std::vector<int> getNodeRanks(
int firstNodeRank,
int peerDistance,
int base,
int nodes) const;
};

} // namespace bcube
Expand Down
28 changes: 20 additions & 8 deletions gloo/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,35 @@ inline uint32_t log2ceil(uint32_t value) {

template <>
void sum<float16>(void* c, const void* a, const void* b, size_t n);
extern template void
sum<float16>(void* c, const void* a, const void* b, size_t n);
extern template void sum<float16>(
void* c,
const void* a,
const void* b,
size_t n);

template <>
void product<float16>(void* c, const void* a, const void* b, size_t n);
extern template void
product<float16>(void* c, const void* a, const void* b, size_t n);
extern template void product<float16>(
void* c,
const void* a,
const void* b,
size_t n);

template <>
void max<float16>(void* c, const void* a, const void* b, size_t n);
extern template void
max<float16>(void* c, const void* a, const void* b, size_t n);
extern template void max<float16>(
void* c,
const void* a,
const void* b,
size_t n);

template <>
void min<float16>(void* c, const void* a, const void* b, size_t n);
extern template void
min<float16>(void* c, const void* a, const void* b, size_t n);
extern template void min<float16>(
void* c,
const void* a,
const void* b,
size_t n);

#endif

Expand Down
12 changes: 8 additions & 4 deletions gloo/test/base_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ class Fixture<float16> {
}
}

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

void
checkBroadcastResult(Fixture<float>& fixture, int root, int rootPointer) {
void checkBroadcastResult(
Fixture<float>& fixture,
int root,
int rootPointer) {
// Expected is set to the expected value at ptr[0]
const auto expected = root * fixture.srcs.size() + rootPointer;
// Stride is difference between values at subsequent indices
Expand Down
12 changes: 8 additions & 4 deletions gloo/transport/ibverbs/pair.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ void Pair::postReceive() {
}
}

std::unique_ptr<::gloo::transport::Buffer>
Pair::createSendBuffer(int slot, void* ptr, size_t size) {
std::unique_ptr<::gloo::transport::Buffer> Pair::createSendBuffer(
int slot,
void* ptr,
size_t size) {
std::unique_lock<std::mutex> lock(m_);
GLOO_ENFORCE_EQ(sendCompletionHandlers_.count(slot), 0);
auto buffer = new Buffer(this, slot, ptr, size);
Expand All @@ -313,8 +315,10 @@ Pair::createSendBuffer(int slot, void* ptr, size_t size) {
return std::unique_ptr<::gloo::transport::Buffer>(buffer);
}

std::unique_ptr<::gloo::transport::Buffer>
Pair::createRecvBuffer(int slot, void* ptr, size_t size) {
std::unique_ptr<::gloo::transport::Buffer> Pair::createRecvBuffer(
int slot,
void* ptr,
size_t size) {
std::unique_lock<std::mutex> lock(m_);
GLOO_ENFORCE_EQ(recvCompletionHandlers_.count(slot), 0);
auto buffer = new Buffer(this, slot, ptr, size);
Expand Down
12 changes: 8 additions & 4 deletions gloo/transport/ibverbs/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ class Pair : public ::gloo::transport::Pair {

virtual void setSync(bool enable, bool busyPoll) override;

virtual std::unique_ptr<::gloo::transport::Buffer>
createSendBuffer(int slot, void* ptr, size_t size) override;
virtual std::unique_ptr<::gloo::transport::Buffer> createSendBuffer(
int slot,
void* ptr,
size_t size) override;

virtual std::unique_ptr<::gloo::transport::Buffer>
createRecvBuffer(int slot, void* ptr, size_t size) override;
virtual std::unique_ptr<::gloo::transport::Buffer> createRecvBuffer(
int slot,
void* ptr,
size_t size) override;

virtual bool isConnected() override;

Expand Down
14 changes: 9 additions & 5 deletions gloo/transport/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ class Pair {

virtual void setSync(bool enable, bool busyPoll) = 0;

virtual std::unique_ptr<Buffer>
createSendBuffer(int slot, void* ptr, size_t size) = 0;

virtual std::unique_ptr<Buffer>
createRecvBuffer(int slot, void* ptr, size_t size) = 0;
virtual std::unique_ptr<Buffer> createSendBuffer(
int slot,
void* ptr,
size_t size) = 0;

virtual std::unique_ptr<Buffer> createRecvBuffer(
int slot,
void* ptr,
size_t size) = 0;

virtual bool isConnected() = 0;

Expand Down
Loading