abseil-cpp: [Bug]: Parameter pack workaround fails with nvcc

Describe the issue

Was looking into failures with abseil 20240116.1 and tensorflow today, which fail with

# Execution platform: @local_execution_config_platform//:platform
$PREFIX/include/absl/strings/str_cat.h: In function 'std::enable_if_t<(sizeof... (T) > 1), typename std::common_type<typename std::conditional<true, void, absl::lts_20240116::strings_internal::EnableIfFastCase<T, typename std::enable_if<((std::is_arithmetic<T>::value && (! std::is_same<T, char>::value)) && (! std::is_same<T, bool>::value)), void>::type> >::type ...>::type> absl::lts_20240116::StrAppend(absl::Nonnull<T*>, T ...)':
$PREFIX/include/absl/strings/str_cat.h:606:316: error: expected ';' before '...' token
  606 |   for (const SomeTrivialEmptyType& dummy2 :
      |                                           ^  

$PREFIX/include/absl/strings/str_cat.h:606:43: error: parameter packs not expanded with '...': 
  606 |   for (const SomeTrivialEmptyType& dummy2 :
      |                                           ^                         

The relevant chunk of code https://github.com/abseil/abseil-cpp/blob/2f9e432cce407ce0ae50676696666f33a77d42ac/absl/strings/str_cat.h#L606-L614 got introduced recently (d5a2cec006d14c6801ddeb768bf2574a1cf4fa7f), and as it turns out, there already was a comment on that commit noting exactly this problem:

@georgthegreat: @derekmauro, this pattern breaks nvcc (tested with nvcc11.4 + c++14, nvcc11.4 + c++17, nvcc12.1 + c++17 modes) with the following error:

absl/strings/str_cat.h:609:316: error: expected ';' after expression
for (const SomeTrivialEmptyType &dummy2 : ({((((((void)(n = (lengths[i]))), ((void)((n < (0)) ? ((void)((*(pos++)) = '-')), (n = (~n)) : (0)))), ((void)numbers_internal::FastIntToBufferBackward(numbers_internal::UnsignedAbsoluteValue(std::move(args)), pos += n, static_cast< uint32_t>(n)))), ((void)(++i))), dummy1)...}))

Can we do anything about this? I do not quite understand the meaning of this code, so I can not truly refactor it to make it compilable.

I do understand that nvcc is quite weird when it comes to such complex c++ code, so I need a workaround of some kind.

@derekmauro: @higher-performance - Can you take a look at this?

I think it effectively boils down to a compiler shortcoming of nvcc, but it would be good to be able to use abseil with CUDA.

Steps to reproduce the problem

Build CUDA-enabled tensorflow with newest abseil.

What version of Abseil are you using?

20240116.1

What operating system and version are you using?

Linux

What compiler and version are you using?

GCC + nvcc

What build system are you using?

bazel

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @higher-performance

A repro with godbolt here

Ah, here’s a workaround. Apparently this works, I’ll take care of it.