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

Compiler warnings with NVCC 11.2 #2676

Closed
1 of 3 tasks
alliepiper opened this issue Mar 16, 2021 · 43 comments · Fixed by #3227
Closed
1 of 3 tasks

Compiler warnings with NVCC 11.2 #2676

alliepiper opened this issue Mar 16, 2021 · 43 comments · Fixed by #3227
Assignees
Labels
confirmed kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@alliepiper
Copy link

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):

#include <nlohmann/json.hpp>
int main()
{
  nlohmann::ordered_json json = {"Test"};
  json.dump();
}

The following warnings are emitted:

_deps/nlohmann_json-src/include\nlohmann/detail/hash.hpp(114): warning: missing return statement at end of non-void function "nlohmann::detail::hash(const BasicJsonType &) [with BasicJsonType=nlohmann::json]"
          detected during instantiation of "size_t nlohmann::detail::hash(const BasicJsonType &) [with BasicJsonType=nlohmann::json]" 
_deps/nlohmann_json-src/include\nlohmann/json.hpp(8709): here

_deps/nlohmann_json-src/include\nlohmann/detail/output/serializer.hpp(704): warning: pointless comparison of unsigned integer with zero
          detected during:
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_integer(NumberType) [with BasicJsonType=nlohmann::basic_json<nlohmann::ordered_map, std::vector, std::string, __nv_bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector<uint8_t, std::allocator<uint8_t>>>, NumberType=uint8_t, <unnamed>=0]" 
(266): here
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, __nv_bool, __nv_bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<nlohmann::ordered_map, std::vector, std::string, __nv_bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector<uint8_t, std::allocator<uint8_t>>>]" 
_deps/nlohmann_json-src/include\nlohmann/json.hpp(2281): here
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::dump(int, char, __nv_bool, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::error_handler_t) const [with ObjectType=nlohmann::ordered_map, ArrayType=std::vector, StringType=std::string, BooleanType=__nv_bool, NumberIntegerType=int64_t, NumberUnsignedType=uint64_t, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer, BinaryType=std::vector<uint8_t, std::allocator<uint8_t>>]" 
test.cu(2): here

_deps/nlohmann_json-src/include\nlohmann/detail/output/serializer.hpp(704): warning: pointless comparison of unsigned integer with zero
          detected during:
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_integer(NumberType) [with BasicJsonType=nlohmann::basic_json<nlohmann::ordered_map, std::vector, std::string, __nv_bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector<uint8_t, std::allocator<uint8_t>>>, NumberType=uint64_t, <unnamed>=0]" 
(338): here
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, __nv_bool, __nv_bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<nlohmann::ordered_map, std::vector, std::string, __nv_bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector<uint8_t, std::allocator<uint8_t>>>]" 
_deps/nlohmann_json-src/include\nlohmann/json.hpp(2281): here
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::dump(int, char, __nv_bool, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::error_handler_t) const [with ObjectType=nlohmann::ordered_map, ArrayType=std::vector, StringType=std::string, BooleanType=__nv_bool, NumberIntegerType=int64_t, NumberUnsignedType=uint64_t, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer, BinaryType=std::vector<uint8_t, std::allocator<uint8_t>>]" 
test.cu(2): here

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?

  • Compiler: NVCC 11.2 + MSVC 2019
  • Operating system: Windows 10

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch
@nlohmann
Copy link
Owner

I recently fixed a lot of warnings with #2561. Can you please re-try with the latest develop branch?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Mar 24, 2021
@alliepiper
Copy link
Author

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.

@nlohmann
Copy link
Owner

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.

@nlohmann
Copy link
Owner

I'm sorry for asking such a basic question, but can you provide me with the CMake call you made?

I tried the following:

  • install apt-get install nvidia-cuda-toolkit
  • call CXX=nvcc cmake .. for the JSON project

Unfortunately, I get the following error:

-- The CXX compiler identification is GNU 8.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/nvcc
-- Check for working CXX compiler: /usr/bin/nvcc - broken
CMake Error at /usr/local/share/cmake-3.19/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "/usr/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /root/json/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_59cc2/fast && /usr/bin/make  -f CMakeFiles/cmTC_59cc2.dir/build.make CMakeFiles/cmTC_59cc2.dir/build
    make[1]: Entering directory '/root/json/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_59cc2.dir/testCXXCompiler.cxx.o
    /usr/bin/nvcc    -o CMakeFiles/cmTC_59cc2.dir/testCXXCompiler.cxx.o -c /root/json/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_59cc2
    /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_59cc2.dir/link.txt --verbose=1
    /usr/bin/nvcc -rdynamic CMakeFiles/cmTC_59cc2.dir/testCXXCompiler.cxx.o -o cmTC_59cc2 
    nvcc fatal   : Unknown option 'rdynamic'
    make[1]: *** [CMakeFiles/cmTC_59cc2.dir/build.make:106: cmTC_59cc2] Error 1
    make[1]: Leaving directory '/root/json/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:140: cmTC_59cc2/fast] Error 2

@t-b
Copy link
Contributor

t-b commented Mar 24, 2021

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

@alliepiper
Copy link
Author

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:

$ cat test.cu
#include <nlohmann/json.hpp>
int main()
{
  nlohmann::ordered_json json = {"Test"};
  json.dump();
}

$ nvcc -I /path/to/json/single-header/ test.cu
<warnings>

Something like this could be added to CI by using a CUDA-language CMake target.

@nlohmann
Copy link
Owner

That works, thanks. I will add a CI job.

@nlohmann
Copy link
Owner

It seems I don't get warnings, but errors.

$ nvcc main.cu
/root/example/json.hpp:3564:156: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                            ^  
/root/example/json.hpp:3564:159: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                               ^
/root/example/json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_object_type_impl <
                                                                                                                                                                            ^    
/root/example/json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3564:239: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                               ^  
/root/example/json.hpp:3564:242: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                  ^
/root/example/json.hpp:3564:266: error: template argument 1 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                          ^
/root/example/json.hpp:3564:268: error: template argument 3 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                            ^
/root/example/json.hpp:3588:165: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                     ^  
/root/example/json.hpp:3588:168: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                        ^
/root/example/json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_constructible_object_type_impl <
                                                                                                                                                                                     ^    
/root/example/json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3588:251: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                           ^  
/root/example/json.hpp:3588:254: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                              ^
/root/example/json.hpp:3588:278: error: template argument 1 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                      ^
/root/example/json.hpp:3588:280: error: template argument 3 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                        ^
/root/example/json.hpp:3657:152: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                        ^  
/root/example/json.hpp:3657:155: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                           ^
/root/example/json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_array_type_impl <
                                                                                                                                                                        ^    
/root/example/json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3657:234: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                          ^  
/root/example/json.hpp:3657:237: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                             ^
/root/example/json.hpp:3657:335: error: template argument 1 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                               ^
/root/example/json.hpp:3657:337: error: template argument 3 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                 ^
/root/example/json.hpp:3687:437: error: expansion pattern 'ConstructibleArrayType' contains no argument packs
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^  
/root/example/json.hpp:3687:440: error: template argument 4 is invalid
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
/root/example/json.hpp:3687:86: error: parse error in template argument list
 struct is_constructible_array_type_impl <
                                                                                      ^                                                   
// main.cpp
#include "json.hpp"

int main()
{}
-- The CXX compiler identification is GNU 11.0.1
-- The CUDA compiler identification is NVIDIA 10.1.243

Running on Ubuntu. Any ideas?

@alliepiper
Copy link
Author

Strange, I can't get the same result here. Does it work if you change the extension to .cu (or pass nvcc -x cu main.cpp)?

If it helps, the warning can be repro'd by copying the current single-header json.hpp into godbolt's CUDA backend: https://www.godbolt.org/z/WWM1hW4v9

@nlohmann
Copy link
Owner

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.

  • Checked out develop branch.
  • Created main.cpp in json/single_include/nlohmann as below.
  • Called nvcc -x cu main.cpp.

Output:

json.hpp:3564:156: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                            ^  
json.hpp:3564:159: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                               
json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_object_type_impl <
                                                                                                                                                                            ^    
json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
json.hpp:3564:239: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                 
json.hpp:3564:242: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                  ^
json.hpp:3564:266: error: template argument 1 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                          ^
json.hpp:3564:268: error: template argument 3 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                            ^
json.hpp:3588:165: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                     ^  
json.hpp:3588:168: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                        ^
json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_constructible_object_type_impl <
                                                                                                                                                                                     ^    
json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
json.hpp:3588:251: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                           ^  
json.hpp:3588:254: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                              ^
json.hpp:3588:278: error: template argument 1 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                      ^
json.hpp:3588:280: error: template argument 3 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                        ^
json.hpp:3657:152: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                        ^  
json.hpp:3657:155: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                           ^
json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_array_type_impl <
                                                                                                                                                                        ^    
json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
json.hpp:3657:234: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                          ^  
json.hpp:3657:237: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                             ^
json.hpp:3657:335: error: template argument 1 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                               ^
json.hpp:3657:337: error: template argument 3 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                 ^
json.hpp:3687:437: error: expansion pattern 'ConstructibleArrayType' contains no argument packs
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^  
json.hpp:3687:440: error: template argument 4 is invalid
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
json.hpp:3687:86: error: parse error in template argument list
 struct is_constructible_array_type_impl <
                                                                                      ^                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
// main.cpp
#include "json.hpp"

int main()
{}
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

@nickaein
Copy link
Contributor

@allisonvacanti

Hi Allison,

I'm not familiar with nvcc, but it seems that there are cases in which nvcc uses an external C++ compiler. For instance, this page says:

A general purpose C++ host compiler is needed by nvcc in the following situations:

  • During non-CUDA phases (except the run phase), because these phases will be forwarded by nvcc to this compiler.
  • During CUDA phases, for several preprocessing stages and host code compilation (see also The CUDA Compilation Trajectory).

So there is the possibility that warnings are being emitted from this host compiler instead of nvcc itself.

You mentioned here that there is a "device compiler" in play, and an exact Google search of emitted error message:

"pointless comparison of unsigned integer with zero"

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?

@alliepiper
Copy link
Author

These do appear to be coming from NVCC itself, and not from the underlying host compiler (which was MSVC 2019 in this case).

@nickaein
Copy link
Contributor

nickaein commented May 27, 2021

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 CXX=nvcc for CMake doesn't work properly, since CMake will try to pass some flags which are incompatible with nvcc (e.g. -rdynamic). We may have to tune CMakeLists.txt and add some flags for activating CUDA compilation, as CMake natively supports compiling C++ cuda codes (example).

I will investigate further in the next days to see how nvcc can be integrated into CI.

@nlohmann
Copy link
Owner

Thanks for taking care of this. It would be cool to have that NVCC in the CI Docker (https://github.com/nlohmann/json-ci).

@lifflander
Copy link

@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., expansion pattern 'CompatibleObjectType' contains no argument packs). After spending over a day rewriting half the type traits in the json library (in a different meta style), I finally found a work around for the bug!

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.

@hei6775
Copy link

hei6775 commented Nov 16, 2021

It seems I don't get warnings, but errors.

$ nvcc main.cu
/root/example/json.hpp:3564:156: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                            ^  
/root/example/json.hpp:3564:159: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                               ^
/root/example/json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_object_type_impl <
                                                                                                                                                                            ^    
/root/example/json.hpp:3564:172: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3564:239: error: expansion pattern 'CompatibleObjectType' contains no argument packs
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                               ^  
/root/example/json.hpp:3564:242: error: template argument 4 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                  ^
/root/example/json.hpp:3564:266: error: template argument 1 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                          ^
/root/example/json.hpp:3564:268: error: template argument 3 is invalid
 struct is_compatible_object_type_impl <
                                                                                                                                                                                                                                                                            ^
/root/example/json.hpp:3588:165: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                     ^  
/root/example/json.hpp:3588:168: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                        ^
/root/example/json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_constructible_object_type_impl <
                                                                                                                                                                                     ^    
/root/example/json.hpp:3588:181: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3588:251: error: expansion pattern 'ConstructibleObjectType' contains no argument packs
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                           ^  
/root/example/json.hpp:3588:254: error: template argument 4 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                              ^
/root/example/json.hpp:3588:278: error: template argument 1 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                      ^
/root/example/json.hpp:3588:280: error: template argument 3 is invalid
 struct is_constructible_object_type_impl <
                                                                                                                                                                                                                                                                                        ^
/root/example/json.hpp:3657:152: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                        ^  
/root/example/json.hpp:3657:155: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                           ^
/root/example/json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
 struct is_compatible_array_type_impl <
                                                                                                                                                                        ^    
/root/example/json.hpp:3657:168: error: 'value' is not a member of 'nlohmann::detail::value_t'
/root/example/json.hpp:3657:234: error: expansion pattern 'CompatibleArrayType' contains no argument packs
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                          ^  
/root/example/json.hpp:3657:237: error: template argument 4 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                             ^
/root/example/json.hpp:3657:335: error: template argument 1 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                               ^
/root/example/json.hpp:3657:337: error: template argument 3 is invalid
 struct is_compatible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                 ^
/root/example/json.hpp:3687:437: error: expansion pattern 'ConstructibleArrayType' contains no argument packs
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^  
/root/example/json.hpp:3687:440: error: template argument 4 is invalid
 struct is_constructible_array_type_impl <
                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
/root/example/json.hpp:3687:86: error: parse error in template argument list
 struct is_constructible_array_type_impl <
                                                                                      ^                                                   
// main.cpp
#include "json.hpp"

int main()
{}
-- The CXX compiler identification is GNU 11.0.1
-- The CUDA compiler identification is NVIDIA 10.1.243

Running on Ubuntu. Any ideas?

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
Copy link
Contributor

nickaein commented Nov 16, 2021

@hei6775 Have you tried this fix? It seems to fix the issue, but we don't have the compilers in the CI to prevent the regression and make sure everything else is also OK.

@hei6775
Copy link

hei6775 commented Nov 16, 2021

@nickaein Hello, I just tried it, but I still get errors. Before the issue was solved, I had to split my json program from the .cu file, then the json file was compiled with g++.

@nickaein
Copy link
Contributor

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: json.hpp
Note that this is not an official release of the library and is considered Work In Progress.

@hei6775
Copy link

hei6775 commented Nov 17, 2021

@nickaein Maybe my expression is not clear. I mean that I use json.hpp in my cuda file. Like this:

#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:

json.hpp:3734:156: error: expansion pattern ‘CompatibleObjectType’ contains no argument packs
json.hpp:3734:159: error: template argument 4 is invalid
json.hpp:3734:95: error: ‘value’ is not a member of ‘nlohmann::detail::value_t’
json.hpp:3734:95: error: ‘value’ is not a member of ‘nlohmann::detail::value_t’
json.hpp:3734:239: error: expansion pattern ‘CompatibleObjectType’ contains no argument packs
 struct is_compatible_object_type_impl <
...
...

No warning, just errors.

@Llcoolsouder
Copy link

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.
I've attached the sample project I used to test this. Without that patch the build fails. After applying the patch, the app compiled with nvcc works as expected.
example-proj.tar.gz

@hei6775
Copy link

hei6775 commented Dec 21, 2021

@Llcoolsouder Tks

@nlohmann
Copy link
Owner

Any idea how to proceed here?

@nlohmann nlohmann added the state: help needed the issue needs help to proceed label Dec 29, 2021
@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

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.
Here is a complete compatibility matrix: https://gist.github.com/ax3l/9489132#compatibility-guarantees

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: -DCMAKE_CXX_COMPILER=$(which g++-7) -DCMAKE_CUDA_HOST_COMPILER=$(which g++-7)

The CXX compiler is used for CMake CXX targes and the CUDAHOSTCXX thingy is used for the host part of CMake CUDA targets. Since they are implemented as independent target languages in CMake, one has do the double hint as above.

@nlohmann
Copy link
Owner

@ax3l Thanks for the hints. But I am confused - don't I still need to bass NVCC to CMake somehow?

@nlohmann
Copy link
Owner

Ok. I'll give it a try and share what I learned in a bit.

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

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.

@nlohmann
Copy link
Owner

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.txt

cmake_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 <
                                                                                                                                                               ^
...

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

Thanks!

I added the following simplifications/updates to get rid of warnings:

CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
project(json_cuda LANGUAGES CUDA)

add_executable(json_cuda json_cuda.cu)
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
)

json_cuda.cu

#include <nlohmann/json.hpp>

int main()
{
    nlohmann::ordered_json json = {"Test"};
    json.dump();
}

Build

$ rm -rf build

$ cmake -S . -B build -DCMAKE_CUDA_HOST_COMPILER=$(which g++-7) -DCMAKE_VERBOSE_MAKEFILE=ON
-- 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
-- Generating done
-- Build files have been written to: /opt/test/nvcc/build

$ cmake --build build
# ...
/usr/bin/nvcc  -ccbin=/usr/bin/g++-7  -I/opt/test/nvcc/../../include --generate-code=arch=compute_30,code=[compute_30,sm_30] -x cu -c /opt/test/nvcc/json_cuda.cu -o CMakeFiles/json_cuda.dir/json_cuda.cu.o ...

I see the same build error as you on develop, also stays when I add -std=c++11 or -std=c++14 flags.

@nlohmann
Copy link
Owner

Thanks - the CMake warnings are gone now. Any ideas now?

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

I think there is a build problem with the enable_if_t/is_detected construct for is_constructible_object_type_impl and is_constructible_array_type_impl.

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

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:

/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits(1356): error: type name is not allowed

/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits(1356): error: type name is not allowed

/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/type_traits(1356): error: identifier "__is_same" is undefined

/opt/test/nvcc/json_cuda.cu(5): error: no instance of constructor "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::basic_json [with ObjectType=nlohmann::ordered_map, ArrayType=std::vector, StringType=std::string, BooleanType=__nv_bool, NumberIntegerType=int64_t, NumberUnsignedType=uint64_t, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer, BinaryType=std::vector<uint8_t, std::allocator<uint8_t>>]" matches the argument list
            argument types are: (const char [5])

/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ext/string_conversions.h(85): error: no instance of overloaded function "_Range_chk::_S_chk" matches the argument list
            argument types are: (const long, std::is_same<int, int>)
          detected during instantiation of "_Ret __gnu_cxx::__stoa(_TRet (*)(const _CharT *, _CharT **, _Base...), const char *, const _CharT *, std::size_t *, _Base...) [with _TRet=long, _Ret=int, _CharT=char, _Base=<int>]" 
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/basic_string.h(6606): here
...

We could try of a newer CTK download fixes the problem already. We could install it via a .deb installer from https://developer.nvidia.com/cuda-downloads or use a Docker image from https://hub.docker.com/r/nvidia/cuda

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

I have some .deb based install logic that pulls selected packages from a recent CUDA toolkit on Ubuntu (instead of pulling everything and every library) here: https://github.com/ECP-WarpX/WarpX/blob/7583728c6b8ad7f634c3f8ed279762ad559432df/.github/workflows/dependencies/nvcc11.sh

A subset of this would replace the slightly older Ubuntu nvidia-cuda-toolkit package that is currently pulled in your Docker image scripts.

@nlohmann
Copy link
Owner

Thanks! I'll give it a try.

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

I think I have a PR to update your CI nearly ready, give me a minute and I will post it :)

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

Posted and currently building/testing locally: nlohmann/json-ci#8

@nlohmann
Copy link
Owner

Thanks so much!

@ax3l
Copy link
Contributor

ax3l commented Dec 29, 2021

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

@nlohmann
Copy link
Owner

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 v2.2.0.

And then I guess it's time to have a look at the warnings mentioned in this issue and #2736.

@nlohmann
Copy link
Owner

Let's see if #3227 works.

@nlohmann nlohmann linked a pull request Dec 29, 2021 that will close this issue
@nlohmann
Copy link
Owner

Alright, #3227 fixes the warning using the fix from @nickaein (thanks!). @allisonvacanti @ax3l @Llcoolsouder can you please double check?

@nlohmann nlohmann added confirmed solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: help needed the issue needs help to proceed state: needs more info the author of the issue needs to provide more details labels Dec 29, 2021
@nlohmann nlohmann added this to the Release 3.10.5 milestone Dec 30, 2021
@nlohmann nlohmann self-assigned this Dec 30, 2021
nlohmann added a commit that referenced this issue Dec 30, 2021
* 👷 add step for NVCC build #2676
* 🚨 fix warning (code taken from #2736)
* 👷 use version 2.2.0 of the CI image
@DAWTcomxDDXXX
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants