Skip to content
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

ran formatter through entire repo (clang-9) #23

Open
wants to merge 1 commit into
base: master
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
120 changes: 120 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Style file for MLSE Libraries based on the modified rocBLAS style

# Common settings
BasedOnStyle: WebKit
TabWidth: 4
IndentWidth: 4
UseTab: Never
ColumnLimit: 100

# Other languages JavaScript, Proto

---
Language: Cpp

# http://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code
# int formatted_code;
# // clang-format off
# void unformatted_code ;
# // clang-format on
# void formatted_code_again;

DisableFormat: false
Standard: Cpp11

AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: Custom
# Control of individual brace wrapping cases
BraceWrapping: {
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
# AfterExternBlock : 'true'
}

#BreakAfterJavaFieldAnnotations: true
#BreakBeforeInheritanceComma: false
#BreakBeforeBinaryOperators: None
#BreakBeforeTernaryOperators: true
#BreakConstructorInitializersBeforeComma: true
#BreakStringLiterals: true

CommentPragmas: '^ IWYU pragma:'
#CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
#SpaceBeforeCpp11BracedList: false
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
#FixNamespaceComments: true
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
#JavaScriptQuotes: Double
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
#ObjCSpaceAfterProperty: true
#ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000

PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
#SpaceAfterTemplateKeyword: true
#SpaceBeforeInheritanceColon: true

#SortUsingDeclarations: true
SortIncludes: true

# Comments are for developers, they should arrange them
ReflowComments: false

#IncludeBlocks: Preserve
#IndentPPDirectives: AfterHash
---
8 changes: 8 additions & 0 deletions .githooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

cd $(git rev-parse --git-dir)
cd hooks

echo "Installing hooks..."
ln -s ../../.githooks/pre-commit pre-commit
echo "Done!"
43 changes: 43 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh
#
# This pre-commit hook checks if any versions of clang-format
# are installed, and if so, uses the installed version to format
# the staged changes.

base=/opt/rocm/hcc/bin/clang-format
format=""

# Redirect output to stderr.
exec 1>&2

# check if clang-format is installed
type "$base" >/dev/null 2>&1 && format="$base"

# no versions of clang-format are installed
if [ -z "$format" ]
then
echo "$base is not installed. Pre-commit hook will not be executed."
exit 0
fi

# Do everything from top - level
cd $(git rev-parse --show-toplevel)

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# do the formatting
for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$')
do
if [ -e "$file" ]
then
echo "$format $file"
"$format" -i -style=file "$file"
fi
done

2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env groovy
// This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/
@Library('rocJenkins') _
@Library('rocJenkins@clang9') _

// This is file for internal AMD use.
// If you are interested in running your own Jenkins, please raise a github issue for assistance.
Expand Down
1 change: 0 additions & 1 deletion examples/cpp_integration/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@

// function prototype
void sort_on_device(thrust::host_vector<int>& V);

11 changes: 5 additions & 6 deletions examples/cpp_integration/host.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <thrust/host_vector.h>
#include <thrust/random.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <thrust/generate.h>
#include <thrust/host_vector.h>
#include <thrust/random.h>
#include <thrust/sort.h>

// defines the function prototype
#include "device.h"

int main(void)
{
// generate 20 random numbers on the host
thrust::host_vector<int> h_vec(20);
thrust::host_vector<int> h_vec(20);
thrust::default_random_engine rng;
thrust::generate(h_vec.begin(), h_vec.end(), rng);

Expand All @@ -24,4 +24,3 @@ int main(void)

return 0;
}

131 changes: 64 additions & 67 deletions examples/include/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,53 @@

// use CUDA's high-resolution timers when possible
#include <hip/hip_runtime_api.h>
#include <string>
#include <thrust/system/cuda/error.h>
#include <thrust/system_error.h>
#include <string>

void cuda_safe_call(hipError_t error, const std::string& message = "")
{
if(error)
throw thrust::system_error(error, thrust::cuda_category(), message);
if(error)
throw thrust::system_error(error, thrust::cuda_category(), message);
}

struct timer
{
hipEvent_t start;
hipEvent_t end;

timer(void)
{
cuda_safe_call(hipEventCreate(&start));
cuda_safe_call(hipEventCreate(&end));
restart();
}

~timer(void)
{
cuda_safe_call(hipEventDestroy(start));
cuda_safe_call(hipEventDestroy(end));
}

void restart(void)
{
cuda_safe_call(hipEventRecord(start, 0));
}

double elapsed(void)
{
cuda_safe_call(hipEventRecord(end, 0));
cuda_safe_call(hipEventSynchronize(end));

float ms_elapsed;
cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end));
return ms_elapsed / 1e3;
}

double epsilon(void)
{
return 0.5e-6;
}
hipEvent_t start;
hipEvent_t end;

timer(void)
{
cuda_safe_call(hipEventCreate(&start));
cuda_safe_call(hipEventCreate(&end));
restart();
}

~timer(void)
{
cuda_safe_call(hipEventDestroy(start));
cuda_safe_call(hipEventDestroy(end));
}

void restart(void)
{
cuda_safe_call(hipEventRecord(start, 0));
}

double elapsed(void)
{
cuda_safe_call(hipEventRecord(end, 0));
cuda_safe_call(hipEventSynchronize(end));

float ms_elapsed;
cuda_safe_call(hipEventElapsedTime(&ms_elapsed, start, end));
return ms_elapsed / 1e3;
}

double epsilon(void)
{
return 0.5e-6;
}
};

#else
Expand All @@ -78,35 +78,32 @@ struct timer

struct timer
{
clock_t start;
clock_t end;

timer(void)
{
restart();
}

~timer(void)
{
}

void restart(void)
{
start = clock();
}

double elapsed(void)
{
end = clock();

return static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC);
}

double epsilon(void)
{
return 1.0 / static_cast<double>(CLOCKS_PER_SEC);
}
clock_t start;
clock_t end;

timer(void)
{
restart();
}

~timer(void) {}

void restart(void)
{
start = clock();
}

double elapsed(void)
{
end = clock();

return static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC);
}

double epsilon(void)
{
return 1.0 / static_cast<double>(CLOCKS_PER_SEC);
}
};

#endif

Loading