diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..8953d1a9a --- /dev/null +++ b/.clang-format @@ -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 +--- diff --git a/.github/config/lint/.clang-format b/.github/config/lint/.clang-format new file mode 120000 index 000000000..3260daf75 --- /dev/null +++ b/.github/config/lint/.clang-format @@ -0,0 +1 @@ +../../../.clang-format \ No newline at end of file diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 2425d12b8..525914126 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -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 diff --git a/gloo/allreduce_bcube.h b/gloo/allreduce_bcube.h index 603176c10..c91fa130d 100644 --- a/gloo/allreduce_bcube.h +++ b/gloo/allreduce_bcube.h @@ -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); @@ -229,8 +232,11 @@ class Group { * group * @return List of ranks of nodes in the group */ - std::vector - getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const { + std::vector getNodeRanks( + int firstNodeRank, + int peerDistance, + int base, + int nodes) const { std::vector groupPeers; for (int i = 0; i < base; ++i) { int peerRank = firstNodeRank + i * peerDistance; diff --git a/gloo/alltoallv.h b/gloo/alltoallv.h index 029d94805..b0bb21e10 100644 --- a/gloo/alltoallv.h +++ b/gloo/alltoallv.h @@ -78,8 +78,10 @@ class AlltoallvOptions { size_t elementSize); // Untemplated implementation of setInput on opaque pointer. - void - setInput(void* ptr, std::vector elementsPerRank, size_t elementSize); + void setInput( + void* ptr, + std::vector elementsPerRank, + size_t elementSize); // Untemplated implementation of setOutput on unbound buffer. void setOutput( diff --git a/gloo/common/string.h b/gloo/common/string.h index f3aa7ee20..7592706df 100644 --- a/gloo/common/string.h +++ b/gloo/common/string.h @@ -28,8 +28,10 @@ inline void MakeStringInternal( } template -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...); } diff --git a/gloo/cuda_allreduce_bcube.h b/gloo/cuda_allreduce_bcube.h index b69fd628b..58ddffc36 100644 --- a/gloo/cuda_allreduce_bcube.h +++ b/gloo/cuda_allreduce_bcube.h @@ -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 - getNodeRanks(int firstNodeRank, int peerDistance, int base, int nodes) const; + std::vector getNodeRanks( + int firstNodeRank, + int peerDistance, + int base, + int nodes) const; }; } // namespace bcube diff --git a/gloo/math.h b/gloo/math.h index 794fe5452..03419a8d8 100644 --- a/gloo/math.h +++ b/gloo/math.h @@ -98,23 +98,35 @@ inline uint32_t log2ceil(uint32_t value) { template <> void sum(void* c, const void* a, const void* b, size_t n); -extern template void -sum(void* c, const void* a, const void* b, size_t n); +extern template void sum( + void* c, + const void* a, + const void* b, + size_t n); template <> void product(void* c, const void* a, const void* b, size_t n); -extern template void -product(void* c, const void* a, const void* b, size_t n); +extern template void product( + void* c, + const void* a, + const void* b, + size_t n); template <> void max(void* c, const void* a, const void* b, size_t n); -extern template void -max(void* c, const void* a, const void* b, size_t n); +extern template void max( + void* c, + const void* a, + const void* b, + size_t n); template <> void min(void* c, const void* a, const void* b, size_t n); -extern template void -min(void* c, const void* a, const void* b, size_t n); +extern template void min( + void* c, + const void* a, + const void* b, + size_t n); #endif diff --git a/gloo/test/base_test.h b/gloo/test/base_test.h index 4245a77cd..8380868d0 100644 --- a/gloo/test/base_test.h +++ b/gloo/test/base_test.h @@ -287,8 +287,10 @@ class Fixture { } } - void - checkBroadcastResult(Fixture& fixture, int root, int rootPointer) { + void checkBroadcastResult( + Fixture& 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 @@ -398,8 +400,10 @@ class Fixture { } } - void - checkBroadcastResult(Fixture& fixture, int root, int rootPointer) { + void checkBroadcastResult( + Fixture& 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 diff --git a/gloo/transport/ibverbs/pair.cc b/gloo/transport/ibverbs/pair.cc index 7812806c6..6ccd3a418 100644 --- a/gloo/transport/ibverbs/pair.cc +++ b/gloo/transport/ibverbs/pair.cc @@ -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 lock(m_); GLOO_ENFORCE_EQ(sendCompletionHandlers_.count(slot), 0); auto buffer = new Buffer(this, slot, ptr, size); @@ -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 lock(m_); GLOO_ENFORCE_EQ(recvCompletionHandlers_.count(slot), 0); auto buffer = new Buffer(this, slot, ptr, size); diff --git a/gloo/transport/ibverbs/pair.h b/gloo/transport/ibverbs/pair.h index 8b9dbdbba..89c6859aa 100644 --- a/gloo/transport/ibverbs/pair.h +++ b/gloo/transport/ibverbs/pair.h @@ -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; diff --git a/gloo/transport/pair.h b/gloo/transport/pair.h index 5e270bfac..1656fc7e1 100644 --- a/gloo/transport/pair.h +++ b/gloo/transport/pair.h @@ -30,11 +30,15 @@ class Pair { virtual void setSync(bool enable, bool busyPoll) = 0; - virtual std::unique_ptr - createSendBuffer(int slot, void* ptr, size_t size) = 0; - - virtual std::unique_ptr - createRecvBuffer(int slot, void* ptr, size_t size) = 0; + virtual std::unique_ptr createSendBuffer( + int slot, + void* ptr, + size_t size) = 0; + + virtual std::unique_ptr createRecvBuffer( + int slot, + void* ptr, + size_t size) = 0; virtual bool isConnected() = 0; diff --git a/gloo/transport/tcp/pair.cc b/gloo/transport/tcp/pair.cc index 051c759aa..f4e8cceee 100644 --- a/gloo/transport/tcp/pair.cc +++ b/gloo/transport/tcp/pair.cc @@ -392,8 +392,10 @@ void Pair::writeComplete( // buffer this message is intended for has not yet been registered (this can // only be the case for unbound buffers). // -ssize_t -Pair::prepareRead(Op& op, NonOwningPtr& buf, struct iovec& iov) { +ssize_t Pair::prepareRead( + Op& op, + NonOwningPtr& buf, + struct iovec& iov) { iov.iov_base = nullptr; iov.iov_len = 0; @@ -875,14 +877,18 @@ void Pair::recv() { } } -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) { auto buffer = new Buffer(this, slot, ptr, 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) { auto buffer = new Buffer(this, slot, ptr, size); registerBuffer(buffer); return std::unique_ptr<::gloo::transport::Buffer>(buffer); diff --git a/gloo/transport/tcp/pair.h b/gloo/transport/tcp/pair.h index 09434ae71..fb08adb56 100644 --- a/gloo/transport/tcp/pair.h +++ b/gloo/transport/tcp/pair.h @@ -111,11 +111,15 @@ class Pair : public ::gloo::transport::Pair, public Handler { virtual void setSync(bool sync, 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; // Send from the specified buffer to remote side of pair. virtual void send( @@ -252,8 +256,10 @@ class Pair : public ::gloo::transport::Pair, public Handler { const Op::Opcode& opcode) const; // Helper function for the `read` function below. - ssize_t - prepareRead(Op& op, NonOwningPtr& buf, struct iovec& iov); + ssize_t prepareRead( + Op& op, + NonOwningPtr& buf, + struct iovec& iov); // Read operation from socket into member variable (see `rx_`). // @@ -285,8 +291,10 @@ class Pair : public ::gloo::transport::Pair, public Handler { virtual void changeState(state nextState) noexcept; template - void - waitUntil(pred_t pred, std::unique_lock& lock, bool useTimeout) { + void waitUntil( + pred_t pred, + std::unique_lock& lock, + bool useTimeout) { auto timeoutSet = timeout_ != kNoTimeout; if (useTimeout && timeoutSet) { // Use a longer timeout when waiting for initial connect diff --git a/gloo/transport/uv/libuv.h b/gloo/transport/uv/libuv.h index 4983eea03..ddc2a807e 100644 --- a/gloo/transport/uv/libuv.h +++ b/gloo/transport/uv/libuv.h @@ -554,11 +554,15 @@ class TCP final : public Handle { static void uv__connection_cb(uv_stream_t* server, int status); - static void - uv__alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); - - static void - uv__read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); + static void uv__alloc_cb( + uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf); + + static void uv__read_cb( + uv_stream_t* stream, + ssize_t nread, + const uv_buf_t* buf); static void uv__write_cb(uv_write_t* req, int status) {} diff --git a/gloo/transport/uv/pair.h b/gloo/transport/uv/pair.h index 24114c86c..510c9619b 100644 --- a/gloo/transport/uv/pair.h +++ b/gloo/transport/uv/pair.h @@ -111,13 +111,17 @@ class Pair : public ::gloo::transport::Pair { abort(); } - 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 { abort(); } - 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 { abort(); }