Skip to content

Commit

Permalink
Formatting changes + fix windows OSS build (#406)
Browse files Browse the repository at this point in the history
Summary:

Add .clang-format

Reviewed By: wconstab

Differential Revision: D69275930
  • Loading branch information
c-p-i-o authored and facebook-github-bot committed Feb 7, 2025
1 parent b67ecd8 commit 62d0b70
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 70 deletions.
126 changes: 126 additions & 0 deletions .github/config/lint/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
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
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros:
- FOR_EACH_RANGE
- FOR_EACH
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Macros:
- >-
PyObject_HEAD_INIT(type)={
/* this is not exactly match with PyObject_HEAD_INIT in Python source code
* but it is enough for clang-format */
{ 0xFFFFFFFF },
(type)
},
- >-
PyVarObject_HEAD_INIT(type, size)={
{
/* manually expand PyObject_HEAD_INIT(type) above
* because clang-format do not support recursive expansion */
{ 0xFFFFFFFF },
(type)
},
(size)
},
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
StatementMacros:
- C10_DEFINE_bool
- C10_DEFINE_int
- C10_DEFINE_int32
- C10_DEFINE_int64
- C10_DEFINE_string
- C10_DEFINE_REGISTRY_WITHOUT_WARNING
- C10_REGISTER_CREATOR
- DEFINE_BINARY
- PyObject_HEAD
- PyObject_VAR_HEAD
- PyException_HEAD
- TORCH_DECLARE_bool

TabWidth: 8
UseTab: Never
---
Language: ObjC
ColumnLimit: 120
AlignAfterOpenBracket: Align
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
...
16 changes: 8 additions & 8 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ jobs:
cd libuv-v1.38.0
mkdir -p build
cd build
mkdir -p ${{ env.gtest_lib_path }}
mkdir -p ${{ env.libuv_path }}
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.libuv_path }}
msbuild INSTALL.vcxproj
- name: Install googletest
run: |
conda activate py376_build
curl https://codeload.github.com/google/googletest/tar.gz/release-1.10.0 --output `
googletest-release-1.10.0.tar.gz
tar xzvf googletest-release-1.10.0.tar.gz
cd googletest-release-1.10.0
curl -L https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz `
--output googletest-1.15.2.tar.gz
tar xzvf googletest-1.15.2.tar.gz
cd googletest-1.15.2
mkdir -p build
cd build
if (Test-Path -Path ${{ env.gtest_lib_path }}) {
echo "Directory already exists"
} else {
mkdir ${{ env.gtest_lib_path }}
mkdir -p ${{ env.gtest_lib_path }}
}
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.gtest_lib_path }} -Dgtest_force_shared_crt=ON
msbuild INSTALL.vcxproj
Expand All @@ -76,9 +76,9 @@ jobs:
mkdir -p build
cd build
cmake .. -DBUILD_TEST=ON -Dlibuv_ROOT=${{ env.libuv_path }} `
-DGTEST_LIBRARY=${{ env.gtest_lib_path }}/lib/gtestd.lib `
-DGTEST_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest.lib `
-DGTEST_INCLUDE_DIR=${{ env.gtest_lib_path }}/include `
-DGTEST_MAIN_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest_maind.lib
-DGTEST_MAIN_LIBRARY=${{ env.gtest_lib_path }}/lib/gtest_main.lib
msbuild ALL_BUILD.vcxproj
- name: Test
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Super-linter
uses: super-linter/[email protected] # x-release-please-version
env:
LINTER_RULES_PATH: .github/config/lint
LINTER_RULES_PATH: .
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
Expand Down
126 changes: 126 additions & 0 deletions gloo/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
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
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros:
- FOR_EACH_RANGE
- FOR_EACH
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
Macros:
- >-
PyObject_HEAD_INIT(type)={
/* this is not exactly match with PyObject_HEAD_INIT in Python source code
* but it is enough for clang-format */
{ 0xFFFFFFFF },
(type)
},
- >-
PyVarObject_HEAD_INIT(type, size)={
{
/* manually expand PyObject_HEAD_INIT(type) above
* because clang-format do not support recursive expansion */
{ 0xFFFFFFFF },
(type)
},
(size)
},
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
StatementMacros:
- C10_DEFINE_bool
- C10_DEFINE_int
- C10_DEFINE_int32
- C10_DEFINE_int64
- C10_DEFINE_string
- C10_DEFINE_REGISTRY_WITHOUT_WARNING
- C10_REGISTER_CREATOR
- DEFINE_BINARY
- PyObject_HEAD
- PyObject_VAR_HEAD
- PyException_HEAD
- TORCH_DECLARE_bool

TabWidth: 8
UseTab: Never
---
Language: ObjC
ColumnLimit: 120
AlignAfterOpenBracket: Align
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
...
10 changes: 10 additions & 0 deletions gloo/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: default

rules:
# 120 chars should be enough, but don't fail if a line is longer
line-length:
max: 120
level: warning
comments:
min-spaces-from-content: 2
14 changes: 10 additions & 4 deletions gloo/allreduce_bcube.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,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 @@ -226,8 +229,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
Loading

0 comments on commit 62d0b70

Please sign in to comment.