Automate C++ include file grouping and ordering using clang-format
Closed this issue · 0 comments
Currently the C++ include files in the RAPIDS codebase are not consistently ordered and grouped.
Inconsistent ordering makes it harder to maintain the codebase, to understand the dependencies,
and to automate changes.
Using clang-format to automate the ordering and grouping of include files will not only add
consistent style, but it will ease automation of changes. For example, We are undertaking a
refactoring of RMM that will replace rmm::mr::device_memory_resource*
with
rmm::device_async_resource-ref
everywhere in RAPIDS (not just cuDF). This requires adding an
include to MANY files across multiple RAPIDS repos. Getting the location of this include correct
everywhere is very difficult without automatic grouping of headers.
I propose to use clang-format's IncludeCategories
settings to automate the ordering and
grouping of include files in the C++ codebase consistently.
Proof-of-concept PRs have been created for RMM and cuDF:
- cuDF: rapidsai/cudf#15063
- RMM: rapidsai#1463
The ordering used for cuDF is given by the following settings.
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"' # quoted includes
Priority: 1
- Regex: '^<(benchmarks|tests)/' # benchmark includes
Priority: 2
- Regex: '^<cudf_test/' # cuDF includes
Priority: 3
- Regex: '^<cudf/' # cuDF includes
Priority: 4
- Regex: '^<(nvtext|cudf_kafka)' # other libcudf includes
Priority: 5
- Regex: '^<(cugraph|cuml|cuspatial|raft|kvikio)' # Other RAPIDS includes
Priority: 6
- Regex: '^<rmm/' # RMM includes
Priority: 7
- Regex: '^<(thrust|cub|cuda)/' # CCCL includes
Priority: 8
- Regex: '^<(cooperative_groups|cuco|cuda.h|cuda_runtime|device_types|math_constants|nvtx3)' # CUDA includes
Priority: 8
- Regex: '^<.*\..*' # other system includes (e.g. with a '.')
Priority: 9
- Regex: '^<[^.]+' # STL includes (no '.')
Priority: 10