Skip to content

Commit ae755b5

Browse files
authored
Add clang format to pre-commit config (#1450)
* Added clang format to pre-commit config * Install clang-format-12 * Remove AlignConsecutiveAssignments
1 parent 88981b5 commit ae755b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+13242
-11506
lines changed

.clang-format

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,42 @@
11
BasedOnStyle: LLVM
2-
IndentWidth: 4
3-
UseTab: Never
4-
Language: Cpp
5-
Standard: Cpp11
62

73
AccessModifierOffset: -4
84

9-
AlignConsecutiveDeclarations: false
10-
AlignConsecutiveAssignments: false
115
AlignConsecutiveMacros: true
12-
AlignTrailingComments: true
6+
AlignConsecutiveBitFields: true
137
AlignEscapedNewlines: Right
148

15-
AllowShortBlocksOnASingleLine: false
16-
AllowShortCaseLabelsOnASingleLine: false
17-
AllowShortFunctionsOnASingleLine: false
18-
AllowShortIfStatementsOnASingleLine: false
19-
AllowShortLoopsOnASingleLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: Empty
2011

21-
AlwaysBreakBeforeMultilineStrings: true
22-
AlwaysBreakTemplateDeclarations: true
12+
AlwaysBreakTemplateDeclarations: Yes
2313

24-
BinPackArguments: false
2514
BinPackParameters: false
2615

27-
BreakBeforeBraces: Allman
28-
BreakConstructorInitializersBeforeComma: true
29-
3016
BraceWrapping:
17+
AfterCaseLabel: true
3118
AfterClass: true
32-
AfterControlStatement: true
19+
AfterControlStatement: MultiLine
3320
AfterEnum: true
3421
AfterFunction: true
3522
AfterNamespace: true
36-
AfterObjCDeclaration: true
23+
AfterObjCDeclaration: false
3724
AfterStruct: true
3825
AfterUnion: true
39-
BeforeCatch: true
26+
AfterExternBlock: true
27+
BeforeCatch: false
4028
BeforeElse: true
29+
BeforeLambdaBody: false
30+
BeforeWhile: false
4131
IndentBraces: false
32+
SplitEmptyFunction: true
33+
SplitEmptyRecord: true
34+
SplitEmptyNamespace: true
4235
BreakBeforeBraces: Custom
4336

44-
ColumnLimit: 120
45-
CommentPragmas: '.*'
37+
ColumnLimit: 80
4638

47-
IndentCaseLabels: false
39+
IndentWidth: 4
4840
IndentWrappedFunctionNames: true
4941

50-
KeepEmptyLinesAtTheStartOfBlocks: false
51-
NamespaceIndentation: All
52-
53-
PointerAlignment: Left
54-
SpaceAfterCStyleCast: false
55-
SpaceBeforeAssignmentOperators: true
56-
SpaceBeforeParens: ControlStatements
57-
SpaceInEmptyParentheses: false
58-
SpacesInAngles: false
59-
SpacesInCStyleCastParentheses: false
60-
SpacesInParentheses: false
61-
SpacesInSquareBrackets: false
62-
63-
SortIncludes: false
64-
ReflowComments: true
65-
66-
IncludeCategories:
67-
- Regex: '^".*'
68-
Priority: 3
69-
- Regex: '^<.*'
70-
Priority: 2
71-
SortIncludes: true
42+
Standard: c++17

.git-blame-ignore-revs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
2+
3+
# Add pre-commit hooks
4+
b0cd5f85c9b0c2705359fee3a3f4f3feda53bfa0
5+
6+
# Add black to pre-commit config
7+
88981b5ae1c99f9b64758db44dfb39f2c20b10db

.github/workflows/pre-commit.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/[email protected]
13-
- uses: actions/[email protected]
14-
with:
15-
python-version: '3.10'
16-
- uses: pre-commit/[email protected]
12+
- name: Set up clang-format
13+
run: |
14+
sudo apt-get install -y clang-format-12
15+
sudo unlink /usr/bin/clang-format
16+
sudo ln -s /usr/bin/clang-format-12 /usr/bin/clang-format
17+
clang-format --version
18+
19+
- uses: actions/[email protected]
20+
- uses: actions/[email protected]
21+
with:
22+
python-version: '3.10'
23+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ repos:
2828
hooks:
2929
- id: black
3030
args: ["--check", "--diff", "--color"]
31+
- repo: https://github.com/pocc/pre-commit-hooks
32+
rev: v1.3.5
33+
hooks:
34+
- id: clang-format
35+
args: ["-i", "--version=12"]

dpnp/backend/examples/example10.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
* Example 10.
2828
*
2929
* Possible compile line:
30-
* clang++ -fsycl dpnp/backend/examples/example10.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example10 -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core
30+
* clang++ -fsycl dpnp/backend/examples/example10.cpp -Idpnp
31+
* -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o
32+
* example10 -lmkl_sycl -lmkl_intel_ilp64 -lmkl_core
3133
*/
3234

3335
#include <iostream>
@@ -38,21 +40,23 @@
3840

3941
#include <dpnp_iface.hpp>
4042

41-
void test_dpnp_random_normal(
42-
const size_t size, const size_t iters, const size_t seed, const double loc, const double scale)
43+
void test_dpnp_random_normal(const size_t size,
44+
const size_t iters,
45+
const size_t seed,
46+
const double loc,
47+
const double scale)
4348
{
4449
clock_t start, end;
4550
double dev_time_used = 0.0;
4651
double sum_dev_time_used = 0.0;
4752

4853
dpnp_queue_initialize_c(QueueOptions::GPU_SELECTOR);
4954

50-
double* result = (double*)dpnp_memory_alloc_c(size * sizeof(double));
55+
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));
5156

5257
dpnp_rng_srand_c(seed); // TODO: will move
5358

54-
for (size_t i = 0; i < iters; ++i)
55-
{
59+
for (size_t i = 0; i < iters; ++i) {
5660
start = clock();
5761
dpnp_rng_normal_c<double>(result, loc, scale, size);
5862
end = clock();
@@ -70,29 +74,32 @@ void test_dpnp_random_normal(
7074
}
7175

7276
// TODO: name check
73-
void test_mkl_random_normal(
74-
const size_t size, const size_t iters, const size_t seed, const double loc, const double scale)
77+
void test_mkl_random_normal(const size_t size,
78+
const size_t iters,
79+
const size_t seed,
80+
const double loc,
81+
const double scale)
7582
{
7683
clock_t start, end;
7784
double dev_time_used = 0.0;
7885
double sum_dev_time_used = 0.0;
7986

8087
sycl::queue queue{sycl::gpu_selector()};
8188

82-
double* result = reinterpret_cast<double*>(malloc_shared(size * sizeof(double), queue));
83-
if (result == nullptr)
84-
{
89+
double *result =
90+
reinterpret_cast<double *>(malloc_shared(size * sizeof(double), queue));
91+
if (result == nullptr) {
8592
throw std::runtime_error("Error: out of memory.");
8693
}
8794

8895
oneapi::mkl::rng::mt19937 rng_engine(queue, seed);
8996
oneapi::mkl::rng::gaussian<double> distribution(loc, scale);
9097

91-
for (size_t i = 0; i < iters; ++i)
92-
{
98+
for (size_t i = 0; i < iters; ++i) {
9399
start = clock();
94100

95-
auto event_out = oneapi::mkl::rng::generate(distribution, rng_engine, size, result);
101+
auto event_out =
102+
oneapi::mkl::rng::generate(distribution, rng_engine, size, result);
96103
event_out.wait();
97104

98105
end = clock();
@@ -110,7 +117,7 @@ void test_mkl_random_normal(
110117
return;
111118
}
112119

113-
int main(int, char**)
120+
int main(int, char **)
114121
{
115122
const size_t size = 100000000;
116123
const size_t iters = 30;
@@ -119,7 +126,8 @@ int main(int, char**)
119126
const double loc = 0.0;
120127
const double scale = 1.0;
121128

122-
std::cout << "Normal distr. params:\nloc is " << loc << ", scale is " << scale << std::endl;
129+
std::cout << "Normal distr. params:\nloc is " << loc << ", scale is "
130+
<< scale << std::endl;
123131

124132
test_dpnp_random_normal(size, iters, seed, loc, scale);
125133
test_mkl_random_normal(size, iters, seed, loc, scale);

dpnp/backend/examples/example11.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
/**
2727
* Example 11.
2828
*
29-
* This example shows simple usage of the DPNP C++ Backend library RNG shuffle function
30-
* for one and ndim arrays.
29+
* This example shows simple usage of the DPNP C++ Backend library RNG shuffle
30+
* function for one and ndim arrays.
3131
*
3232
* Possible compile line:
33-
* g++ -g dpnp/backend/examples/example11.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example11
33+
* g++ -g dpnp/backend/examples/example11.cpp -Idpnp -Idpnp/backend/include
34+
* -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example11
3435
*
3536
*/
3637

@@ -39,21 +40,21 @@
3940
#include <dpnp_iface.hpp>
4041

4142
template <typename T>
42-
void print_dpnp_array(T* arr, size_t size)
43+
void print_dpnp_array(T *arr, size_t size)
4344
{
4445
std::cout << std::endl;
45-
for (size_t i = 0; i < size; ++i)
46-
{
46+
for (size_t i = 0; i < size; ++i) {
4747
std::cout << arr[i] << ", ";
4848
}
4949
std::cout << std::endl;
5050
}
5151

52-
int main(int, char**)
52+
int main(int, char **)
5353
{
5454
// Two cases:
55-
// 1) array size = 100, ndim = 1, high_dim_size = 10 (aka ndarray with shape (100,) )
56-
// 2) array size = 100, ndim = 2, high_dim_size = 20 (e.g. ndarray with shape (20, 5) and len(array) = 20 )
55+
// 1) array size = 100, ndim = 1, high_dim_size = 10 (aka ndarray with shape
56+
// (100,) ) 2) array size = 100, ndim = 2, high_dim_size = 20 (e.g. ndarray
57+
// with shape (20, 5) and len(array) = 20 )
5758
const size_t ndim_cases = 2;
5859
const size_t itemsize = sizeof(double);
5960
const size_t ndim[ndim_cases] = {1, 2};
@@ -63,9 +64,9 @@ int main(int, char**)
6364

6465
// DPNPC dpnp_rng_shuffle_c
6566
// DPNPC interface
66-
double* array_1 = reinterpret_cast<double*>(dpnp_memory_alloc_c(size * sizeof(double)));
67-
for (size_t i = 0; i < ndim_cases; i++)
68-
{
67+
double *array_1 =
68+
reinterpret_cast<double *>(dpnp_memory_alloc_c(size * sizeof(double)));
69+
for (size_t i = 0; i < ndim_cases; i++) {
6970
std::cout << "\nREPRODUCE: DPNPC dpnp_rng_shuffle_c:";
7071
std::cout << "\nDIMS: " << ndim[i] << std::endl;
7172
// init array 0, 1, 2, 3, 4, 5, 6, ....
@@ -74,7 +75,8 @@ int main(int, char**)
7475
std::cout << "\nINPUT array:";
7576
print_dpnp_array(array_1, size);
7677
dpnp_rng_srand_c(seed);
77-
dpnp_rng_shuffle_c<double>(array_1, itemsize, ndim[i], high_dim_size[i], size);
78+
dpnp_rng_shuffle_c<double>(array_1, itemsize, ndim[i], high_dim_size[i],
79+
size);
7880
// print shuffle result
7981
std::cout << "\nSHUFFLE INPUT array:";
8082
print_dpnp_array(array_1, size);

dpnp/backend/examples/example3.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,44 @@
3131
*
3232
* Possible compile line:
3333
* . /opt/intel/oneapi/setvars.sh
34-
* g++ -g dpnp/backend/examples/example3.cpp -Idpnp -Idpnp/backend/include -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example3
34+
* g++ -g dpnp/backend/examples/example3.cpp -Idpnp -Idpnp/backend/include
35+
* -Ldpnp -Wl,-rpath='$ORIGIN'/dpnp -ldpnp_backend_c -o example3
3536
*
3637
*/
3738

3839
#include <iostream>
3940

4041
#include "dpnp_iface.hpp"
4142

42-
int main(int, char**)
43+
int main(int, char **)
4344
{
4445
const size_t size = 256;
4546

4647
dpnp_queue_initialize_c();
4748
std::cout << "SYCL queue is CPU: " << dpnp_queue_is_cpu_c() << std::endl;
4849

49-
int* array1 = (int*)dpnp_memory_alloc_c(size * sizeof(int));
50-
double* result = (double*)dpnp_memory_alloc_c(size * sizeof(double));
50+
int *array1 = (int *)dpnp_memory_alloc_c(size * sizeof(int));
51+
double *result = (double *)dpnp_memory_alloc_c(size * sizeof(double));
5152

52-
for (size_t i = 0; i < 10; ++i)
53-
{
53+
for (size_t i = 0; i < 10; ++i) {
5454
array1[i] = i;
5555
result[i] = 0;
5656
std::cout << ", " << array1[i];
5757
}
5858
std::cout << std::endl;
5959

6060
const long ndim = 1;
61-
shape_elem_type* shape = reinterpret_cast<shape_elem_type*>(dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
61+
shape_elem_type *shape = reinterpret_cast<shape_elem_type *>(
62+
dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
6263
shape[0] = size;
63-
shape_elem_type* strides = reinterpret_cast<shape_elem_type*>(dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
64+
shape_elem_type *strides = reinterpret_cast<shape_elem_type *>(
65+
dpnp_memory_alloc_c(ndim * sizeof(shape_elem_type)));
6466
strides[0] = 1;
6567

66-
dpnp_cos_c<int, double>(result, size, ndim, shape, strides, array1, size, ndim, shape, strides, NULL);
68+
dpnp_cos_c<int, double>(result, size, ndim, shape, strides, array1, size,
69+
ndim, shape, strides, NULL);
6770

68-
for (size_t i = 0; i < 10; ++i)
69-
{
71+
for (size_t i = 0; i < 10; ++i) {
7072
std::cout << ", " << result[i];
7173
}
7274
std::cout << std::endl;

0 commit comments

Comments
 (0)