Skip to content

Commit 41a6471

Browse files
committed
Initial commit
0 parents  commit 41a6471

File tree

7 files changed

+673
-0
lines changed

7 files changed

+673
-0
lines changed

.clang-format

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
# Refer to the following link for the explanation of each params:
3+
# http://releases.llvm.org/8.0.0/tools/clang/docs/ClangFormatStyleOptions.html
4+
Language: Cpp
5+
# BasedOnStyle: Google
6+
AccessModifierOffset: -1
7+
AlignAfterOpenBracket: Align
8+
AlignConsecutiveAssignments: true
9+
AlignConsecutiveBitFields: true
10+
AlignConsecutiveDeclarations: false
11+
AlignConsecutiveMacros: true
12+
AlignEscapedNewlines: Left
13+
AlignOperands: true
14+
AlignTrailingComments: true
15+
AllowAllArgumentsOnNextLine: true
16+
AllowAllConstructorInitializersOnNextLine: true
17+
AllowAllParametersOfDeclarationOnNextLine: true
18+
AllowShortBlocksOnASingleLine: true
19+
AllowShortCaseLabelsOnASingleLine: true
20+
AllowShortEnumsOnASingleLine: true
21+
AllowShortFunctionsOnASingleLine: All
22+
AllowShortIfStatementsOnASingleLine: true
23+
AllowShortLambdasOnASingleLine: true
24+
AllowShortLoopsOnASingleLine: false
25+
# This is deprecated
26+
AlwaysBreakAfterDefinitionReturnType: None
27+
AlwaysBreakAfterReturnType: None
28+
AlwaysBreakBeforeMultilineStrings: true
29+
AlwaysBreakTemplateDeclarations: Yes
30+
BinPackArguments: false
31+
BinPackParameters: false
32+
BraceWrapping:
33+
AfterClass: false
34+
AfterControlStatement: false
35+
AfterEnum: false
36+
AfterFunction: false
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
AfterExternBlock: false
42+
BeforeCatch: false
43+
BeforeElse: false
44+
IndentBraces: false
45+
# disabling the below splits, else, they'll just add to the vertical length of source files!
46+
SplitEmptyFunction: false
47+
SplitEmptyRecord: false
48+
SplitEmptyNamespace: false
49+
BreakAfterJavaFieldAnnotations: false
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeBraces: WebKit
52+
BreakBeforeInheritanceComma: false
53+
BreakBeforeTernaryOperators: true
54+
BreakConstructorInitializersBeforeComma: false
55+
BreakConstructorInitializers: BeforeColon
56+
BreakInheritanceList: BeforeColon
57+
BreakStringLiterals: true
58+
ColumnLimit: 100
59+
CommentPragmas: '^ IWYU pragma:'
60+
CompactNamespaces: false
61+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
62+
# Kept the below 2 to be the same as `IndentWidth` to keep everything uniform
63+
ConstructorInitializerIndentWidth: 2
64+
ContinuationIndentWidth: 2
65+
Cpp11BracedListStyle: true
66+
DerivePointerAlignment: false
67+
DisableFormat: false
68+
ExperimentalAutoDetectBinPacking: false
69+
FixNamespaceComments: true
70+
ForEachMacros:
71+
- foreach
72+
- Q_FOREACH
73+
- BOOST_FOREACH
74+
IncludeBlocks: Preserve
75+
IncludeIsMainRegex: '([-_](test|unittest))?$'
76+
IndentCaseLabels: true
77+
IndentPPDirectives: None
78+
IndentWidth: 2
79+
IndentWrappedFunctionNames: false
80+
JavaScriptQuotes: Leave
81+
JavaScriptWrapImports: true
82+
KeepEmptyLinesAtTheStartOfBlocks: false
83+
MacroBlockBegin: ''
84+
MacroBlockEnd: ''
85+
MaxEmptyLinesToKeep: 1
86+
NamespaceIndentation: None
87+
ObjCBinPackProtocolList: Never
88+
ObjCBlockIndentWidth: 2
89+
ObjCSpaceAfterProperty: false
90+
ObjCSpaceBeforeProtocolList: true
91+
PenaltyBreakAssignment: 2
92+
PenaltyBreakBeforeFirstCallParameter: 1
93+
PenaltyBreakComment: 300
94+
PenaltyBreakFirstLessLess: 120
95+
PenaltyBreakString: 1000
96+
PenaltyBreakTemplateDeclaration: 10
97+
PenaltyExcessCharacter: 1000000
98+
PenaltyReturnTypeOnItsOwnLine: 200
99+
PointerAlignment: Left
100+
RawStringFormats:
101+
- Language: Cpp
102+
Delimiters:
103+
- cc
104+
- CC
105+
- cpp
106+
- Cpp
107+
- CPP
108+
- 'c++'
109+
- 'C++'
110+
CanonicalDelimiter: ''
111+
- Language: TextProto
112+
Delimiters:
113+
- pb
114+
- PB
115+
- proto
116+
- PROTO
117+
EnclosingFunctions:
118+
- EqualsProto
119+
- EquivToProto
120+
- PARSE_PARTIAL_TEXT_PROTO
121+
- PARSE_TEST_PROTO
122+
- PARSE_TEXT_PROTO
123+
- ParseTextOrDie
124+
- ParseTextProtoOrDie
125+
CanonicalDelimiter: ''
126+
BasedOnStyle: google
127+
# Enabling comment reflow causes doxygen comments to be messed up in their formats!
128+
ReflowComments: true
129+
SortIncludes: true
130+
SortUsingDeclarations: true
131+
SpaceAfterCStyleCast: false
132+
SpaceAfterTemplateKeyword: true
133+
SpaceBeforeAssignmentOperators: true
134+
SpaceBeforeCpp11BracedList: false
135+
SpaceBeforeCtorInitializerColon: true
136+
SpaceBeforeInheritanceColon: true
137+
SpaceBeforeParens: ControlStatements
138+
SpaceBeforeRangeBasedForLoopColon: true
139+
SpaceBeforeSquareBrackets: false
140+
SpaceInEmptyBlock: false
141+
SpaceInEmptyParentheses: false
142+
SpacesBeforeTrailingComments: 2
143+
SpacesInAngles: false
144+
SpacesInConditionalStatement: false
145+
SpacesInContainerLiterals: true
146+
SpacesInCStyleCastParentheses: false
147+
SpacesInParentheses: false
148+
SpacesInSquareBrackets: false
149+
Standard: c++17
150+
StatementMacros:
151+
- Q_UNUSED
152+
- QT_REQUIRE_VERSION
153+
# Be consistent with indent-width, even for people who use tab for indentation!
154+
TabWidth: 2
155+
UseTab: Never

.clang-tidy

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
Checks: 'clang-diagnostic-*,
3+
clang-analyzer-*,
4+
cppcoreguidelines-*,
5+
modernize-*,
6+
bugprone-*,
7+
performance-*,
8+
readability-*,
9+
llvm-*,
10+
-cppcoreguidelines-macro-usage,
11+
-llvm-header-guard,
12+
-modernize-use-trailing-return-type,
13+
-readability-named-parameter,
14+
-bugprone-easily-swappable-parameters'
15+
WarningsAsErrors: ''
16+
HeaderFilterRegex: ''
17+
AnalyzeTemporaryDtors: false
18+
FormatStyle: none
19+
CheckOptions:
20+
- key: cert-dcl16-c.NewSuffixes
21+
value: 'L;LL;LU;LLU'
22+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
23+
value: '0'
24+
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
25+
value: '0'
26+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
27+
value: '1'
28+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
29+
value: '1'
30+
- key: google-readability-braces-around-statements.ShortStatementLines
31+
value: '1'
32+
- key: google-readability-function-size.StatementThreshold
33+
value: '800'
34+
- key: google-readability-namespace-comments.ShortNamespaceLines
35+
value: '10'
36+
- key: google-readability-namespace-comments.SpacesBeforeComments
37+
value: '2'
38+
- key: llvm-else-after-return.WarnOnConditionVariables
39+
value: '0'
40+
- key: llvm-else-after-return.WarnOnUnfixable
41+
value: '0'
42+
- key: llvm-qualified-auto.AddConstToQualified
43+
value: '0'
44+
- key: modernize-loop-convert.MaxCopySize
45+
value: '16'
46+
- key: modernize-loop-convert.MinConfidence
47+
value: reasonable
48+
- key: modernize-loop-convert.NamingStyle
49+
value: CamelCase
50+
- key: modernize-pass-by-value.IncludeStyle
51+
value: llvm
52+
- key: modernize-replace-auto-ptr.IncludeStyle
53+
value: llvm
54+
- key: modernize-use-nullptr.NullMacros
55+
value: 'NULL'
56+
- key: readability-identifier-length.IgnoredParameterNames
57+
value: 'mr|os'
58+
- key: readability-identifier-length.IgnoredVariableNames
59+
value: 'mr|_'
60+
#- key: readability-function-cognitive-complexity.IgnoreMacros
61+
# value: '1'
62+
- key: bugprone-easily-swappable-parameters.IgnoredParameterNames
63+
value: 'alignment'
64+
- key: cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues
65+
value: '1'
66+
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
67+
value: '1'
68+
...

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.cache/**
2+
build/**
3+
4+
compile_commands.json
5+
settings.json

CMakeLists.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cmake_minimum_required(VERSION 3.20.1 FATAL_ERROR)
2+
3+
project(StreamSafetyFirst
4+
VERSION 00.01.00
5+
LANGUAGES CXX CUDA)
6+
7+
# ---- Dependencies ----
8+
9+
# ---- Get CPM ----
10+
11+
set(CPM_DOWNLOAD_VERSION 0.34.0)
12+
13+
if(CPM_SOURCE_CACHE)
14+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
15+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
16+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
17+
else()
18+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
19+
endif()
20+
21+
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
22+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
23+
file(DOWNLOAD
24+
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
25+
${CPM_DOWNLOAD_LOCATION}
26+
)
27+
endif()
28+
29+
include(${CPM_DOWNLOAD_LOCATION})
30+
31+
CPMAddPackage("gh:catchorg/[email protected]")
32+
33+
if(NOT DEFINED ${CMAKE_CUDA_ARCHITECTURES})
34+
set(CMAKE_CUDA_ARCHITECTURES 70 CACHE STRING "CUDA architectures" FORCE)
35+
endif()
36+
message ("CUDA ARCHS: ${CMAKE_CUDA_ARCHITECTURES}")
37+
38+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
39+
40+
# ---- Create ranger library ----
41+
42+
# library targets
43+
add_library(ranger INTERFACE)
44+
add_library(ranger::ranger ALIAS ranger)
45+
46+
target_include_directories(ranger INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
47+
"$<INSTALL_INTERFACE:include>")
48+
49+
# install export targets
50+
install(TARGETS ranger EXPORT ranger-exports)
51+
install(DIRECTORY include/ranger/ DESTINATION include/ranger)
52+
53+
# ---- Built test binary ----
54+
55+
add_executable(ranger_test test_ranger.cu)
56+
target_link_libraries(ranger_test Catch2 ranger)
57+
target_compile_features(ranger_test PRIVATE cxx_std_17)
58+
59+
# ---- Enable testing ----
60+
61+
enable_testing()
62+
add_test(ranger_test ranger_test)

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Ranger: CUDA-enabled range helpers for range-based for loops
2+
3+
Facilities for generating simple index ranges for C++ range-based for loops. Includes support for
4+
CUDA grid-stride ranges.
5+
6+
## Examples:
7+
8+
9+
```
10+
// generate values from 0 to N
11+
for (auto i : range(N)) {
12+
std::cout << i << std::endl;
13+
}
14+
```
15+
16+
```
17+
// generate values from `begin` to `end`
18+
for (auto i : range(begin, end)) {
19+
std::cout << i << std::endl;
20+
}
21+
```
22+
23+
```
24+
// generate values stepping by `step` from `begin` to `end`
25+
for (auto i : range(begin, end, step)) {
26+
std::cout << i << std::endl;
27+
}
28+
```
29+
30+
```
31+
// generate values from 0 to N in a kernel
32+
__global__ void size_kernel(int N, int* out)
33+
{
34+
for (auto i : grid_stride_range(N)) {
35+
out[i] = i;
36+
}
37+
}
38+
```
39+
40+
```
41+
// generate values from begin to N in a kernel
42+
__global__ void begin_end_kernel(int begin, end, int* out)
43+
{
44+
for (auto i : grid_stride_range(begin, end)) {
45+
out[i-begin] = i;
46+
}
47+
}
48+
```
49+
50+
```
51+
// generate values stepping by `step` from 0 to N in a kernel
52+
__global__ void step_kernel(int N, int step, int* out)
53+
{
54+
for (auto i : grid_stride_range(0, N, step)) {
55+
out[i / step] = i;
56+
}
57+
}
58+
```

0 commit comments

Comments
 (0)