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

Remove format_header.sh #1466

Merged
merged 13 commits into from
Jun 28, 2024
Merged

Remove format_header.sh #1466

merged 13 commits into from
Jun 28, 2024

Conversation

MarcelKoch
Copy link
Member

This PR removes the format_header.sh in favor of purely relying on clang-format. The .clang-format is updated to allow regrouping of includes. In total, out of the affected 1000 files, only ~200 have non-whitespace changes. Many of those are regarding the ginkgo main header, or previously missing

Include groups (ordered by their prority)

  1. <oneapi/... since we used force-top with that a lot.
  2. <hip/hip_runtime.h> same
  3. 'main' include
  4. STL
  5. backend library, i.e. cuda/hip/omp/mpi/...
  6. third party library
  7. Ginkgo main header
  8. Ginkgo headers
  9. Other <...> includes
  10. All "..." includes

This is mostly based on the already used regrouping in format_header.sh.

Notable Changes

  • The 'main' header of an implementation file now uses "...", instead of <...>. This is required, since clang-format can't deduce the main header otherwise.
  • force-top is removed and instead handling by using negative priorities in .clang-format. In very few cases this is not sufficient, and there clang-format on/off achieves the same results.
  • Only 1 empty line between separate groups of includes. It is not possible to adjust that with a clang-format setting.
  • The <ginkgo/ginkgo.hpp> header is now ordered after standard library includes
  • Some 'main' headers are not recognized. This concerns especially backend headers, which add stuff to code headers, for example cuda/matrix/batch_struct.hpp will not have core/matrix/batch_struct.hpp as its main header anymore.
  • Split up implementations, like for the Jacobi preconditioner, don't recognize the 'main' header correctly. One solution could be to use the same splitting approach as for CSR/FBCSR kernels.

Since the format_header.sh script is very complex, I think these changes are a small price to removing it.

@ginkgo-bot ginkgo-bot added reg:build This is related to the build system. reg:testing This is related to testing. reg:ci-cd This is related to the continuous integration system. reg:documentation This is related to documentation. reg:example This is related to the examples. reg:benchmarking This is related to benchmarking. type:solver This is related to the solvers type:preconditioner This is related to the preconditioners type:matrix-format This is related to the Matrix formats type:factorization This is related to the Factorizations type:reordering This is related to the matrix(LinOp) reordering reg:helper-scripts This issue/PR is related to the helper scripts mainly concerned with development of Ginkgo. type:multigrid This is related to multigrid type:stopping-criteria This is related to the stopping criteria mod:all This touches all Ginkgo modules. labels Nov 16, 2023
@upsj
Copy link
Member

upsj commented Nov 16, 2023

I like it, if it performs well, this should make IDE integration of our header ordering much smoother

@MarcelKoch
Copy link
Member Author

The non-whitespace diff can be obtained with:

git diff -b -B -w -z --ignore-space-at-eol --ignore-blank-lines 195e5bf3..195e5bf3~1

The diff is also attached here.
diff.txt

@MarcelKoch MarcelKoch self-assigned this Nov 16, 2023
Base automatically changed from use-fixed-clang-format to develop November 16, 2023 18:02
Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

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

LGTM!

@MarcelKoch MarcelKoch added the 1:ST:do-not-merge Please do not merge PR this yet. label Nov 17, 2023
@yhmtsai
Copy link
Member

yhmtsai commented Nov 20, 2023

<oneapi/.. -> <oneapi/dpl... only the dpl need to be on the top. the other oneapi before dpl may also introduce issues.
clang format does not take care of the "" for local and <> from global, so it may still destroy the regroup
hip_runtime should be in hip group. only a few hip tests request it on top which can be handled by clang-format off
9 can be merged into 6?
It changes a lot of the format rules in the documentation
I would say this pr changes the format style not just remove format_header

Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

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

the regroup does not take care the header. for example cb_gmres example

@MarcelKoch
Copy link
Member Author

The main goal of the PR is to remove format_header.sh. The formatting changes are a by product of that.

9 can be merged into 6?

I don't follow, can you elaborate?

the regroup does not take care the header. for example cb_gmres example

Do you mean the wrong comment on the main ginkgo header file?

@MarcelKoch
Copy link
Member Author

clang format does not take care of the "" for local and <> from global, so it may still destroy the regroup

I think it does. Any <> is priority 1-4, the <ginkgo/ headers are priority 5-6, and everything else, which includes "" is priority 7.

@MarcelKoch MarcelKoch force-pushed the remove-format_header branch 2 times, most recently from 70bb6df to 0d2e147 Compare June 14, 2024 12:51
Copy link
Member

@pratikvn pratikvn left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

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

LGTM!

@MarcelKoch MarcelKoch added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:do-not-merge Please do not merge PR this yet. labels Jun 18, 2024
In general, all include statements should be present on the top of the file,
ordered in the following groups, with two blank lines between each group:
ordered in the following groups, with *one* blank lines between each group:

Copy link
Member

Choose a reason for hiding this comment

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

the following is slightly different from the clang_format group rule such as the ginkgo main header is in another group

#include <gtest/gtest.h>


#include <ginkgo/core/base/array.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#include <ginkgo/core/base/array.hpp>
#include "ginkgo/core/base/array.hpp"

such that it can be recognized as a main header

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not the main header. The conversation about main headers only makes sense for files which implement functions defined in a header file. This is not the case for the test files, so there is no main header here.
I think we had a different interpretation of main header previously, which was based on ~vibes~. Now we just follow clangs definition.
So all the comments on the test files are unnecessary. Sorry for not making that clearer before.

Copy link
Member

Choose a reason for hiding this comment

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

with this definition, the opposite part needs to change.
cuda/test/matrix/coo_kernels.cpp uses core/matrix/coo_kernels.hpp as the main header because they are in the mainHeaderSource

Copy link
Member Author

Choose a reason for hiding this comment

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

do you mean cuda/matrix/coo_kernels.cpp? Because there is no cuda/test/matrix/coo_kernels.cpp.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I just randomly pick something might have issue.
something like this: cuda/test/solver/lower_trs_kernels.cu uses core/solver/lower_trs_kernels.hpp

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. This poses an issue, because there doesn't seem to be a way to prevent clang from detecting core/solver/lower_trs_kernels.hpp as main header. I think the simplest choice is to consider these headers as the main header again.

Side note: this particular header is unnecessary. The test doesn't call any kernel directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or we can just ignore it and live with these (small) inconsistencies. That means there will be some tests which have a main header and those that don't.

#include <ginkgo/core/base/exception.hpp>
#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/executor.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <gtest/gtest.h>

#include <ginkgo/core/base/exception_helpers.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/base/index_set.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <gtest/gtest.h>

#include <ginkgo/core/stop/iteration.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <ginkgo/core/base/math.hpp>

#include <ginkgo/core/stop/residual_norm.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <chrono>
#include <thread>

#include <ginkgo/core/stop/time.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <gtest/gtest.h>

#include <ginkgo/core/base/timer.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

#include <ginkgo/core/base/exception.hpp>
#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/csr.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

main header

Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

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

summary of my comments:

  1. oneapi except for dpl should be in the same group as cu/hip...
  2. sde_lib is also from papi. and maybe we can put the priority 4 and 5 together?
  3. some main headers are missed or wrong due to no "".
  4. because dpl in priority -2, we do not need the clang-format on/off to force it. It may apply to runtime but I am not sure the priority 2 is enough for solving the compiling issue.

Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

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

I ignore main header inconsistentence for now.
the onedpl with disabling the clang-format is not changed and some wrong usage of header ""/<> is not resolved yet.

@@ -6,13 +6,11 @@
#define GKO_CORE_BASE_BATCH_MULTI_VECTOR_KERNELS_HPP_


#include <ginkgo/core/base/batch_multi_vector.hpp>

#include "ginkgo/core/base/batch_multi_vector.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

I thought the hpp is out of the maing header check?

Copy link
Member Author

Choose a reason for hiding this comment

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

you're right, I will update this (and the others) accordingly

@@ -6,16 +6,13 @@
#define GKO_CORE_BASE_DEVICE_MATRIX_DATA_KERNELS_HPP_


#include <ginkgo/core/base/device_matrix_data.hpp>

#include "ginkgo/core/base/device_matrix_data.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

same question

#include <ginkgo/core/base/polymorphic_object.hpp>
#include <ginkgo/core/base/types.hpp>
#include <ginkgo/core/matrix/csr.hpp>

#include "ginkgo/core/base/utils.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

because no main header, use <> not ""

@@ -6,14 +6,12 @@
#define GKO_CORE_DISTRIBUTED_INDEX_MAP_KERNELS_HPP_


#include <ginkgo/core/distributed/index_map.hpp>

#include "ginkgo/core/distributed/index_map.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

same question for hpp

#include "core/components/addressable_pq.hpp"
#include "ginkgo/core/reorder/mc64.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

should use <>

MarcelKoch and others added 13 commits June 28, 2024 09:06
changes from: `./dev_tools/scripts/change-main-include.py $(git ls-files)`

This is done based on the heuristic that the first include is the main include, except in some cases.

Here are the cases where the heuristic can't determine either way:

benchmark/utils/mpi_timer.cpp
benchmark/utils/tuning_variables.cpp
core/base/mpi.cpp
core/base/segmented_array.cpp
core/base/version.cpp
core/config/multigrid_config.cpp
core/distributed/index_map.cpp
core/distributed/partition.cpp
core/log/logger.cpp
core/preconditioner/batch_jacobi.cpp
core/stop/combined.cpp
core/stop/criterion.cpp
core/stop/iteration.cpp
core/stop/time.cpp
cuda/base/version.cpp
devices/cuda/executor.cpp
devices/hip/executor.cpp
dpcpp/base/version.dp.cpp
hip/base/version.hip.cpp
omp/base/version.cpp
reference/base/version.cpp
Co-authored-by: Yu-Hsiang M. Tsai <[email protected]>
@MarcelKoch
Copy link
Member Author

I've rebased it after the changes from #1616. It went pretty smoothly. I don't think there are additional changes that were not reviewed before, so I will go a head and merge it when the tests pass.

@MarcelKoch MarcelKoch merged commit 5363f07 into develop Jun 28, 2024
10 of 14 checks passed
@MarcelKoch MarcelKoch deleted the remove-format_header branch June 28, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-to-merge This PR is ready to merge. mod:all This touches all Ginkgo modules. reg:benchmarking This is related to benchmarking. reg:build This is related to the build system. reg:ci-cd This is related to the continuous integration system. reg:documentation This is related to documentation. reg:example This is related to the examples. reg:helper-scripts This issue/PR is related to the helper scripts mainly concerned with development of Ginkgo. reg:testing This is related to testing. type:factorization This is related to the Factorizations type:matrix-format This is related to the Matrix formats type:multigrid This is related to multigrid type:preconditioner This is related to the preconditioners type:reordering This is related to the matrix(LinOp) reordering type:solver This is related to the solvers type:stopping-criteria This is related to the stopping criteria
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants