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

Use cxx14 standard #611

Merged
merged 6 commits into from
Aug 7, 2020
Merged

Use cxx14 standard #611

merged 6 commits into from
Aug 7, 2020

Conversation

tcojean
Copy link
Member

@tcojean tcojean commented Aug 3, 2020

Upgrade Ginkgo from C++11 standard to C++14.

There are multiple reasons for this:

  1. CUDA's thrust will be deprecating C++11 and moving to C++14 shortly.
  2. On paper and in practice, all the compiler versions we support already support C++14, so moving doesn't make us lose anything. The only failure is a corner case of CUDA 9.2 and clang 5.0 as CUDA host compiler which cannot be fixed, see the comments in the related PR on this issue.

What changed:

  • Upgrade any mention of C++11 to C++14
  • Review the std_extensions to use implementation from C++14 instead of the custom made one.
  • Update all code calls from xstd to std when the feature used was a C++14 feature.
  • Use Intel 2020 together with GCC 9 as there is an incompatibility when considering C++14 between Intel 2019 and GCC 9.
  • Ensure tests are always compiled with the C++14 standard
  • Throw a fatal_error when using CUDA 9.2 with clang 5.0 as CUDA host compiler.

Closes #604

@tcojean tcojean added the 1:ST:WIP This PR is a work in progress. Not ready for review. label Aug 3, 2020
@tcojean tcojean self-assigned this Aug 3, 2020
@tcojean tcojean force-pushed the use_cxx14_standard branch 3 times, most recently from f0f467a to 30bd205 Compare August 3, 2020 13:34
@tcojean
Copy link
Member Author

tcojean commented Aug 3, 2020

Everything is working except for cuda 9.2 + clang 5.0 as host compiler. For some reason, there is an issue interpreting the standard headers and I cannot find the reason. See this pipeline: https://gitlab.com/ginkgo-project/ginkgo-public-ci/-/pipelines/173724849

For some reason, a small example such as the following compiled with nvcc -std=c++14 -ccbin=/usr/bin/clang++ test.cu will fail, whereas nvcc -std=c++14 -ccbin=/usr/bin/g++ test.cu succeeds.

#include <complex>
int main() {
        return 0;
}

@tcojean
Copy link
Member Author

tcojean commented Aug 4, 2020

The issue is clearly that nvcc for some reason adds spaces between operator and "" and more importantly "" and if (etc). The operator is defined as operator""if without space (the space has its importance it seems, see https://en.cppreference.com/w/cpp/numeric/complex/operator%22%22i and https://en.cppreference.com/w/cpp/language/user_literal (especially the example down there). Clearly, clang seems to be correct in saying that there is an error here, the issue is why does nvcc 9.2 transforms the perfectly valid header into

constexpr complex< float>  operator "" if(long double __num) 

@upsj
Copy link
Member

upsj commented Aug 4, 2020

This is a bug in the clang tokenization/parser: It consumes the "if" token as the if keyword instead of an identifier. Removing the space or changing the identifier to be a non-keyword fixes it.
Output of clang++ --std=c++14 -fsyntax-only -Xclang -dump-tokens:

string_literal '""'	 [LeadingSpace]	Loc=<test.cpp:1:33>
if 'if'	 [LeadingSpace]	Loc=<test.cpp:1:36>

No wait, that doesn't make sense, you are right. An identifier may never be a keyword.

@tcojean
Copy link
Member Author

tcojean commented Aug 4, 2020

This can be reproduced with the following simple example

constexpr double operator "" if(unsigned long long d)
{
        return 0.0;
}

int main()
{
        return 0;
}
test.cpp:1:30: error: expected identifier
constexpr double operator "" if(unsigned long long d)
                             ^
1 error generated.

The error has two issues mixed in:

  • The space is added by nvcc after the cudafe++ call as Tobias points out down below
  • clang's parser messes up and interprets the if as a language construct, any other keyword creates the same problem (else, for, static_cast, operator, ...). Adding a space to a string literal with only an i or literally anything which isn't part of the grammar only gives a warning stating that an underscore is required.

@upsj
Copy link
Member

upsj commented Aug 4, 2020

Okay, I finished digging, this is a bug in cudafe++: --gnu_version=70500 gives the correct translation, --clang --clang_version=50000 inserts the space. I guess we can't do anything about that.

@upsj
Copy link
Member

upsj commented Aug 4, 2020

Regarding the space: The standard is a bit unclear about the details, but as the Literal operators section of the page you linked states, the user-defined-string-literal token was introduced to allow keywords to be used as literal suffixes, so I believe clang isn't at fault here. gcc emits a similar error message:
unexpected keyword; remove space between quotes and suffix identifier

@tcojean
Copy link
Member Author

tcojean commented Aug 4, 2020

Yes, I think clang is somewhat correct in the end, despite the bug being a weird parsing issue. Overall, this shouldn't be valid C++. My understanding is that having a space at this place operator"" if means that it's a user defined literal, which should always start with a underscore. If you put an underscore here, as expected the test example compiles correctly.

@tcojean
Copy link
Member Author

tcojean commented Aug 4, 2020

Tobias helped find a possible way to work around this issue, from the previous nvcc error example:

#include <complex>
int main() {
        return 0;
}

You can compile it successfully with the following arguments:

nvcc -ccbin=/usr/bin/clang++ -Xcudafe --gnu_version=70500 -Xcudafe --no_clang -std=c++14 test.cu

@tcojean tcojean added reg:build This is related to the build system. reg:ci-cd This is related to the continuous integration system. mod:core This is related to the core module. is:enhancement An improvement of an existing feature. 1:ST:ready-for-review This PR is ready for review and removed 1:ST:WIP This PR is a work in progress. Not ready for review. labels Aug 5, 2020
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!

README.md Outdated Show resolved Hide resolved
@tcojean
Copy link
Member Author

tcojean commented Aug 5, 2020

The previous fix mentioned works for the complex header, but sadly it creates a lot of issues as soon as we include the <memory> header, so I went with the solution of throwing an error when using clang 5.0 as CUDA host compiler with CUDA 9.2.

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!

.gitlab-ci.yml Outdated
@@ -488,7 +467,7 @@ build/nocuda/clang/core/release/shared:

build/nocuda/intel/core/debug/shared:
<<: *default_build_with_test
image: localhost:5000/gko-nocuda-gnu9-llvm8
image: localhost:5000/add_cuda11_container_1b1857a4_gko-nocuda-gnu9-llvm8
Copy link
Member

Choose a reason for hiding this comment

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

Question: Are these changes necessary or left-over from the cuda11 branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are necessary, I had to upgrade the intel compiler to 2020 for this PR to work properly. I used the CUDA 11 PR to update this at the same time. The Intel 2019 has some incompatibility with GNU 9 backend when considering C++14 code. Therefore we will need to merge the CUDA11 container before this.

.gitlab-ci.yml Outdated
@@ -536,7 +515,7 @@ build/nocuda/clang/omp/debug/static:

build/nocuda/intel/omp/release/static:
<<: *default_build_with_test
image: localhost:5000/gko-nocuda-gnu9-llvm8
image: localhost:5000/add_cuda11_container_1b1857a4_gko-nocuda-gnu9-llvm8
Copy link
Member

Choose a reason for hiding this comment

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

Same here

README.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #611 into develop will not change coverage.
The diff coverage is 81.81%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #611   +/-   ##
========================================
  Coverage    93.01%   93.01%           
========================================
  Files          296      296           
  Lines        20656    20656           
========================================
  Hits         19214    19214           
  Misses        1442     1442           
Impacted Files Coverage Δ
core/base/extended_float.hpp 92.23% <ø> (ø)
core/test/base/polymorphic_object.cpp 97.61% <ø> (ø)
core/test/utils/assertions.hpp 70.98% <ø> (ø)
include/ginkgo/core/base/array.hpp 92.52% <ø> (ø)
include/ginkgo/core/base/lin_op.hpp 97.64% <ø> (ø)
include/ginkgo/core/base/name_demangling.hpp 85.71% <ø> (ø)
include/ginkgo/core/base/range.hpp 95.48% <ø> (ø)
include/ginkgo/core/log/logger.hpp 92.10% <ø> (ø)
include/ginkgo/core/matrix/csr.hpp 47.69% <0.00%> (ø)
include/ginkgo/core/preconditioner/ilu.hpp 96.93% <ø> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4c524a...634018e. Read the comment docs.

tcojean and others added 6 commits August 6, 2020 15:32
+ Replace our own code with calls to the standard implementation
+ Do not directly call `xstd` in our code for base C++14 features.
There is an issue between `cudafe` which adds wrong spaces to `operator
"" if()` definitions which make `clang` crash as it looks for the token
`if`.
Co-authored-by: Pratik Nayak <[email protected]>
Co-authored-by: Tobias Ribizel <[email protected]>
@tcojean tcojean added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Aug 6, 2020
@sonarcloud
Copy link

sonarcloud bot commented Aug 6, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

36.4% 36.4% Coverage
4.5% 4.5% Duplication

warning The version of Java (1.8.0_121) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

@tcojean tcojean merged commit 563fbbb into develop Aug 7, 2020
@tcojean tcojean deleted the use_cxx14_standard branch August 7, 2020 07:47
tcojean added a commit that referenced this pull request Aug 26, 2020
Release 1.3.0 of Ginkgo.

The Ginkgo team is proud to announce the new minor release of Ginkgo version
1.3.0. This release brings CUDA 11 support, changes the default C++ standard to
be C++14 instead of C++11, adds a new Diagonal matrix format and capacity for
diagonal extraction, significantly improves the CMake configuration output
format, adds the Ginkgo paper which got accepted into the Journal of Open Source
Software (JOSS), and fixes multiple issues.

Supported systems and requirements:
+ For all platforms, cmake 3.9+
+ Linux and MacOS
  + gcc: 5.3+, 6.3+, 7.3+, all versions after 8.1+
  + clang: 3.9+
  + Intel compiler: 2017+
  + Apple LLVM: 8.0+
  + CUDA module: CUDA 9.0+
  + HIP module: ROCm 2.8+
+ Windows
  + MinGW and Cygwin: gcc 5.3+, 6.3+, 7.3+, all versions after 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:
+ Add paper for Journal of Open Source Software (JOSS). [#479](#479)
+ Add a DiagonalExtractable interface. [#563](#563)
+ Add a new diagonal Matrix Format. [#580](#580)
+ Add Cuda11 support. [#603](#603)
+ Add information output after CMake configuration. [#610](#610)
+ Add a new preconditioner export example. [#595](#595)
+ Add a new cuda-memcheck CI job. [#592](#592)

Changes:
+ Use unified memory in CUDA debug builds. [#621](#621)
+ Improve `BENCHMARKING.md` with more detailed info. [#619](#619)
+ Use C++14 standard instead of C++11. [#611](#611)
+ Update the Ampere sm information and CudaArchitectureSelector. [#588](#588)

Fixes:
+ Fix documentation warnings and errors. [#624](#624)
+ Fix warnings for diagonal matrix format. [#622](#622)
+ Fix criterion factory parameters in CUDA. [#586](#586)
+ Fix the norm-type in the examples. [#612](#612)
+ Fix the WAW race in OpenMP is_sorted_by_column_index. [#617](#617)
+ Fix the example's exec_map by creating the executor only if requested. [#602](#602)
+ Fix some CMake warnings. [#614](#614)
+ Fix Windows building documentation. [#601](#601)
+ Warn when CXX and CUDA host compiler do not match. [#607](#607)
+ Fix reduce_add, prefix_sum, and doc-build. [#593](#593)
+ Fix find_library(cublas) issue on machines installing multiple cuda. [#591](#591)
+ Fix allocator in sellp read. [#589](#589)
+ Fix the CAS with HIP and NVIDIA backends. [#585](#585)

Deletions:
+ Remove unused preconditioner parameter in LowerTrs. [#587](#587)

Related PR: #625
tcojean added a commit that referenced this pull request Aug 27, 2020
The Ginkgo team is proud to announce the new minor release of Ginkgo version
1.3.0. This release brings CUDA 11 support, changes the default C++ standard to
be C++14 instead of C++11, adds a new Diagonal matrix format and capacity for
diagonal extraction, significantly improves the CMake configuration output
format, adds the Ginkgo paper which got accepted into the Journal of Open Source
Software (JOSS), and fixes multiple issues.

Supported systems and requirements:
+ For all platforms, cmake 3.9+
+ Linux and MacOS
  + gcc: 5.3+, 6.3+, 7.3+, all versions after 8.1+
  + clang: 3.9+
  + Intel compiler: 2017+
  + Apple LLVM: 8.0+
  + CUDA module: CUDA 9.0+
  + HIP module: ROCm 2.8+
+ Windows
  + MinGW and Cygwin: gcc 5.3+, 6.3+, 7.3+, all versions after 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:
+ Add paper for Journal of Open Source Software (JOSS). [#479](#479)
+ Add a DiagonalExtractable interface. [#563](#563)
+ Add a new diagonal Matrix Format. [#580](#580)
+ Add Cuda11 support. [#603](#603)
+ Add information output after CMake configuration. [#610](#610)
+ Add a new preconditioner export example. [#595](#595)
+ Add a new cuda-memcheck CI job. [#592](#592)

Changes:
+ Use unified memory in CUDA debug builds. [#621](#621)
+ Improve `BENCHMARKING.md` with more detailed info. [#619](#619)
+ Use C++14 standard instead of C++11. [#611](#611)
+ Update the Ampere sm information and CudaArchitectureSelector. [#588](#588)

Fixes:
+ Fix documentation warnings and errors. [#624](#624)
+ Fix warnings for diagonal matrix format. [#622](#622)
+ Fix criterion factory parameters in CUDA. [#586](#586)
+ Fix the norm-type in the examples. [#612](#612)
+ Fix the WAW race in OpenMP is_sorted_by_column_index. [#617](#617)
+ Fix the example's exec_map by creating the executor only if requested. [#602](#602)
+ Fix some CMake warnings. [#614](#614)
+ Fix Windows building documentation. [#601](#601)
+ Warn when CXX and CUDA host compiler do not match. [#607](#607)
+ Fix reduce_add, prefix_sum, and doc-build. [#593](#593)
+ Fix find_library(cublas) issue on machines installing multiple cuda. [#591](#591)
+ Fix allocator in sellp read. [#589](#589)
+ Fix the CAS with HIP and NVIDIA backends. [#585](#585)

Deletions:
+ Remove unused preconditioner parameter in LowerTrs. [#587](#587)

Related PR: #627
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:enhancement An improvement of an existing feature. mod:core This is related to the core module. reg:build This is related to the build system. reg:ci-cd This is related to the continuous integration system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile Ginkgo with C++14
3 participants