Skip to content

Commit 20eb64a

Browse files
authored
Add .clang-tidy and fix clang-tidy warnings (rapidsai#857)
Adds a .clang-tidy configuration file. This does not add CI tests yet, but I wanted to get it ready to do so without forcing it on anyone. As-is, this PR will enable clang-tidy "yellow squiggles" if you use clangd in vscode. Starting with these Checks: ``` Checks: 'clang-diagnostic-*, clang-analyzer-*, cppcoreguidelines-*, modernize-*, bugprone-*, performance-*, readability-*, llvm-*, -modernize-use-trailing-return-type' ``` Here is a list of warnings fixed * readability-identifier-length * cppcoreguidelines-special-member-functions * modernize-use-nodiscard * modernize-use-nullptr * cppcoreguidelines-pro-type-cstyle-cast (ignore locally for CUDA-defined stream constants) * performance-noexcept-move-constructor * readability-function-cognitive-complexity * readability-qualified-auto * modernize-concat-nested-namespaces * readability-isolate-declaration * readability-redundant-member-init * modernize-use-override * modernize-avoid-c-arrays * cppcoreguidelines-pro-bounds-array-to-pointer-decay * cppcoreguidelines-pro-bounds-constant-array-index * bugprone-narrowing-conversions * readability-implicit-bool-conversion * readability-redundant-smartptr-get * llvm-else-after-return * readability-uppercase-literal-suffix * readability-braces-around-statements * cppcoreguidelines-avoid-magic-numbers * performance-unnecessary-value-param * bugprone-macro-parentheses * performance-faster-string-find NOLINT lines have been added where fixes are unavailable, such as with necessary pointer arithmetic or `reinterpret_cast` calls. I have a private branch of google test which adds NOLINT lines to suppress warnings caused by gtest's code. I plan to make a PR for this. There are still a couple of outstanding warnings having to do with "easily swappable parameters" (e.g. when a function takes two sizes. Fixing these requires breaking API changes. Alternatively we could suppress them.) Authors: - Mark Harris (https://github.com/harrism) Approvers: - Jake Hemstad (https://github.com/jrhemstad) - Rong Ou (https://github.com/rongou) - GALI PREM SAGAR (https://github.com/galipremsagar) URL: rapidsai#857
1 parent fe53a72 commit 20eb64a

File tree

70 files changed

+2402
-2093
lines changed

Some content is hidden

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

70 files changed

+2402
-2093
lines changed

.clang-tidy

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

benchmarks/cuda_stream_pool/cuda_stream_pool_bench.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,36 +14,36 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <benchmark/benchmark.h>
18-
1917
#include <rmm/cuda_stream_pool.hpp>
2018
#include <rmm/detail/error.hpp>
2119

2220
#include <cuda_runtime_api.h>
2321

22+
#include <benchmark/benchmark.h>
23+
2424
#include <stdexcept>
2525

2626
static void BM_StreamPoolGetStream(benchmark::State& state)
2727
{
2828
rmm::cuda_stream_pool stream_pool{};
2929

30-
for (auto _ : state) {
31-
auto s = stream_pool.get_stream();
32-
cudaStreamQuery(s.value());
30+
for (auto _ : state) { // NOLINT(clang-analyzer-deadcode.DeadStores)
31+
auto stream = stream_pool.get_stream();
32+
cudaStreamQuery(stream.value());
3333
}
3434

35-
state.SetItemsProcessed(state.iterations());
35+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()));
3636
}
3737
BENCHMARK(BM_StreamPoolGetStream)->Unit(benchmark::kMicrosecond);
3838

3939
static void BM_CudaStreamClass(benchmark::State& state)
4040
{
41-
for (auto _ : state) {
42-
auto s = rmm::cuda_stream{};
43-
cudaStreamQuery(s.view().value());
41+
for (auto _ : state) { // NOLINT(clang-analyzer-deadcode.DeadStores)
42+
auto stream = rmm::cuda_stream{};
43+
cudaStreamQuery(stream.view().value());
4444
}
4545

46-
state.SetItemsProcessed(state.iterations());
46+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()));
4747
}
4848
BENCHMARK(BM_CudaStreamClass)->Unit(benchmark::kMicrosecond);
4949

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,33 +14,35 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include <benchmark/benchmark.h>
18-
19-
#include <cuda_runtime_api.h>
2017
#include <rmm/device_uvector.hpp>
2118
#include <rmm/device_vector.hpp>
2219
#include <rmm/mr/device/cuda_memory_resource.hpp>
2320
#include <rmm/mr/device/per_device_resource.hpp>
2421
#include <rmm/mr/device/pool_memory_resource.hpp>
2522

23+
#include <benchmark/benchmark.h>
24+
25+
#include <cuda_runtime_api.h>
26+
2627
static void BM_UvectorSizeConstruction(benchmark::State& state)
2728
{
2829
rmm::mr::cuda_memory_resource cuda_mr{};
2930
rmm::mr::pool_memory_resource<rmm::mr::cuda_memory_resource> mr{&cuda_mr};
3031
rmm::mr::set_current_device_resource(&mr);
3132

32-
for (auto _ : state) {
33+
for (auto _ : state) { // NOLINT(clang-analyzer-deadcode.DeadStores)
3334
rmm::device_uvector<int32_t> vec(state.range(0), rmm::cuda_stream_view{});
3435
cudaDeviceSynchronize();
3536
}
3637

37-
state.SetItemsProcessed(state.iterations());
38+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()));
3839

3940
rmm::mr::set_current_device_resource(nullptr);
4041
}
42+
4143
BENCHMARK(BM_UvectorSizeConstruction)
42-
->RangeMultiplier(10)
43-
->Range(10'000, 1'000'000'000)
44+
->RangeMultiplier(10) // NOLINT
45+
->Range(10'000, 1'000'000'000) // NOLINT
4446
->Unit(benchmark::kMicrosecond);
4547

4648
static void BM_ThrustVectorSizeConstruction(benchmark::State& state)
@@ -49,19 +51,19 @@ static void BM_ThrustVectorSizeConstruction(benchmark::State& state)
4951
rmm::mr::pool_memory_resource<rmm::mr::cuda_memory_resource> mr{&cuda_mr};
5052
rmm::mr::set_current_device_resource(&mr);
5153

52-
for (auto _ : state) {
54+
for (auto _ : state) { // NOLINT(clang-analyzer-deadcode.DeadStores)
5355
rmm::device_vector<int32_t> vec(state.range(0));
5456
cudaDeviceSynchronize();
5557
}
5658

57-
state.SetItemsProcessed(state.iterations());
59+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()));
5860

5961
rmm::mr::set_current_device_resource(nullptr);
6062
}
6163

6264
BENCHMARK(BM_ThrustVectorSizeConstruction)
63-
->RangeMultiplier(10)
64-
->Range(10'000, 1'000'000'000)
65+
->RangeMultiplier(10) // NOLINT
66+
->Range(10'000, 1'000'000'000) // NOLINT
6567
->Unit(benchmark::kMicrosecond);
6668

6769
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)