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

Automate C++ include file grouping and ordering using clang-format #1349

Merged
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
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.

repos:
- repo: https://github.com/PyCQA/isort
Expand Down Expand Up @@ -39,14 +39,19 @@ repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
args: ["--config pyproject.toml"]
additional_dependencies: ["tomli"]
- id: codespell
args: ["--config pyproject.toml"]
additional_dependencies: ["tomli"]
- repo: https://github.com/rapidsai/dependency-file-generator
rev: v1.8.0
hooks:
- id: rapids-dependency-file-generator
args: ["--clean"]
- repo: https://github.com/rapidsai/pre-commit-hooks
rev: v0.0.1
hooks:
- id: verify-copyright


default_language_version:
python: python3
28 changes: 24 additions & 4 deletions cpp/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
Expand All @@ -27,7 +27,7 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
Expand Down Expand Up @@ -71,8 +71,28 @@ ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"' # quoted includes
Priority: 1
- Regex: '^<(benchmarks|tests)/' # benchmark includes
Priority: 2
- Regex: '^<(cuspatial_test|cuproj_test)/' # cuSpatial/cuProj test includes
Priority: 3
- Regex: '^<(cuspatial|cuproj)/' # cuSpatial/cuProj includes
Priority: 4
- Regex: '^<(cudf_test|cudf|cuml|raft|kvikio)' # Other RAPIDS includes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about removing cuml/raft/kvikio since they are not used, should it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I'm also trying to keep things relatively consistent across RAPIDS repos. But I'm not confident in that direction. Thoughts?

Copy link
Contributor

@isVoid isVoid Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not confident either - especially if we apply this remove-not-used rule, then what about the cuda libraries below? If we remove cuda rules, are we sure that future contributors do not use them?

From that end, I think the future-facing approach is to maintain the disjunction set from all RAPIDS libraries to embed the collective behavioral customs. This reduces possible conflicts when migrating code or merging repos.

Priority: 5
- Regex: '^<rmm/' # RMM includes
Priority: 6
- Regex: '^<(thrust|cub|cuda)/' # CCCL includes
Priority: 7
- Regex: '^<(cooperative_groups|cuco|cuda.h|cuda_runtime|device_types|driver_types|math_constants|nvtx3)' # CUDA includes
Priority: 7
- Regex: '^<.*\..*' # other system includes (e.g. with a '.')
Priority: 8
- Regex: '^<[^.]+' # STL includes (no '.')
Priority: 9
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/distance/hausdorff_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,11 @@
* limitations under the License.
*/

#include <cuspatial/distance.hpp>

#include <benchmarks/fixture/benchmark_fixture.hpp>
#include <benchmarks/synchronization/synchronization.hpp>

#include <cuspatial/distance.hpp>

#include <cudf/detail/iterator.cuh>
#include <cudf_test/column_wrapper.hpp>

Expand Down
5 changes: 3 additions & 2 deletions cpp/benchmarks/distance/pairwise_linestring_distance.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,15 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <cuspatial_test/geometry_generator.cuh>

#include <cuspatial/distance.cuh>

#include <rmm/cuda_stream_view.hpp>

#include <nvbench/nvbench.cuh>

using namespace cuspatial;

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,15 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <cuspatial_test/geometry_generator.cuh>

#include <cuspatial/distance.cuh>

#include <rmm/cuda_stream_view.hpp>

#include <nvbench/nvbench.cuh>

using namespace cuspatial;

template <typename T>
Expand Down
5 changes: 3 additions & 2 deletions cpp/benchmarks/distance/pairwise_point_polygon_distance.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <cuspatial_test/geometry_generator.cuh>

Expand All @@ -25,6 +24,8 @@
#include <rmm/cuda_stream_view.hpp>
#include <rmm/exec_policy.hpp>

#include <nvbench/nvbench.cuh>

using namespace cuspatial;
using namespace cuspatial::test;

Expand Down
11 changes: 6 additions & 5 deletions cpp/benchmarks/indexing/quadtree_on_points.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,18 +14,19 @@
* limitations under the License.
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>

#include <cuspatial/geometry/vec_2d.hpp>
#include <cuspatial/point_quadtree.cuh>

#include <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/device_vector.hpp>

#include <rmm/exec_policy.hpp>

#include <thrust/host_vector.h>

#include <nvbench/nvbench.cuh>

using namespace cuspatial;

template <typename T>
Expand Down
5 changes: 3 additions & 2 deletions cpp/benchmarks/point_in_polygon/point_in_polygon.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>
#include <nvbench/nvbench.cuh>

#include <cuspatial_test/geometry_generator.cuh>

Expand All @@ -27,6 +26,8 @@

#include <thrust/iterator/counting_iterator.h>

#include <nvbench/nvbench.cuh>

#include <memory>
#include <numeric>

Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/points_in_range/points_in_range.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,14 +26,14 @@
#include <rmm/device_uvector.hpp>
#include <rmm/exec_policy.hpp>

#include <nvbench/nvbench.cuh>

#include <thrust/iterator/counting_iterator.h>
#include <thrust/random/linear_congruential_engine.h>
#include <thrust/random/normal_distribution.h>
#include <thrust/random/uniform_int_distribution.h>
#include <thrust/tabulate.h>

#include <nvbench/nvbench.cuh>

#include <memory>

using cuspatial::vec_2d;
Expand Down
26 changes: 9 additions & 17 deletions cpp/benchmarks/synchronization/synchronization.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,14 @@
* limitations under the License.
*/

#pragma once

#include <rmm/cuda_stream_view.hpp>

#include <driver_types.h>

#include <benchmark/benchmark.h>

/**
* @file synchronization.hpp
* @brief This is the header file for `cuda_event_timer`.
Expand Down Expand Up @@ -52,22 +60,8 @@
// Register the function as a benchmark. You will need to set the `UseManualTime()`
// flag in order to use the timer embedded in this class.
BENCHMARK(sample_cuda_benchmark)->UseManualTime();


**/

#ifndef CUDF_BENCH_SYNCHRONIZATION_H
#define CUDF_BENCH_SYNCHRONIZATION_H

// Google Benchmark library
#include <benchmark/benchmark.h>

#include <cudf/types.hpp>

#include <rmm/cuda_stream_view.hpp>

#include <driver_types.h>

class cuda_event_timer {
public:
/**
Expand Down Expand Up @@ -99,5 +93,3 @@ class cuda_event_timer {
rmm::cuda_stream_view stream;
benchmark::State* p_state;
};

#endif
7 changes: 4 additions & 3 deletions cpp/benchmarks/utility/floating_point_equality.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

#include <benchmarks/fixture/rmm_pool_raii.hpp>

#include <cuspatial_test/random.cuh>

#include <cuspatial/detail/utility/floating_point.cuh>
Expand All @@ -23,10 +24,10 @@
#include <rmm/device_vector.hpp>
#include <rmm/exec_policy.hpp>

#include <nvbench/nvbench.cuh>

#include <thrust/tabulate.h>

#include <nvbench/nvbench.cuh>

#include <memory>
#include <type_traits>

Expand Down
26 changes: 9 additions & 17 deletions cpp/cuproj/benchmarks/synchronization/synchronization.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
* Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,14 @@
* limitations under the License.
*/

#pragma once

#include <rmm/cuda_stream_view.hpp>

#include <driver_types.h>

#include <benchmark/benchmark.h>

/**
* @file synchronization.hpp
* @brief This is the header file for `cuda_event_timer`.
Expand Down Expand Up @@ -52,22 +60,8 @@
// Register the function as a benchmark. You will need to set the `UseManualTime()`
// flag in order to use the timer embedded in this class.
BENCHMARK(sample_cuda_benchmark)->UseManualTime();


**/

#ifndef CUDF_BENCH_SYNCHRONIZATION_H
#define CUDF_BENCH_SYNCHRONIZATION_H

// Google Benchmark library
#include <benchmark/benchmark.h>

#include <cudf/types.hpp>

#include <rmm/cuda_stream_view.hpp>

#include <driver_types.h>

class cuda_event_timer {
public:
/**
Expand Down Expand Up @@ -99,5 +93,3 @@ class cuda_event_timer {
rmm::cuda_stream_view stream;
benchmark::State* p_state;
};

#endif
Loading
Loading