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

clang format integration #214

Merged
merged 3 commits into from
Sep 3, 2021
Merged
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
116 changes: 116 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
# General options
Language: Cpp
Standard: c++17
DisableFormat: false

AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 119
CommentPragmas: '^ COMMENT pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
TabWidth: 4
UseCRLF: false
UseTab: Never

# Project specific options
IncludeCategories:
# Local headers (in "") above all else
- Regex: '"([A-Za-z0-9.\/-_])+"'
Priority: 1
# <alpaka/foo.hpp> after local headers
- Regex: '"cupla/([A-Za-z0-9.\/-_])+"'
Priority: 2
# <alpaka/foo.hpp> after local headers
- Regex: '<alpaka/([A-Za-z0-9.\/-_])+>'
Priority: 3
# C++ standard library headers are the last group to be included
- Regex: '<([A-Za-z0-9\/-_])+>'
Priority: 4

# Future options - not supported in clang-format 11
# AlignConsecutiveBitFields: false
# AllowShortEnumsOnASingleLine: false
# BitFieldColonSpacing: Both
# IndentCaseBlocks: true
# IndentExternBlock: AfterExternBlock
# OperandAlignmentStyle: Align
...
40 changes: 40 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,32 @@
include:
- local: '/script/compiler_base.yml'

stages:
- validate
- compile-and-run

################################################################################
# Check code formation with clang-format
# pull request validation:
# - check C++ code style
pull-request-validation:
stage: validate
image: ubuntu:focal
script:
- apt update
# install clang-format-11
- apt install -y -q gnupg2 wget
- wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
- echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main" | tee -a /etc/apt/sources.list
- apt update
- DEBIAN_FRONTEND=noninteractive apt install -y clang-format-11
# Check C++ code style
- source $CI_PROJECT_DIR/script/check_cpp_code_style.sh
tags:
- x86_64

cuda92:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-gcc:1.4
variables:
CUPLA_CXX: "g++-6"
Expand All @@ -21,69 +46,80 @@ cuda92:
extends: .base_cuda

cuda100:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

cuda101:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

cuda102:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda102-gcc:1.4
variables:
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda

gcc1:
stage: compile-and-run
variables:
CUPLA_CXX: "g++-5 g++-6 g++-7 g++-8 g++-9"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0"
extends: .base_gcc

gcc2:
stage: compile-and-run
variables:
CUPLA_CXX: "g++-5 g++-6 g++-7 g++-8 g++-9"
CUPLA_BOOST_VERSIONS: "1.68.0 1.69.0 1.70.0"
extends: .base_gcc

gcc3:
stage: compile-and-run
variables:
CUPLA_CXX: "g++-5 g++-6 g++-7 g++-8 g++-9"
CUPLA_BOOST_VERSIONS: "1.71.0 1.72.0 1.73.0"
extends: .base_gcc

clang:
stage: compile-and-run
variables:
CUPLA_CXX: "clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_clang

cudaClang92:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-clang:1.4
variables:
CUPLA_CXX: "clang++-8 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

cudaClang100:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-clang:1.4
variables:
CUPLA_CXX: "clang++-8 clang++-9 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

cudaClang101:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-clang:1.4
variables:
CUPLA_CXX: "clang++-9 clang++-10 clang++-11"
CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0"
extends: .base_cuda_clang

hip42:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-rocm4.2:1.4
variables:
CMAKE_MODULE_PATH: "/opt/rocm-4.2.0/hip/cmake"
Expand All @@ -97,6 +133,7 @@ hip42:
# build external project and use cupla via cmake add_subdirectory()
# use internal alpaka
addSubdirectoryInternal:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
Expand All @@ -110,6 +147,7 @@ addSubdirectoryInternal:
# build external project and use cupla via cmake add_subdirectory()
# use installed alpaka
addSubdirectoryExternal:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
Expand All @@ -124,6 +162,7 @@ addSubdirectoryExternal:
# build external project and use cupla via cmake find_package()
# cupla was installed with disabled examples
findPackageWithoutExample:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
Expand All @@ -139,6 +178,7 @@ findPackageWithoutExample:
# build external project and use cupla via cmake find_package()
# cupla was installed with enabled examples
findPackageWithExample:
stage: compile-and-run
image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4
variables:
GIT_SUBMODULE_STRATEGY: normal
Expand Down
54 changes: 25 additions & 29 deletions example/CUDASamples/asyncAPI/src/asyncAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@

// includes, project
#include <helper_cuda.h>
#include <helper_functions.h> // helper utility functions
#include <helper_functions.h> // helper utility functions

struct increment_kernel
{

template<
typename T_Acc
>
ALPAKA_FN_ACC
void operator()(T_Acc const & acc, int *g_data, int inc_value) const
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
g_data[idx] = g_data[idx] + inc_value;
}
template<typename T_Acc>
ALPAKA_FN_ACC void operator()(T_Acc const& acc, int* g_data, int inc_value) const
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
g_data[idx] = g_data[idx] + inc_value;
}
};

int correct_output(int *data, const int n, const int x)
int correct_output(int* data, const int n, const int x)
{
for (int i = 0; i < n; i++)
if (data[i] != x)
for(int i = 0; i < n; i++)
if(data[i] != x)
{
printf("Error! data[%d] = %d, ref = %d\n", i, data[i], x);
return 0;
Expand All @@ -55,44 +51,44 @@ int correct_output(int *data, const int n, const int x)
return 1;
}

int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
// int devID;
// cudaDeviceProp deviceProps;
// int devID;
// cudaDeviceProp deviceProps;

printf("[%s] - Starting...\n", argv[0]);

// This will pick the best possible CUDA capable device
// devID = findCudaDevice(argc, (const char **)argv);
// devID = findCudaDevice(argc, (const char **)argv);

// get device name
// checkCudaErrors(cudaGetDeviceProperties(&deviceProps, devID));
// printf("CUDA device [%s]\n", deviceProps.name);
// checkCudaErrors(cudaGetDeviceProperties(&deviceProps, devID));
// printf("CUDA device [%s]\n", deviceProps.name);

int n = 16 * 1024 * 1024;
int nbytes = n * sizeof(int);
int value = 26;

// allocate host memory
int *a = 0;
checkCudaErrors(cudaMallocHost((void **)&a, nbytes));
int* a = 0;
checkCudaErrors(cudaMallocHost((void**) &a, nbytes));
memset(a, 0, nbytes);

// allocate device memory
int *d_a=0;
checkCudaErrors(cudaMalloc((void **)&d_a, nbytes));
int* d_a = 0;
checkCudaErrors(cudaMalloc((void**) &d_a, nbytes));
checkCudaErrors(cudaMemset(d_a, 255, nbytes));

// set kernel launch configuration
dim3 threads = dim3(512, 1);
dim3 blocks = dim3(n / threads.x, 1);
dim3 blocks = dim3(n / threads.x, 1);

// create cuda event handles
cudaEvent_t start, stop;
checkCudaErrors(cudaEventCreate(&start));
checkCudaErrors(cudaEventCreate(&stop));

StopWatchInterface *timer = NULL;
StopWatchInterface* timer = NULL;
sdkCreateTimer(&timer);
sdkResetTimer(&timer);

Expand All @@ -109,9 +105,9 @@ int main(int argc, char *argv[])
sdkStopTimer(&timer);

// have CPU do some work while waiting for stage 1 to finish
unsigned long int counter=0;
unsigned long int counter = 0;

while (cudaEventQuery(stop) == cudaErrorNotReady)
while(cudaEventQuery(stop) == cudaErrorNotReady)
{
counter++;
}
Expand All @@ -124,7 +120,7 @@ int main(int argc, char *argv[])
printf("CPU executed %lu iterations while waiting for GPU to finish\n", counter);

// check the output for correctness
bool bFinalResults = (bool)correct_output(a, n, value);
bool bFinalResults = (bool) correct_output(a, n, value);

// release resources
checkCudaErrors(cudaEventDestroy(start));
Expand Down
Loading