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
…2202)

This uses the IncludeCategories settings in .clang-format to automate include ordering and grouping and to make include ordering more consistent with the rest of RAPIDS. For discussion, see rapidsai/cudf#15063. This PR uses a similar set of header grouping categories used in that PR, adapted for RAFT.

The header reordering in this PR uncovered one place where `#include <cutlass/layout/pitch_linear.h>` was missing from `raft/cpp/include/raft/distance/detail/./pairwise_distance_epilogue_elementwise.h`, so I also added that include.

One purpose of this is to make it easier to automate injection of a header change with an upcoming RMM refactoring (and in the future).

Closes #2193

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

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #2202
  • Loading branch information
harrism authored Mar 6, 2024
1 parent 8cdabd3 commit 04c9b33
Show file tree
Hide file tree
Showing 613 changed files with 2,613 additions and 2,012 deletions.
26 changes: 23 additions & 3 deletions cpp/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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: '^<(common|benchmarks|tests)/' # benchmark/test includes
Priority: 2
#- Regex: '^<(cuspatial_test|cuproj_test)/' # cuSpatial/cuProj test includes
# Priority: 3
- Regex: '^<raft/' # RAFT includes
Priority: 3
- Regex: '^<(cudf|cuml|raft|kvikio)' # Other RAPIDS includes
Priority: 4
- Regex: '^<rmm/' # RMM includes
Priority: 5
- Regex: '^<(thrust|cub|cuda)/' # CCCL includes
Priority: 6
- Regex: '^<(cooperative_groups|cuco|cuda|device_types|driver_types|math_constants|nvtx3)' # CUDA includes
Priority: 6
- Regex: '^<.*\..*' # other system includes (e.g. with a '.')
Priority: 7
- Regex: '^<[^.]+' # STL includes (no '.')
Priority: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
Expand Down
10 changes: 6 additions & 4 deletions cpp/bench/ann/src/common/benchmark.cpp
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 @@ -13,19 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// clang-format off
#include "cuda_stub.hpp" // must go first
// clang-format on

#include "ann_types.hpp"

#include <dlfcn.h>
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

#include <filesystem>
#include <memory>
#include <unordered_map>

#include <dlfcn.h>
#include <filesystem>

namespace raft::bench::ann {

struct lib_handle {
Expand Down
5 changes: 3 additions & 2 deletions cpp/bench/ann/src/common/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include "dataset.hpp"
#include "util.hpp"

#include <benchmark/benchmark.h>
#include <raft/core/logger.hpp>

#include <benchmark/benchmark.h>
#include <unistd.h>

#include <algorithm>
#include <chrono>
#include <cmath>
Expand All @@ -34,7 +36,6 @@
#include <numeric>
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>

namespace raft::bench::ann {
Expand Down
5 changes: 4 additions & 1 deletion cpp/bench/ann/src/common/cuda_huge_page_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
#pragma once

#include <raft/core/error.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/detail/error.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <sys/mman.h>

#include <cstddef>
#include <cstring>

namespace raft::mr {
/**
Expand Down
3 changes: 1 addition & 2 deletions cpp/bench/ann/src/common/cuda_pinned_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
#pragma once

#include <rmm/mr/device/device_memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>
#include <rmm/detail/error.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <cstddef>

Expand Down
23 changes: 13 additions & 10 deletions cpp/bench/ann/src/common/cuda_stub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

/*
The content of this header is governed by two preprocessor definitions:
- BUILD_CPU_ONLY - whether none of the CUDA functions are used.
- ANN_BENCH_LINK_CUDART - dynamically link against this string if defined.
______________________________________________________________________________
___________________________________________________________________________________
|BUILD_CPU_ONLY | ANN_BENCH_LINK_CUDART | cudart | cuda_runtime_api.h |
| | | found | needed | included |
|---------|-----------------------|-----------|---------|--------------------|
| ON | <not defined> | false | false | NO |
| ON | "cudart.so.xx.xx" | false | false | NO |
| OFF | <nod defined> | true | true | YES |
| OFF | "cudart.so.xx.xx" | <runtime> | true | YES |
------------------------------------------------------------------------------
| | | found | needed | included |
|---------------|-----------------------|-----------|---------|--------------------|
| ON | <not defined> | false | false | NO |
| ON | "cudart.so.xx.xx" | false | false | NO |
| OFF | <not defined> | true | true | YES |
| OFF | "cudart.so.xx.xx" | <runtime> | true | YES |
------------------------------------------------------------------------------------
*/

#pragma once

#ifndef BUILD_CPU_ONLY
#include <cuda_fp16.h>
#include <cuda_runtime_api.h>
#ifdef ANN_BENCH_LINK_CUDART
#include <cstring>
#include <dlfcn.h>

#include <cstring>
#endif
#else
#include <cstdint>

typedef void* cudaStream_t;
typedef void* cudaEvent_t;
typedef uint16_t half;
Expand Down
5 changes: 3 additions & 2 deletions cpp/bench/ann/src/common/thread_pool.hpp
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,11 +15,12 @@
*/
#pragma once

#include <omp.h>

#include <atomic>
#include <future>
#include <memory>
#include <mutex>
#include <omp.h>
#include <stdexcept>
#include <thread>
#include <utility>
Expand Down
11 changes: 5 additions & 6 deletions cpp/bench/ann/src/common/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@
#include <sys/stat.h>
#include <sys/types.h>

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <filesystem>
#include <functional>
#include <mutex>
#include <optional>
#include <sstream>
#include <string>
#include <vector>

#include <atomic>
#include <condition_variable>
#include <filesystem>
#include <functional>
#include <optional>

namespace raft::bench::ann {

/**
Expand Down
13 changes: 7 additions & 6 deletions cpp/bench/ann/src/faiss/faiss_cpu_benchmark.cpp
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 @@ -14,6 +14,12 @@
* limitations under the License.
*/

#include "../common/ann_types.hpp"
#include "faiss_cpu_wrapper.h"

#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

#include <algorithm>
#include <cmath>
#include <memory>
Expand All @@ -22,11 +28,6 @@
#include <type_traits>
#include <utility>

#include "../common/ann_types.hpp"
#include "faiss_cpu_wrapper.h"
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

namespace raft::bench::ann {

template <typename T>
Expand Down
16 changes: 9 additions & 7 deletions cpp/bench/ann/src/faiss/faiss_gpu_benchmark.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 @@ -14,6 +14,14 @@
* limitations under the License.
*/

#include "../common/ann_types.hpp"

#undef WARP_SIZE
#include "faiss_gpu_wrapper.h"

#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

#include <algorithm>
#include <cmath>
#include <memory>
Expand All @@ -22,12 +30,6 @@
#include <type_traits>
#include <utility>

#include "../common/ann_types.hpp"
#undef WARP_SIZE
#include "faiss_gpu_wrapper.h"
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

namespace raft::bench::ann {

template <typename T>
Expand Down
11 changes: 6 additions & 5 deletions cpp/bench/ann/src/ggnn/ggnn_benchmark.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
* limitations under the License.
*/

#include "../common/ann_types.hpp"
#include "ggnn_wrapper.cuh"

#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

#include <algorithm>
#include <cmath>
#include <memory>
Expand All @@ -22,11 +28,6 @@
#include <type_traits>
#include <utility>

#include "../common/ann_types.hpp"
#include "ggnn_wrapper.cuh"
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

namespace raft::bench::ann {

template <typename T>
Expand Down
3 changes: 2 additions & 1 deletion cpp/bench/ann/src/ggnn/ggnn_wrapper.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#include "../common/ann_types.hpp"
#include "../common/util.hpp"

#include <ggnn/cuda_knn_ggnn_gpu_instance.cuh>
#include <raft/util/cudart_utils.hpp>

#include <ggnn/cuda_knn_ggnn_gpu_instance.cuh>

#include <memory>
#include <stdexcept>

Expand Down
10 changes: 5 additions & 5 deletions cpp/bench/ann/src/hnswlib/hnswlib_benchmark.cpp
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,6 +15,10 @@
*/

#include "../common/ann_types.hpp"
#include "hnswlib_wrapper.h"

#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

#include <algorithm>
#include <cmath>
Expand All @@ -24,10 +28,6 @@
#include <type_traits>
#include <utility>

#include "hnswlib_wrapper.h"
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>

namespace raft::bench::ann {

template <typename T>
Expand Down
9 changes: 5 additions & 4 deletions cpp/bench/ann/src/hnswlib/hnswlib_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
#pragma once

#include "../common/ann_types.hpp"
#include "../common/thread_pool.hpp"

#include <hnswlib/hnswlib.h>

#include <algorithm>
#include <atomic>
#include <cassert>
Expand All @@ -31,10 +36,6 @@
#include <utility>
#include <vector>

#include "../common/ann_types.hpp"
#include "../common/thread_pool.hpp"
#include <hnswlib/hnswlib.h>

namespace raft::bench::ann {

template <typename T>
Expand Down
1 change: 1 addition & 0 deletions cpp/bench/ann/src/raft/raft_cagra_hnswlib_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "../hnswlib/hnswlib_wrapper.h"
#include "raft_cagra_wrapper.h"

#include <memory>

namespace raft::bench::ann {
Expand Down
Loading

0 comments on commit 04c9b33

Please sign in to comment.