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

ordered_json::reset() compile error with nvcc #3013

Closed
lashgar opened this issue Sep 10, 2021 · 9 comments · Fixed by #3234
Closed

ordered_json::reset() compile error with nvcc #3013

lashgar opened this issue Sep 10, 2021 · 9 comments · Fixed by #3234
Assignees
Labels
confirmed release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@lashgar
Copy link

lashgar commented Sep 10, 2021

Compiling this code:

#include <nlohmann/json.hpp>
int main()
{
  nlohmann::ordered_json metadata;
  metadata.erase("key"); 
  return 0;
}

with following command:
/usr/local/cuda-11.4/bin/nvcc -I/path/to/nlohmann-json/include/ -c file.cu -o a.out
fails with:

(const BasicJsonType &) [with BasicJsonType=nlohmann::json]"
          detected during instantiation of "std::size_t nlohmann::detail::hash(const BasicJsonType &) [with BasicJsonType=nlohmann::json]" 
/path/to/nlohmann-json/include/nlohmann/json.hpp(8709): here

/path/to/nlohmann-json/include/nlohmann/ordered_map.hpp: In instantiation of ‘typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type nlohmann::ordered_map<Key, T, IgnoredLess, Allocator>::erase(const Key&) [with Key = std::__cxx11::basic_string<char>; T = nlohmann::basic_json<nlohmann::ordered_map>; IgnoredLess = std::less<>; Allocator = std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> > >; typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type = long unsigned int]’:
/path/to/nlohmann-json/include/nlohmann/json.hpp:4241:37:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::erase(const typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type&) [with ObjectType = nlohmann::ordered_map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type = long unsigned int; typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type = std::__cxx11::basic_string<char>]’
file.cu:7:21:   required from here
/path/to/nlohmann-json/include/nlohmann/ordered_map.hpp:92:6: error: object type ‘std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> >’ does not match destructor name ~‘value_type’
   92 |                     it->~value_type(); // Destroy but keep allocation
      |      ^         
make: *** [Makefile:13: toy] Error 1

nlohmann json version: 3.9.1
gcc version: 9.3

Tested with nvcc version 11.0, 11.1, 11.2, 11.3, and 11.4 with same error. This code compiles fine with gcc. Possibly an nvcc/C++ bug, but there might be a solution in nlohmann/json side?

@nlohmann
Copy link
Owner

Thanks for reporting. We really need an NVCC running in our CI - see also #2676. We have nvcc 10.1.243 in our Docker image (https://github.com/nlohmann/json-ci), but so far failed to properly build the library with it. Is there a way to build the test suite with it?

@nlohmann
Copy link
Owner

We now added NVCC to the CI. I added your code example to check if I can reproduce the issue.

@nlohmann
Copy link
Owner

I can reproduce your findings:

FAILED: CMakeFiles/json_cuda.dir/json_cuda.cu.o 
/usr/local/cuda/bin/nvcc -forward-unknown-to-host-compiler -ccbin=g++-8  -I/__w/json/json/test/cuda_example/../../include -g --generate-code=arch=compute_52,code=[compute_52,sm_52] -MD -MT CMakeFiles/json_cuda.dir/json_cuda.cu.o -MF CMakeFiles/json_cuda.dir/json_cuda.cu.o.d -x cu -c /__w/json/json/test/cuda_example/json_cuda.cu -o CMakeFiles/json_cuda.dir/json_cuda.cu.o
/__w/json/json/test/cuda_example/../../include/nlohmann/ordered_map.hpp: In instantiation of 'typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type nlohmann::ordered_map<Key, T, IgnoredLess, Allocator>::erase(const Key&) [with Key = std::__cxx11::basic_string<char>; T = nlohmann::basic_json<nlohmann::ordered_map>; IgnoredLess = std::less<>; Allocator = std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> > >; typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type = long unsigned int]':
make[3]: *** [CMakeFiles/ci_cuda_example.dir/build.make:71: CMakeFiles/ci_cuda_example] Error 1
/__w/json/json/test/cuda_example/../../include/nlohmann/json.hpp:2399:39:   required from 'nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::erase(const typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type&) [with ObjectType = nlohmann::ordered_map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type = long unsigned int; typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type = std::__cxx11::basic_string<char>]'
/__w/json/json/test/cuda_example/json_cuda.cu:10:21:   required from here
/__w/json/json/test/cuda_example/../../include/nlohmann/ordered_map.hpp:98:7: error: object type 'std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> >' does not match destructor name ~'value_type'
                     it->~value_type(); // Destroy but keep allocation
       ^     

I am, however, not sure if this is actually an error, because value_type is an alias for std::pair<const Key, T>. Any ideas?

@nlohmann nlohmann added the state: help needed the issue needs help to proceed label Dec 30, 2021
@lashgar
Copy link
Author

lashgar commented Dec 30, 2021

I suggest using NVCC 11.0 or later in the CI. Older versions have a very poor support of C++ and parser fails in reading template notations. CUDA officially supports C++-17 starting version 11.0.

@nlohmann
Copy link
Owner

We use 11.0.221 in the CI.

@nlohmann nlohmann added confirmed release item: 🐛 bug fix 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 labels Dec 31, 2021
@nlohmann nlohmann added this to the Release 3.10.5 milestone Dec 31, 2021
@nlohmann nlohmann self-assigned this Dec 31, 2021
@nlohmann
Copy link
Owner

@lashgar I could fix the issue in our CI. Can you please check whether #3234 works for you?

@lashgar
Copy link
Author

lashgar commented Jan 2, 2022

@nlohmann , yes, #3234 fixes the issue. I tested with nvcc 11.5. Thank you.

Happy new year! 🎉

@ax3l
Copy link
Contributor

ax3l commented Jan 4, 2022

Thanks for the fix 🎉

Just as x-ref: now also reported as Nvidia bug ID 3487723 (developer.nvidia.com).

@nlohmann
Copy link
Owner

nlohmann commented Jan 4, 2022

Thanks for checking back! Good to know that it was actually a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed release item: 🐛 bug fix 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.

3 participants