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

Different use_constexpr definitions in spdlog and fmt causes compile time error in NVCC (and possibly other compilers) #2856

Closed
ShujianQian opened this issue Aug 18, 2023 · 4 comments · Fixed by #2901

Comments

@ShujianQian
Copy link

Description

When calling logger.trace() in an .cu file compiled using nvcc, I get the following compile time error:

spdlog/common.h:351:30: error: call to non-‘constexpr’ function ‘const T* fmt::v9::detail::buffer<T>::data() const [with T = char]’
  351 |     return spdlog::string_view_t{buf.data(), buf.size()};
      |                      ~~~~~~~~^~

Cause

The to_string_view utility function is declared as SPDLOG_CONSTEXPR_FUNC. The functions calls fmt::v9::detail::buffer::data() which is declared as FMT_CONSTEXPR. However, FMT_CONSTEXPR has different conditions than SPDLOG_CONSTEXPR_FUNC and is defined to be empty for NVCC, leading to the data() function not declared as constexpr and thus causing the error.

Fix

Adding the same condition to the definition of SPDLOG_CONSTEXPR_FUNC fixes the error. However, the two definitions need to be kept in sync in future changes.

Another potential fix is to declare the to_string_view functions as inline instead of constexpr.

@tt4g
Copy link
Contributor

tt4g commented Aug 18, 2023

PR is welcome.

@gabime
Copy link
Owner

gabime commented Aug 18, 2023

Which version of spdlog?

@ShujianQian
Copy link
Author

This is introduced in commit 4f800773 and is included in v1.12.0 and in the current v1.x branch.

@cartoonist
Copy link

I came across the same issue using nvcc 11.4 and gcc 10.5.0. PR #2859 fixed it for me (spdlog v1.11.0). Thanks @ShujianQian for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants