-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Compiler warnings with NVCC 11.2 #2676
Comments
I recently fixed a lot of warnings with #2561. Can you please re-try with the latest develop branch? |
Thanks for the heads up! It's better -- The missing return statement warning is gone. But I still see a warning about comparing an unsigned int with zero on this line. |
Thanks for checking! The comparison in that line has a history, and I have not found a way to get rid of it. I'll check if I can add NVCC to the CI. |
I'm sorry for asking such a basic question, but can you provide me with the CMake call you made? I tried the following:
Unfortunately, I get the following error:
|
@nlohmann Why not use the suggestion from #755 (comment)? This can be also simplified to not have enable_if with something like template <typename T>
bool IsNegative(T);
template <>
bool IsNegative<number_integer_t>(number_integer_t x)
{
return x < 0;
}
template <>
bool IsNegative<number_unsigned_t>(number_unsigned_t)
{
return false;
} of course this is overkill. But a good compiler can already figure out that is not worthy a warning. |
Thanks for taking a look! It doesn't look like building json with nvcc would replicate this, as nvcc will not invoke the device compilers for pure-C++ targets, and CMake won't easily support using it as a C++ compiler. The easiest way to replicate this by hand would be:
Something like this could be added to CI by using a CUDA-language CMake target. |
That works, thanks. I will add a CI job. |
It seems I don't get warnings, but errors.
// main.cpp
#include "json.hpp"
int main()
{}
Running on Ubuntu. Any ideas? |
Strange, I can't get the same result here. Does it work if you change the extension to If it helps, the warning can be repro'd by copying the current single-header |
I re-tried in the Docker container I used for the CI (https://hub.docker.com/repository/docker/nlohmann/json-ci) that has nvcc 10.1 installed.
Output:
// main.cpp
#include "json.hpp"
int main()
{}
|
Hi Allison, I'm not familiar with
So there is the possibility that warnings are being emitted from this host compiler instead of You mentioned here that there is a "device compiler" in play, and an exact Google search of emitted error message:
hints that the compiler could be Intel compiler or a variant of arm/avr compiler (which AFAIK are usually derived from gcc). Can you check on what compiler is being used in this case? |
These do appear to be coming from NVCC itself, and not from the underlying host compiler (which was MSVC 2019 in this case). |
I was able to reproduce this with docker cuda images shipped by Nvidia. Here is a Dockerfile demonstrating the issue. Thank you Allison for reporting this issue and providing the details. :-) FROM nvidia/cuda:11.2.0-devel-ubuntu20.04
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt update && apt-get -y install curl
RUN curl https://raw.githubusercontent.com/nlohmann/json/v3.9.1/single_include/nlohmann/json.hpp -o json-v3.9.1.hpp && \
curl https://raw.githubusercontent.com/nickaein/nlohmann-json/25ed41033172dca5f299687b4ed30d5f275d58f8/single_include/nlohmann/json.hpp -o json-patched.hpp
RUN diff -u json-v3.9.1.hpp json-patched.hpp
RUN echo "TESTING WITH json-v3.9.1.hpp ..." && \
echo '#include "json-v3.9.1.hpp"\n \
int main() {nlohmann::json j = {"Test"}; j.dump(); } \n' > test-a.cpp && \
nvcc -x cu test-a.cpp -o test-a && ./test-a
RUN echo "TESTING WITH json-patched.hpp ..." && \
echo '#include "json-patched.hpp"\n \
int main() {nlohmann::json j = {"Test"}; j.dump(); } \n' > test-b.cpp && \
nvcc -x cu test-b.cpp -o test-b && ./test-b This will show the warning on the original version, while with the fix in PR #2736, the warning is gone. I have played around integrating the nvcc compiler into CI workflow. The issue is that setting I will investigate further in the next days to see how nvcc can be integrated into CI. |
Thanks for taking care of this. It would be cool to have that NVCC in the CI Docker (https://github.com/nlohmann/json-ci). |
@nlohmann @nickaein @allisonvacanti Hi, I lead a project called DARMA (main code is https://github.com/DARMA-tasking/vt) and we decided to import your json library, but we have to support a wide range of GNU/Clang/Intel/NVidia compilers including nvcc 10.1. I was able to reproduce the exact error above (i.e., Here is the patch that "solves"/works-around the compiler bug: DARMA-tasking/vt@3c5b95d I figured out that reversing the template argument order for some unknown reason causes nvcc 10.1 to not choke on it anymore. Also, in case it's useful, this is the script for the docker container I use to test nvcc compilers with the Kokkos nvcc_wrapper to putting all the code through nvcc: https://github.com/DARMA-tasking/vt/blob/develop/ci/docker/ubuntu-18.04-nvidia-cpp.dockerfile Also, it would be nice if you added CI testing across Intel and NVidia compilers. You can build a container with Intel compilers pretty easily. I have some hacked up scripts (https://github.com/DARMA-tasking-internal/icc-docker-build) that could be useful. |
Hello, nlohmann::json is so cool. Thanks for your contribution. I also meet the error. Is there any new progress on this issue now? |
@nickaein Hello, I just tried it, but I still get errors. Before the issue was solved, I had to split my |
Which version of library are you using? Since the fix was based on an older version of library, I updated it with the latest one (devel branch, specifically). Now you can find the patch here and manually apply them. You can also get the "fixed" single-header file from here: |
@nickaein Maybe my expression is not clear. I mean that I use #include "baseC.h"
#include "superC.h"
#include "json.hpp"
int main()
{
BaseC* bseC = new SuperC();
// SuperC* superCCC = new SuperC();
//bseC = superCCC;
bseC->printC();
nlohmann::json j = "{ \"happy\": true, \"pi\": 3.141 }"_json;
return 0;
} I get errors. Output:
No warning, just errors. |
I am having the same issue as @hei6775 . This patch doesn't seem to fix it. However, I did test out the patch provided by @lifflander and my problem seems to be resolved. |
@Llcoolsouder Tks |
Any idea how to proceed here? |
The problem you see above might be related to the requirements of the CUDA toolkit, in particular that GCC 11 is not supported by NVCC 10. Since you have NVCC 10.1.243 installed, you could use a GCC 7 or 8 from the distribution packages and hint CMake to use it as NVCC's host-compiler via: export CXX=$(which g++-7)
export CUDAHOSTCXX=${CXX} or via the CMake CLI options: The |
@ax3l Thanks for the hints. But I am confused - don't I still need to bass NVCC to CMake somehow? |
Ok. I'll give it a try and share what I learned in a bit. |
Sounds great! Let me know if there is a CI script to look at. I added a few more details in the last post now: that would be the logic needed to make sure a target is treated as "CUDA C++" instead of "C++" in CMake. |
Alright, before starting a branch and playing ping-pong with the CI, here is what I tried in the Docker image of the CI: I created a new directory with a small CMake project: CMakeLists.txtcmake_minimum_required(VERSION 3.8)
project(json_cuda LANGUAGES CUDA)
add_executable(json_cuda json_cuda.cpp)
set_source_files_properties(json_cuda.cpp PROPERTIES LANGUAGE CUDA)
target_include_directories(json_cuda PRIVATE ../../include)
target_compile_features(json_cuda PUBLIC cuda_std_11)
set_target_properties(json_cuda PROPERTIES
CUDA_EXTENSIONS OFF
CUDA_STANDARD_REQUIRED ON
CUDA_SEPARABLE_COMPILATION ON # Just needed if we need separable compilation; this adds -dc
) json_cuda.cpp#include <nlohmann/json.hpp>
int main()
{} Calls$ cmake .. -DCMAKE_CXX_COMPILER=$(which g++-7) -DCMAKE_CUDA_HOST_COMPILER=$(which g++-7)
-- The CUDA compiler identification is NVIDIA 10.1.243
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /usr/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Configuring done
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
empty CUDA_ARCHITECTURES not allowed. Run "cmake --help-policy CMP0104"
for policy details. Use the cmake_policy command to set the policy and
suppress this warning.
CUDA_ARCHITECTURES is empty for target "json_cuda".
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
empty CUDA_ARCHITECTURES not allowed. Run "cmake --help-policy CMP0104"
for policy details. Use the cmake_policy command to set the policy and
suppress this warning.
CUDA_ARCHITECTURES is empty for target "json_cuda".
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) in CMakeLists.txt:
Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
empty CUDA_ARCHITECTURES not allowed. Run "cmake --help-policy CMP0104"
for policy details. Use the cmake_policy command to set the policy and
suppress this warning.
CUDA_ARCHITECTURES is empty for target "json_cuda".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_CXX_COMPILER
-- Build files have been written to: /root/json/test/cuda_example/build $ make
[ 33%] Building CUDA object CMakeFiles/json_cuda.dir/json_cuda.cpp.o
/root/json/test/cuda_example/../../include/nlohmann/detail/meta/type_traits.hpp:260:156: error: expansion pattern 'CompatibleObjectType' contains no argument packs
struct is_compatible_object_type_impl <
^
/root/json/test/cuda_example/../../include/nlohmann/detail/meta/type_traits.hpp:260:159: error: template argument 4 is invalid
struct is_compatible_object_type_impl <
^
... |
Thanks! I added the following simplifications/updates to get rid of warnings:
|
Thanks - the CMake warnings are gone now. Any ideas now? |
I think there is a build problem with the |
This is most likely a NVCC bug and might already be fixed in a newer version of the CUDA toolkit (CTK). It looks like @allisonvacanti is already using NVCC 11.2 in her original post. I also tried with clang 6.0, 7 and 8 from the image now as host-compiler, which also raises errors, but of the kind:
We could try of a newer CTK download fixes the problem already. We could install it via a |
I have some A subset of this would replace the slightly older Ubuntu |
Thanks! I'll give it a try. |
I think I have a PR to update your CI nearly ready, give me a minute and I will post it :) |
Posted and currently building/testing locally: nlohmann/json-ci#8 |
Thanks so much! |
Wuhu, works 🎉 $ cmake -S . -B build -DCMAKE_CUDA_HOST_COMPILER=$(which g++-8)
-- The CUDA compiler identification is NVIDIA 11.0.221
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/test/nvcc/build
$ cmake --build build
[ 50%] Building CUDA object CMakeFiles/json_cuda.dir/json_cuda.cu.o
/opt/test/nvcc/../../include/nlohmann/detail/output/serializer.hpp(710): warning: pointless comparison of unsigned integer with zero
# ...
[100%] Linking CUDA executable json_cuda
[100%] Built target json_cuda |
Cool! I merge the change to the CI. Once the image is ready, I can create a PR that adds a new build step to ubuntu.yml. And once that runs through, I'll tag the CI image with And then I guess it's time to have a look at the warnings mentioned in this issue and #2736. |
Let's see if #3227 works. |
Alright, #3227 fixes the warning using the fix from @nickaein (thanks!). @allisonvacanti @ax3l @Llcoolsouder can you please double check? |
Y'all are full of sssssshat https://drive.google.com/file/d/13J1p7cjLchjjBGA9KFVmItOC6MrzmDj-/view?usp=drivesdk |
What is the issue you have?
Instantiating the
json::basic_json
template and compiling with the CUDA NVCC compiler emits the warnings below.Please describe the steps to reproduce the issue.
Compile the following with nvcc (observed on 11.2 with MSVC 2019 host):
The following warnings are emitted:
Can you provide a small but working code example?
See above.
What is the expected behavior?
No warnings.
And what is the actual behavior instead?
Warnings.
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: