-
Notifications
You must be signed in to change notification settings - Fork 184
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
[c++17] changes to cudaq headers for pure c++17 environment #1468
[c++17] changes to cudaq headers for pure c++17 environment #1468
Conversation
8f2ca94
to
f4314c3
Compare
c34f49e
to
30477a9
Compare
a2a4a95
to
463843a
Compare
LGTM. I also want to ask @bmhowe23's opinion regarding breaking/non-breaking classification of the syntax change from |
@schweitzpgi What's the issue with the reasoning that the nvq++ compiler is necessarily used to compile the code and nvq++ contains C++20 support? Is there a scenario where the code with If we pull in this change, we should remove the -Wno-c++20-extensions flag here and here. |
traditionally, |
I assume the requirement that Eric is trying to satisfy is that cudaq.h, which includes For example, this file: #include "cudaq.h"
int test() {
return 0;
} is compilable with all 3 of these commands. $ nvcc -c -I/usr/local/cudaq/include -std=c++17 bentest.cpp -o bentest.o
$ g++ -c -I/usr/local/cudaq/include -std=c++17 bentest.cpp -o bentest.o
$ /opt/llvm/bin/clang++ -c -I/usr/local/cudaq/include -std=c++17 bentest.cpp -o bentest.o Is the requirement that our full language is callable from C++17 code, or just that the standard cudaq.h header files cannot interfere with a C++17-only compiler? |
The bug in the current setup is that we simply allow code that is not C++17 to compile without so much as a warning as C++17. That can only happen if the compiler already knows about C++20. This is clearly problematic. For one thing, it lets us assume we can write tests and other code which is incorrect and no amount of testing will catch the problems. In library mode, it should not the case that we force users down specific usage paths because we can't be consistent and do the right thing. |
Yes, this was a bit of a backdoor extension. I can remove it. Thanks for the feedback. |
463843a
to
666b65c
Compare
Yes, it should be true that the cuda.h file is (and should remain) legal C++17 and should compile with any C++17 compiler. That was the requirement: supporting C++17 only systems. We don't want to silently regress from this point, which is possible because we are disabling our compiler checks currently as a workaround for an omission. Thanks for verifying. |
To be clear, the above test file and test compile commands worked for me without any of the changes in this PR. Were you seeing failures before this PR with a specific compiler, or was this issue found by inspection only? |
This was found by inspection. The current setup accepts C++20 programs even when adding the C++17 flag, which is a problem. |
c1f81a6
to
19a7aca
Compare
19a7aca
to
fb76196
Compare
c73a7ee
to
f3afb4a
Compare
c2a64bd
to
ac01a72
Compare
We were allowing calls such as x<cudaq::ctrl>(q); in C++17 compilation mode even though that syntax requires C++20. This PR prevents using the C++20 syntax when compiling as C++17. C++17 code will have to rewrite the above as cx(q); More generally, the cudaq::control and cudaq::adjoint functions can be used. Change the definition of my to be C++17. Refactor the definition of swap to be C++17. Adds a "cswap" for the control variant. Add test. Add handling of cr[xyz1] to the bridge. Port the conditional_sample.cpp test to C++17. Mark tests that use C++20 syntax as REQUIRES c++20. Port negation.cpp test to have a c++17 variant. Review comments: add back deleted RUN lines. Cleanup the cr? functions. Remove unneeded templates.
ac01a72
to
7398e24
Compare
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
The driver and headers were allowing all C++20 syntax to pass, even in C++17 mode. This was happening by leaning into the idea that a C++20 compiler was available, it was just being told to compile as C++17. This meant that in a pure C++17 environment, which didn't know anything about C++20 whatsoever, would choke on the CUDA-Q syntax.
This PR disables the use of the offending syntax in the headers unless a C++20 (or better) compiler is truly in use. This distinction means that CUDA-Q programs written for C++17 may be required to use a different syntax in order to compile.
For example, the following C++20 syntax
must be written as