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

Support iwyu and clang-tidy #298

Merged
merged 4 commits into from
May 6, 2019
Merged

Support iwyu and clang-tidy #298

merged 4 commits into from
May 6, 2019

Conversation

tcojean
Copy link
Member

@tcojean tcojean commented Apr 30, 2019

Add support for clang-tidy 1 and iwyu 2 tools.

Overview

These tools allow to statically find potential programming issues and include
issues, respectively. They are able to find a lot of potential issues (both bugs
or style problems), so they are a useful addition for contributors. For now, no
specific configuration is included but it is possible to give a style file which
would control what we consider to be errors and what are not.

The use of the tools is controlled through the respective GINKGO_WITH_CLANG_TIDY
and GINKGO_WITH_IWYU variables. They are turned off by default, but their
availability is highlighted in the main README.md

Here is an example of what these tools bring in terms of analysis. Looking at what is outputted here, there are actual problems (such as not including memory header).

clang-tidy output for coo_kernels.cpp

/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:95:53: warning: parameter 'exec' is unused [misc-unused-parameters]
void spmv2(std::shared_ptr<const ReferenceExecutor> exec,
                                                    ^~~~~
                                                     /*exec*/
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:95:53: warning: the parameter 'exec' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:105:19: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
            c->at(coo_row[i], j) += coo_val[i] * b->at(coo_col[i], j);
                  ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:105:37: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
            c->at(coo_row[i], j) += coo_val[i] * b->at(coo_col[i], j);
                                    ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:105:56: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
            c->at(coo_row[i], j) += coo_val[i] * b->at(coo_col[i], j);
                                                       ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:114:62: warning: parameter 'exec' is unused [misc-unused-parameters]
void advanced_spmv2(std::shared_ptr<const ReferenceExecutor> exec,
                                                             ^~~~~
                                                              /*exec*/
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:114:62: warning: the parameter 'exec' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:127:19: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
            c->at(coo_row[i], j) +=
                  ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:128:29: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
                alpha_val * coo_val[i] * b->at(coo_col[i], j);
                            ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:128:48: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
                alpha_val * coo_val[i] * b->at(coo_col[i], j);
                                               ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:138:72: warning: parameter 'exec' is unused [misc-unused-parameters]
void convert_row_idxs_to_ptrs(std::shared_ptr<const ReferenceExecutor> exec,
                                                                       ^~~~~
                                                                        /*exec*/
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:138:72: warning: the parameter 'exec' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
void convert_row_idxs_to_ptrs(std::shared_ptr<const ReferenceExecutor> exec,
                              ~~~                                      ^
                              const                                   &
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:167:64: warning: parameter 'exec' is unused [misc-unused-parameters]
void convert_to_dense(std::shared_ptr<const ReferenceExecutor> exec,
                                                               ^~~~~
                                                                /*exec*/
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:167:64: warning: the parameter 'exec' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:182:20: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
        result->at(coo_row[i], coo_col[i]) += coo_val[i];
                   ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:182:32: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
        result->at(coo_row[i], coo_col[i]) += coo_val[i];
                               ^
/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:182:47: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
        result->at(coo_row[i], coo_col[i]) += coo_val[i];

Include What You Use output with coo_kernels.cpp

Warning: include-what-you-use reported diagnostics:

/home/tcojean/Workspace/software/ginkgo-github/core/matrix/coo_kernels.hpp should add these lines:
#include <memory>                         // for shared_ptr
#include "ginkgo/core/base/executor.hpp"  // for DefaultExecutor

/home/tcojean/Workspace/software/ginkgo-github/core/matrix/coo_kernels.hpp should remove these lines:
- #include <ginkgo/core/base/types.hpp>  // lines 37-37
- #include <ginkgo/core/matrix/coo.hpp>  // lines 38-38
- #include <ginkgo/core/matrix/csr.hpp>  // lines 39-39

The full include-list for /home/tcojean/Workspace/software/ginkgo-github/core/matrix/coo_kernels.hpp:
#include <ginkgo/core/matrix/dense.hpp>   // for Dense, Coo, Csr
#include <memory>                         // for shared_ptr
#include "ginkgo/core/base/executor.hpp"  // for DefaultExecutor
---

/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp should add these lines:
#include "ginkgo/core/base/types.hpp"                  // for size_type, GKO...

/home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp should remove these lines:
- #include <ginkgo/core/base/exception_helpers.hpp>  // lines 36-36
- #include <ginkgo/core/base/math.hpp>  // lines 37-37
- #include <ginkgo/core/matrix/csr.hpp>  // lines 38-38

The full include-list for /home/tcojean/Workspace/software/ginkgo-github/reference/matrix/coo_kernels.cpp:
#include "core/matrix/coo_kernels.hpp"
#include <ginkgo/core/matrix/dense.hpp>                // for Dense, Coo, Csr
#include "ginkgo/core/base/types.hpp"                  // for size_type, GKO...
#include "reference/components/format_conversion.hpp"  // for convert_idxs_t...
---

These tools allow to statically find potential programming issues and include
issues, respectively.

The use of the tools is controlled through the respective GINKGO_WITH_CLANG_TIDY
and GINKGO_WITH_IWYU variables. They are turned off by default, but their
availability is highlighted in the main `README.md`

[1]: https://clang.llvm.org/extra/clang-tidy/
[2]: https://include-what-you-use.org/
@tcojean tcojean added is:new-feature A request or implementation of a feature that does not exist yet. reg:build This is related to the build system. labels Apr 30, 2019
@tcojean tcojean self-assigned this Apr 30, 2019
@tcojean tcojean changed the title Support iwyu clang tidy Support iwyu and clang-tidy Apr 30, 2019
@tcojean tcojean changed the title Support iwyu and clang-tidy Support iwyu and clang-tidy Apr 30, 2019
@thoasm
Copy link
Member

thoasm commented May 2, 2019

Very useful tools. However, when I enable both on my system, it stops compiling and I get the following error:

/home/thomas/projects/ginkgo_github_2/omp/matrix/coo_kernels.cpp:36:10: error: 'omp.h' file not found **[clang-diagnostic-error]**

It seems like it does not find the omp.h file, and then just cancels the compilation.
I did this with a complete new cmake and make.
Here is the cmake command I used:

cmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    -DCMAKE_BUILD_TYPE=Debug \
    -DGINKGO_DEVEL_TOOLS=ON -DGINKGO_BUILD_TESTS=ON \
    -DGINKGO_BUILD_REFERENCE=ON -DGINKGO_BUILD_OMP=ON -DGINKGO_BUILD_CUDA=ON -DGINKGO_CUDA_ARCHITECTURES="50" \
    -DBUILD_SHARED_LIBS=ON \
    -DGINKGO_WITH_CLANG_TIDY=ON \
    -DGINKGO_WITH_IWYU=ON -DGINKGO_IWYU_PATH="/home/thomas/software/include-what-you-use/build/bin/include-what-you-use" \
    ../..

Is there a way to prevent this issue? I think it would be nice if it would only add information as warnings, so it would still compile, even if there are many issues.

@thoasm
Copy link
Member

thoasm commented May 2, 2019

I tested it without the iwyu, and it still crashed with the same error, so the clang-tidy does not work properly on my system. Is there a way to forward the OpenMP information to clang-tidy, or to tell clang-tidy to ignore this header file?

@thoasm
Copy link
Member

thoasm commented May 2, 2019

Testing it with iwyu only works on my system, so it definitively looks like clang-tidy is the problem for me.
On a different topic: Is there a way for this to be run on the CI system? I think it would be very useful information when doing code review.

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

The behavior you have with clang-tidy is weird, by default I believe everything is treated as a warning. I will try to see whether I can reproduce this and if there is a way around this.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

I have clang version clang 8.0.0-4 if that helps.

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

Did you install the openmp package? Maybe the problem is that you do not have OpenMP support with clang? In my case, I do not get this error.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

Do I have to install an OpenMP package on Arch linux? I thought it always comes with the compiler.
I at least did not do that. Unfortunately, I cannot test that right now since it happened on my work laptop, which I did not bring with me. I am testing right now what happens on my Ubuntu.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

Apparently, there is an openmp package for Arch that I did not know about, which is an optional requirement for clang...
That might actually be the problem, since I am pretty sure I did not install it myself. It works fine on my Ubuntu.

The remaining question I have is: Should we make this a step in the CI system for easier code review, or would that be too much?

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

I will add this to the CI system, I'm not sure how much it will help currently though as there is a lot of problems so it's hard to see if there is any new error or not.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

I guess we would definitively have to search for the file that was edited, but I think that we can fix these issues for the future PRs one after the other.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

The CI system apparently has a similar problem to my Arch Linux (does not find a particular header file):

/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/cxxabi_init_exception.h:38:10: fatal error: 'stddef.h' file not found

Taken from the CI output.

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

The problem is actually with iwyu though, clang-tidy worked fine. That is surprising at first I thought it would be the opposite due to the clang-version being low.

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

Looks like this is a known issue with iwyu. Depending how well the maintainers do the packaging, it may not properly find standard headers.
include-what-you-use/include-what-you-use#679

I'll try to get around this.

@pratikvn
Copy link
Member

pratikvn commented May 3, 2019

Even in the clang-tidy step there seem to be similar errors.

@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

You're both right. It did not fail for some reason so I thought all was well there.

@thoasm
Copy link
Member

thoasm commented May 3, 2019

@pratikvn is correct. There are multiple 'stddef.h' file not found [clang-diagnostic-error] errors, however, they do not lead to a compile termination (probably since they are in system header instead of in the project headers).
Examples for the errors:

/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/cxxabi_init_exception.h:38:10: error: 'stddef.h' file not found [clang-diagnostic-error]
/usr/include/limits.h:123:16: error: 'limits.h' file not found [clang-diagnostic-error]
/usr/include/wchar.h:39:11: error: 'stdarg.h' file not found [clang-diagnostic-error]

Taken from this CI output

It seems to be limited to stddef.h, stdarg.h and limits.h.

+ Use a pre-compiled version of `iwyu` for `clang 6.0`
+ Use a properly compiled version of `clang-tidy` matching the installed `clang`
  version
@tcojean
Copy link
Member Author

tcojean commented May 3, 2019

This is now fixed.

Copy link
Member

@thoasm thoasm 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

@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!

@tcojean tcojean merged commit 2d3f031 into develop May 6, 2019
@tcojean tcojean deleted the support_iwyu_clang-tidy branch May 6, 2019 09:11
@tcojean tcojean added the 1:ST:ready-to-merge This PR is ready to merge. label May 15, 2019
tcojean added a commit that referenced this pull request Oct 20, 2019
The Ginkgo team is proud to announce the new minor release of Ginkgo version
1.1.0. This release brings several performance improvements, adds Windows support, 
adds support for factorizations inside Ginkgo and a new ILU preconditioner
based on ParILU algorithm, among other things. For detailed information, check the respective issue.

Supported systems and requirements:
+ For all platforms, cmake 3.9+
+ Linux and MacOS
  + gcc: 5.3+, 6.3+, 7.3+, 8.1+
  + clang: 3.9+
  + Intel compiler: 2017+
  + Apple LLVM: 8.0+
  + CUDA module: CUDA 9.0+
+ Windows
  + MinGW and CygWin: gcc 5.3+, 6.3+, 7.3+, 8.1+
  + Microsoft Visual Studio: VS 2017 15.7+
  + CUDA module: CUDA 9.0+, Microsoft Visual Studio
  + OpenMP module: MinGW or CygWin.


The current known issues can be found in the [known issues
page](https://github.com/ginkgo-project/ginkgo/wiki/Known-Issues).


Additions:
+ Upper and lower triangular solvers ([#327](#327), [#336](#336), [#341](#341), [#342](#342)) 
+ New factorization support in Ginkgo, and addition of the ParILU
  algorithm ([#305](#305), [#315](#315), [#319](#319), [#324](#324))
+ New ILU preconditioner ([#348](#348), [#353](#353))
+ Windows MinGW and Cygwin support ([#347](#347))
+ Windows Visual studio support ([#351](#351))
+ New example showing how to use ParILU as a preconditioner ([#358](#358))
+ New example on using loggers for debugging ([#360](#360))
+ Add two new 9pt and 27pt stencil examples ([#300](#300), [#306](#306))
+ Allow benchmarking CuSPARSE spmv formats through Ginkgo's benchmarks ([#303](#303))
+ New benchmark for sparse matrix format conversions ([#312](#312))
+ Add conversions between CSR and Hybrid formats ([#302](#302), [#310](#310))
+ Support for sorting rows in the CSR format by column idices ([#322](#322))
+ Addition of a CUDA COO SpMM kernel for improved performance ([#345](#345))
+ Addition of a LinOp to handle perturbations of the form (identity + scalar *
  basis * projector) ([#334](#334))
+ New sparsity matrix representation format with Reference and OpenMP
  kernels ([#349](#349), [#350](#350))

Fixes:
+ Accelerate GMRES solver for CUDA executor ([#363](#363))
+ Fix BiCGSTAB solver convergence ([#359](#359))
+ Fix CGS logging by reporting the residual for every sub iteration ([#328](#328))
+ Fix CSR,Dense->Sellp conversion's memory access violation ([#295](#295))
+ Accelerate CSR->Ell,Hybrid conversions on CUDA ([#313](#313), [#318](#318))
+ Fixed slowdown of COO SpMV on OpenMP ([#340](#340))
+ Fix gcc 6.4.0 internal compiler error ([#316](#316))
+ Fix compilation issue on Apple clang++ 10 ([#322](#322))
+ Make Ginkgo able to compile on Intel 2017 and above ([#337](#337))
+ Make the benchmarks spmv/solver use the same matrix formats ([#366](#366))
+ Fix self-written isfinite function ([#348](#348))
+ Fix Jacobi issues shown by cuda-memcheck

Tools and ecosystem:
+ Multiple improvements to the CI system and tools ([#296](#296), [#311](#311), [#365](#365))
+ Multiple improvements to the Ginkgo containers ([#328](#328), [#361](#361))
+ Add sonarqube analysis to Ginkgo ([#304](#304), [#308](#308), [#309](#309))
+ Add clang-tidy and iwyu support to Ginkgo ([#298](#298))
+ Improve Ginkgo's support of xSDK M12 policy by adding the `TPL_` arguments
  to CMake ([#300](#300))
+ Add support for the xSDK R7 policy ([#325](#325))
+ Fix examples in html documentation ([#367](#367))
tcojean added a commit that referenced this pull request Oct 21, 2019
The Ginkgo team is proud to announce the new minor release of Ginkgo version
1.1.0. This release brings several performance improvements, adds Windows support,
adds support for factorizations inside Ginkgo and a new ILU preconditioner
based on ParILU algorithm, among other things. For detailed information, check the respective issue.

Supported systems and requirements:
+ For all platforms, cmake 3.9+
+ Linux and MacOS
  + gcc: 5.3+, 6.3+, 7.3+, 8.1+
  + clang: 3.9+
  + Intel compiler: 2017+
  + Apple LLVM: 8.0+
  + CUDA module: CUDA 9.0+
+ Windows
  + MinGW and Cygwin: gcc 5.3+, 6.3+, 7.3+, 8.1+
  + Microsoft Visual Studio: VS 2017 15.7+
  + CUDA module: CUDA 9.0+, Microsoft Visual Studio
  + OpenMP module: MinGW or Cygwin.


The current known issues can be found in the [known issues
page](https://github.com/ginkgo-project/ginkgo/wiki/Known-Issues).


### Additions
+ Upper and lower triangular solvers ([#327](#327), [#336](#336), [#341](#341), [#342](#342)) 
+ New factorization support in Ginkgo, and addition of the ParILU
  algorithm ([#305](#305), [#315](#315), [#319](#319), [#324](#324))
+ New ILU preconditioner ([#348](#348), [#353](#353))
+ Windows MinGW and Cygwin support ([#347](#347))
+ Windows Visual Studio support ([#351](#351))
+ New example showing how to use ParILU as a preconditioner ([#358](#358))
+ New example on using loggers for debugging ([#360](#360))
+ Add two new 9pt and 27pt stencil examples ([#300](#300), [#306](#306))
+ Allow benchmarking CuSPARSE spmv formats through Ginkgo's benchmarks ([#303](#303))
+ New benchmark for sparse matrix format conversions ([#312](#312))
+ Add conversions between CSR and Hybrid formats ([#302](#302), [#310](#310))
+ Support for sorting rows in the CSR format by column idices ([#322](#322))
+ Addition of a CUDA COO SpMM kernel for improved performance ([#345](#345))
+ Addition of a LinOp to handle perturbations of the form (identity + scalar *
  basis * projector) ([#334](#334))
+ New sparsity matrix representation format with Reference and OpenMP
  kernels ([#349](#349), [#350](#350))

### Fixes
+ Accelerate GMRES solver for CUDA executor ([#363](#363))
+ Fix BiCGSTAB solver convergence ([#359](#359))
+ Fix CGS logging by reporting the residual for every sub iteration ([#328](#328))
+ Fix CSR,Dense->Sellp conversion's memory access violation ([#295](#295))
+ Accelerate CSR->Ell,Hybrid conversions on CUDA ([#313](#313), [#318](#318))
+ Fixed slowdown of COO SpMV on OpenMP ([#340](#340))
+ Fix gcc 6.4.0 internal compiler error ([#316](#316))
+ Fix compilation issue on Apple clang++ 10 ([#322](#322))
+ Make Ginkgo able to compile on Intel 2017 and above ([#337](#337))
+ Make the benchmarks spmv/solver use the same matrix formats ([#366](#366))
+ Fix self-written isfinite function ([#348](#348))
+ Fix Jacobi issues shown by cuda-memcheck

### Tools and ecosystem improvements
+ Multiple improvements to the CI system and tools ([#296](#296), [#311](#311), [#365](#365))
+ Multiple improvements to the Ginkgo containers ([#328](#328), [#361](#361))
+ Add sonarqube analysis to Ginkgo ([#304](#304), [#308](#308), [#309](#309))
+ Add clang-tidy and iwyu support to Ginkgo ([#298](#298))
+ Improve Ginkgo's support of xSDK M12 policy by adding the `TPL_` arguments
  to CMake ([#300](#300))
+ Add support for the xSDK R7 policy ([#325](#325))
+ Fix examples in html documentation ([#367](#367))


Related PR: #370
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. is:new-feature A request or implementation of a feature that does not exist yet. reg:build This is related to the build system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants