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

dispatch_hash: build error with GCC 6/7 #3772

Closed
stefan-it opened this Issue Nov 18, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@stefan-it
Copy link
Contributor

stefan-it commented Nov 18, 2017

Hi,

I ran into the following compilation error using GCC in version 6.3 and 7.2 (using the latest pytorch version 0fd9682):

/mnt/Repositories/pytorch/torch/csrc/jit/python_arg_flatten.h:28:80:   required from here
/mnt/Repositories/pytorch/torch/csrc/utils/hash.h:75:39: error: call of overloaded 'dispatch_hash(const at::ScalarType&)' is ambiguous
     return _hash_detail::dispatch_hash(o);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/mnt/Repositories/pytorch/torch/csrc/utils/hash.h:52:6: note: candidate: decltype ((std::hash<_Tp>()(o), std::size_t())) torch::_hash_detail::dispatch_hash(const T&) [with T = at::ScalarType; decltype ((std::hash<_Tp>()(o), std::size_t())) = long unsigned int; std::size_t = long unsigned int]
 auto dispatch_hash(const T& o) -> decltype(std::hash<T>()(o), std::size_t()) {
      ^~~~~~~~~~~~~
/mnt/Repositories/pytorch/torch/csrc/utils/hash.h:59:68: note: candidate: typename std::enable_if<std::is_enum<_Tp>::value, long unsigned int>::type torch::_hash_detail::dispatch_hash(const T&) [with T = at::ScalarType; typename std::enable_if<std::is_enum<_Tp>::value, long unsigned int>::type = long unsigned int]
 typename std::enable_if<std::is_enum<T>::value, std::size_t>::type dispatch_hash(const T& o) {
                                                                    ^~~~~~~~~~~~~

But I found a quick workaround for that (torch/csrc/utils/hash.h):

#ifndef _MSC_VER
// MSVC has this one defined already
//template<typename T>
//typename std::enable_if<std::is_enum<T>::value, std::size_t>::type dispatch_hash(const T& o) {
  //return std::hash<int>()(static_cast<int>(o));
//}
#endif

Maybe we can add something like ("pseudo-code") around the dispatcher?

#ifndef _MSC_VER && _GCC_VER < 7

So I guess we can discuss a solution here. I can reproduce this on Arch Linux (both x64 and ARM64) + can give of course further feedback (testing patches and so on) :)

@apaszke

This comment has been minimized.

Copy link
Member

apaszke commented Nov 18, 2017

Yes, that seems fine. Can you please send a PR with a fix?

@apaszke

This comment has been minimized.

Copy link
Member

apaszke commented Nov 18, 2017

@stefan-it

This comment has been minimized.

Copy link
Contributor

stefan-it commented Nov 18, 2017

I'll prepare a PR for that :) The build error also occurs with GCC 6.

@stefan-it stefan-it changed the title dispatch_hash: build error with GCC 7 dispatch_hash: build error with GCC 6/7 Nov 18, 2017

@stefan-it

This comment has been minimized.

Copy link
Contributor

stefan-it commented Nov 20, 2017

This issue is now solved with #3783, so I'm closing here :)

@stefan-it stefan-it closed this Nov 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment