Spdlog doesn't work with nvcc (12.6) and c++20 (bug in nvcc?)

Experienced CUDA programmer here working on large-scale GPGPU application, using spdlog as logging library. Wanting to migrate from spdlog 1.1 to latest version, however nvcc yields some weird errors.

Here is the minimum reproducible example:

#include <spdlog/spdlog.h>

int main(int argc, char **argv) {
    return 0;
}

Compiling with
nvcc -std=c++20 -c spdlog-error.cu

yields errors:

/usr/include/fmt/core.h: In function ‘constexpr bool fmt::v8::detail::is_constant_evaluated(bool)’:
/usr/include/fmt/core.h:357:14: error: call to non-‘constexpr’ function ‘void fmt::v8::detail::ignore_unused(const T& ...) [with T = {bool}]’
  357 |   ignore_unused(default_value);
      |   ~~~~~~~~~~~^~~~~~~~~~~~~~~
/usr/include/fmt/core.h:352:28: note: ‘void fmt::v8::detail::ignore_unused(const T& ...) [with T = {bool}]’ declared here
  352 | template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
      |                            ^~~~~~~~~~~~~
/usr/include/fmt/format.h: In function ‘constexpr int fmt::v8::detail::count_digits(uint64_t)’:
/usr/include/fmt/format.h:985:29: error: call to non-‘constexpr’ function ‘int fmt::v8::detail::count_digits_fallback(T) [with T = long unsigned int]’
  985 |   return count_digits_fallback(n);

Compiling with g++ works:
g++ -std=c++20 -c spdlog-error.cpp

(To install latest version of spdlog from standard Ubuntu repo, you can use apt install libspdlog-dev)

I am not a language lawyer and am not familiar with the relevant sections of the ISO C++ standard. However, I note that a reference website provides the following tidbit (emphasis mine):

Prior to C++23, the C++ standard says that a constexpr function must return a constexpr value for at least one set of arguments, otherwise it is technically ill-formed. Calling a non-constexpr function unconditionally in a constexpr function makes the constexpr function ill-formed. However, compilers are not required to generate errors or warnings for such cases – therefore, the compiler probably won’t complain unless you try to call such a constexpr function in a constant context. In C++23, this requirement was rescinded.

This might explain the difference in compiler behavior. A proper diagnosis would require a close look at the code the CUDA compiler complains about and some language lawyering along the lines of the quoted section above.

You might also want to try (1) bringing up the issue with spdlog support, as calling a non-constexpr function from a constexpr function may have happened unintentionally (2) switching to the latest CUDA version (for suspected compiler bugs NVIDIA is generally interested in issues that reproduce with the latest version).

Bring internal investigation conclusion here . This is not a nvcc bug . It seems “fmt/core.h” has special handling for nvcc .

98 // Check if relaxed C++14 constexpr is supported.
99 // GCC doesn't allow throw in constexpr until version 6 (bug 67371).
100 #ifndef FMT_USE_CONSTEXPR
101 #  define FMT_USE_CONSTEXPR                                           \
102     (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1912 || \
103      (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) &&           \
104         !FMT_NVCC && !FMT_ICC_VERSION
105 #endif
106 #if FMT_USE_CONSTEXPR
107 #  define FMT_CONSTEXPR constexpr
108 #  define FMT_CONSTEXPR_DECL constexpr
109 #else
110 #  define FMT_CONSTEXPR
111 #  define FMT_CONSTEXPR_DECL
112 #endif

If you try fmt mainline GitHub - fmtlib/fmt: A modern formatting library and GitHub - gabime/spdlog: Fast C++ logging library. mainline , they can compile well in nvcc 12.6 and latest 12.9 .

(base) local-yni@ipp1-0008:~/yni/5271815$ /usr/local/cuda-12.9/bin/nvcc -ccbin=g++-14 -std=c++20 -x cu test.c -c
nvcc warning : Support for offline compilation for architectures prior to '<compute/sm/lto>_75' will be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
(base) local-yni@ipp1-0008:~/yni/5271815$ 
(base) local-yni@ipp1-0008:~/yni/5271815$ /usr/local/cuda-12.6/bin/nvcc -ccbin=g++-11 -std=c++20 -x cu test.c -c
(base) local-yni@ipp1-0008:~/yni/5271815$ 
(base) local-yni@ipp1-0008:~/yni/5271815$ cat test.c
#include <spdlog/spdlog.h>
int main(int argc, char **argv) { 
    return 0; 
} (base) local-yni@ipp1-0008:~/yni/5271815$ 
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.