Skip to content

Commit

Permalink
Merge pull request #267 from chillenzer/update-clang-format
Browse files Browse the repository at this point in the history
Update clang format
  • Loading branch information
psychocoderHPC authored Nov 8, 2024
2 parents 29d2757 + fbefa18 commit 8c897de
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 270 deletions.
110 changes: 83 additions & 27 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Standard: c++20
DisableFormat: false
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: None
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments: false
AlignOperands: Align
AlignTrailingComments:
Kind: Never
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
Expand All @@ -26,84 +27,139 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BreakAfterAttributes: Never
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Allman
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 119
CommentPragmas: "^ COMMENT pragma:"
CommentPragmas: '^ COMMENT pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentRequiresClause: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: true
IntegerLiteralSeparator:
Binary: 4
Decimal: 3
DecimalMinDigits: 7
Hex: 4
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0 # default made explicit here
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0 # default made explicit here
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
PPIndentWidth: -1 # follow IndentWidth
QualifierAlignment: Custom
QualifierOrder: ['friend', 'static', 'inline', 'constexpr', 'type', 'const', 'volatile', 'restrict']
ReferenceAlignment: Pointer # follow PointerAlignment
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: WithPreceding
RequiresExpressionIndentation: OuterScope
ShortNamespaceLines: 0
SortIncludes: true
SortUsingDeclarations: true
SortUsingDeclarations: Lexicographic
SeparateDefinitionBlocks: Always
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default # follow PointerAlignment
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
TabWidth: 4
UseCRLF: false
UseTab: Never
# Project specific options -- uncomment and modify as needed
#IncludeCategories:
# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
# Priority: 2
# SortPriority: 0
# - Regex: '^(<|"(gtest|gmock|isl|json)/)'
# Priority: 3
# SortPriority: 0
# - Regex: '.*'
# Priority: 1
# SortPriority: 0

# Future options - not supported in clang-format 11
# BitFieldColonSpacing: Both
# OperandAlignmentStyle: Align
# Project specific options
#AttributeMacros: []
#ForEachMacros: []
#IfMacros: []
IncludeCategories:
# Local headers (in "") above all else
- Regex: '"([A-Za-z0-9.\/-_])+"'
Priority: 1
# "alpaka/foo.hpp" after local headers (occur inside alpaka)
- Regex: '"alpaka/([A-Za-z0-9.\/-_])+"'
Priority: 2
# <alpaka/foo.hpp> after local headers (occur outside alpaka in examples and test)
- 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: 5
# Includes that made it this far are third-party headers and will be placed
# below alpaka's includes
- Regex: '<([A-Za-z0-9.\/-_])+>'
Priority: 4
# Macros: []
# NamespaceMacros: []
StatementAttributeLikeMacros:
- 'ALPAKA_DEVICE_VOLATILE'
- 'ALPAKA_FN_ACC'
- 'ALPAKA_FN_EXTERN'
- 'ALPAKA_FN_HOST'
- 'ALPAKA_FN_HOST_ACC'
- 'ALPAKA_FN_INLINE'
- 'ALPAKA_STATIC_ACC_MEM_CONSTANT'
- 'ALPAKA_STATIC_ACC_MEM_GLOBAL'
- 'ALPAKA_UNROLL'
- 'ALPAKA_VECTORIZE_HINT'
#StatementMacros: []
#TypenameMacros: []
#WhitespaceSensitiveMacros: []
44 changes: 23 additions & 21 deletions examples/mallocMC_example01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
THE SOFTWARE.
*/

#include <algorithm>
#include <alpaka/alpaka.hpp>
#include <alpaka/example/ExampleDefaultAcc.hpp>

#include <mallocMC/mallocMC.hpp>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <mallocMC/mallocMC.hpp>
#include <numeric>

using Dim = alpaka::DimInt<1>;
Expand Down Expand Up @@ -84,7 +86,7 @@ auto main() -> int
constexpr auto length = 100;

auto const platform = alpaka::Platform<Acc>{};
const auto dev = alpaka::getDevByIdx(platform, 0);
auto const dev = alpaka::getDevByIdx(platform, 0);
auto queue = alpaka::Queue<Acc, alpaka::Blocking>{dev};

auto const devProps = alpaka::getAccDevProps<Acc>(dev);
Expand All @@ -103,13 +105,13 @@ auto main() -> int
// create arrays of arrays on the device
{
auto createArrayPointers
= [] ALPAKA_FN_ACC(const Acc& acc, int x, int y, ScatterAllocator::AllocatorHandle allocHandle)
= [] ALPAKA_FN_ACC(Acc const& acc, int x, int y, ScatterAllocator::AllocatorHandle allocHandle)
{
arA = (int**) allocHandle.malloc(acc, sizeof(int*) * x * y);
arB = (int**) allocHandle.malloc(acc, sizeof(int*) * x * y);
arC = (int**) allocHandle.malloc(acc, sizeof(int*) * x * y);
};
const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{1}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{1}, Idx{1}};
alpaka::enqueue(
queue,
alpaka::createTaskKernel<Acc>(
Expand All @@ -122,9 +124,9 @@ auto main() -> int

// fill 2 of them all with ascending values
{
auto fillArrays = [] ALPAKA_FN_ACC(const Acc& acc, int length, ScatterAllocator::AllocatorHandle allocHandle)
auto fillArrays = [] ALPAKA_FN_ACC(Acc const& acc, int length, ScatterAllocator::AllocatorHandle allocHandle)
{
const auto id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];
auto const id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];

arA[id] = (int*) allocHandle.malloc(acc, length * sizeof(int));
arB[id] = (int*) allocHandle.malloc(acc, length * sizeof(int));
Expand All @@ -136,7 +138,7 @@ auto main() -> int
arB[id][i] = static_cast<int>(id * length + i);
}
};
const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
alpaka::enqueue(
queue,
alpaka::createTaskKernel<Acc>(workDiv, fillArrays, length, scatterAlloc.getAllocatorHandle()));
Expand All @@ -147,9 +149,9 @@ auto main() -> int
{
auto sumsBufferAcc = alpaka::allocBuf<int, Idx>(dev, Idx{block * grid});

auto addArrays = [] ALPAKA_FN_ACC(const Acc& acc, int length, int* sums)
auto addArrays = [] ALPAKA_FN_ACC(Acc const& acc, int length, int* sums)
{
const auto id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];
auto const id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];

sums[id] = 0;
for(int i = 0; i < length; ++i)
Expand All @@ -158,25 +160,25 @@ auto main() -> int
sums[id] += arC[id][i];
}
};
const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
alpaka::enqueue(
queue,
alpaka::createTaskKernel<Acc>(workDiv, addArrays, length, alpaka::getPtrNative(sumsBufferAcc)));

auto const platformCPU = alpaka::Platform<alpaka::DevCpu>{};
const auto hostDev = alpaka::getDevByIdx(platformCPU, 0);
auto const hostDev = alpaka::getDevByIdx(platformCPU, 0);

auto sumsBufferHost = alpaka::allocBuf<int, Idx>(hostDev, Idx{block * grid});
alpaka::memcpy(queue, sumsBufferHost, sumsBufferAcc, Idx{block * grid});
alpaka::wait(queue);

const auto* sumsPtr = alpaka::getPtrNative(sumsBufferHost);
const auto sum = std::accumulate(sumsPtr, sumsPtr + block * grid, size_t{0});
auto const* sumsPtr = alpaka::getPtrNative(sumsBufferHost);
auto const sum = std::accumulate(sumsPtr, sumsPtr + block * grid, size_t{0});
std::cout << "The sum of the arrays on GPU is " << sum << '\n';
}

const auto n = static_cast<size_t>(block * grid * length);
const auto gaussian = n * (n - 1);
auto const n = static_cast<size_t>(block * grid * length);
auto const gaussian = n * (n - 1);
std::cout << "The gaussian sum as comparison: " << gaussian << '\n';

/*constexpr*/ if(mallocMC::Traits<ScatterAllocator>::providesAvailableSlots)
Expand All @@ -187,25 +189,25 @@ auto main() -> int
}

{
auto freeArrays = [] ALPAKA_FN_ACC(const Acc& acc, ScatterAllocator::AllocatorHandle allocHandle)
auto freeArrays = [] ALPAKA_FN_ACC(Acc const& acc, ScatterAllocator::AllocatorHandle allocHandle)
{
const auto id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];
auto const id = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];
allocHandle.free(acc, arA[id]);
allocHandle.free(acc, arB[id]);
allocHandle.free(acc, arC[id]);
};
const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{grid}, Idx{block}, Idx{1}};
alpaka::enqueue(queue, alpaka::createTaskKernel<Acc>(workDiv, freeArrays, scatterAlloc.getAllocatorHandle()));
}

{
auto freeArrayPointers = [] ALPAKA_FN_ACC(const Acc& acc, ScatterAllocator::AllocatorHandle allocHandle)
auto freeArrayPointers = [] ALPAKA_FN_ACC(Acc const& acc, ScatterAllocator::AllocatorHandle allocHandle)
{
allocHandle.free(acc, arA);
allocHandle.free(acc, arB);
allocHandle.free(acc, arC);
};
const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{1}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{1}, Idx{1}};
alpaka::enqueue(
queue,
alpaka::createTaskKernel<Acc>(workDiv, freeArrayPointers, scatterAlloc.getAllocatorHandle()));
Expand Down
16 changes: 9 additions & 7 deletions examples/mallocMC_example03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
THE SOFTWARE.
*/

#include <algorithm>
#include <alpaka/alpaka.hpp>
#include <alpaka/example/ExampleDefaultAcc.hpp>

#include <mallocMC/mallocMC.hpp>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <mallocMC/mallocMC.hpp>
#include <numeric>
#include <vector>

Expand Down Expand Up @@ -75,14 +77,14 @@ ALPAKA_STATIC_ACC_MEM_GLOBAL int* arA = nullptr;

struct ExampleKernel
{
ALPAKA_FN_ACC void operator()(const Acc& acc, ScatterAllocator::AllocatorHandle allocHandle) const
ALPAKA_FN_ACC void operator()(Acc const& acc, ScatterAllocator::AllocatorHandle allocHandle) const
{
const auto id = static_cast<uint32_t>(alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0]);
auto const id = static_cast<uint32_t>(alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0]);
if(id == 0)
arA = (int*) allocHandle.malloc(acc, sizeof(int) * 32);
// wait the the malloc from thread zero is not changing the result for some threads
alpaka::syncBlockThreads(acc);
const auto slots = allocHandle.getAvailableSlots(acc, 1);
auto const slots = allocHandle.getAvailableSlots(acc, 1);
if(arA != nullptr)
{
arA[id] = id;
Expand All @@ -101,14 +103,14 @@ struct ExampleKernel
auto main() -> int
{
auto const platform = alpaka::Platform<Acc>{};
const auto dev = alpaka::getDevByIdx(platform, 0);
auto const dev = alpaka::getDevByIdx(platform, 0);
auto queue = alpaka::Queue<Acc, alpaka::Blocking>{dev};
auto const devProps = alpaka::getAccDevProps<Acc>(dev);
unsigned const block = std::min(static_cast<size_t>(32u), static_cast<size_t>(devProps.m_blockThreadCountMax));

ScatterAllocator scatterAlloc(dev, queue, 1U * 1024U * 1024U * 1024U); // 1GB for device-side malloc

const auto workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{block}, Idx{1}};
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Idx{1}, Idx{block}, Idx{1}};
alpaka::enqueue(queue, alpaka::createTaskKernel<Acc>(workDiv, ExampleKernel{}, scatterAlloc.getAllocatorHandle()));

std::cout << "Slots from Host: " << scatterAlloc.getAvailableSlots(dev, queue, 1) << '\n';
Expand Down
1 change: 1 addition & 0 deletions src/include/mallocMC/alignmentPolicies/Noop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Noop.hpp"

#include <alpaka/core/Common.hpp>

#include <cstdint>
#include <string>
#include <tuple>
Expand Down
2 changes: 2 additions & 0 deletions src/include/mallocMC/alignmentPolicies/Shrink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Shrink.hpp"

#include <alpaka/core/Common.hpp>

#include <cstdint>
#include <iostream>
#include <sstream>
Expand All @@ -50,6 +51,7 @@ namespace mallocMC
{
using type = unsigned int;
};

template<>
struct __PointerEquivalent<8>
{
Expand Down
Loading

0 comments on commit 8c897de

Please sign in to comment.