Skip to content

Commit

Permalink
Automate C++ include file grouping and ordering using clang-format (#…
Browse files Browse the repository at this point in the history
…1349)

This uses the IncludeCategories settings in .clang-format to attempt to enforce our documented #include order in libcuspatial. For discussion, see rapidsai/cudf#15063. This PR uses a subset of the header grouping categories used in that PR.

Note that this also updates the pre-commit configuration to check and correct file copyright years. This comes from rapidsai/cudf#14917.  @KyleFromNVIDIA can you confirm whether or not it's OK to do this? It seems to be working fine.

Closes #1345

Authors:
  - Mark Harris (https://github.com/harrism)

Approvers:
  - Michael Wang (https://github.com/isVoid)

URL: #1349
  • Loading branch information
harrism authored Mar 6, 2024
1 parent f29e404 commit baa1bbb
Show file tree
Hide file tree
Showing 77 changed files with 268 additions and 278 deletions.
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
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

0 comments on commit baa1bbb

Please sign in to comment.