NVIDIA / NVIDIA/AMGX

[C++20] AMGX chokes on `-Wdeprecated-enum-enum-conversion`

Open
#231 3 comments 0 reactions 1 assignee View on GitHub

@mattmartineau is already working on this.

Since Feb 14, 2023.

build issues
Dominant language
Cuda
Stars
692
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Problem:

include/amgx_config.h:128:42: error: arithmetic between different enumeration types ‘AMGX_MemorySpace’ and ‘AMGX_VecPrecision’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  128 |     AMGX_modeRange = AMGX_memorySpaceNum * AMGX_vecPrecisionNum * AMGX_matPrecisionNum * AMGX_indPrecisionNum,
      |                      ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

It also seems that AMGX_ASSEMBLE_MODE() is a hotbed for these warnings,

include/amgx_config.h:116:13: error: arithmetic between different enumeration types ‘AMGX_MemorySpace’ and ‘AMGX_ModeNums’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  116 |   memSpace  * AMGX_MemorySpaceBase  \
      |             ^
/home/svcpetsc/petsc-hash-pkgs/97b05b/include/amgx_config.h:129:22: note: in expansion of macro ‘AMGX_ASSEMBLE_MODE’
  129 |     AMGX_mode_hDDI = AMGX_ASSEMBLE_MODE(AMGX_host,   AMGX_vecDouble, AMGX_matDouble, AMGX_indInt), // mode == 8192
      |                      ^~~~~~~~~~~~~~~~~~
include/amgx_config.h:117:13: error: arithmetic between different enumeration types ‘AMGX_VecPrecision’ and ‘AMGX_ModeNums’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  117 |   + vecPrec * AMGX_VecPrecisionBase \
      |             ^
/home/svcpetsc/petsc-hash-pkgs/97b05b/include/amgx_config.h:129:22: note: in expansion of macro ‘AMGX_ASSEMBLE_MODE’
  129 |     AMGX_mode_hDDI = AMGX_ASSEMBLE_MODE(AMGX_host,   AMGX_vecDouble, AMGX_matDouble, AMGX_indInt), // mode == 8192
      |                      ^~~~~~~~~~~~~~~~~~
...

Version:

git commit 888c206e7596fe926ea05d7121de4cbb4e9ff90f (main Aug 22 2022) using g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with

-Wall -Werror -std=gnu++20

see https://gitlab.com/petsc/petsc/-/jobs/3699922389 (corresponding make.log truncated to relevant bits)

Suggested fix (illustrative, untested):

#if AMGX_CPP_VERSION >= 23
#  include <utility> // std::to_underlying
#else
#  include <type_traits> // std::underlying_type
#endif

namespace amgx 
{

namespace util
{

#if AMGX_CPP_VERSION >= 23
using std::to_underlying;
#else
template <typename T>
static inline constexpr typename std::underlying_type<T>::type to_underlying(T value) noexcept
{
  static_assert(std::is_enum<T>::value, "");
  return static_cast<typename std::underlying_type<T>::type>(value);
}
#endif

} // namespace util

} // namespace amgx

#define AMGX_ASSEMBLE_MODE(memSpace, vecPrec, matPrec, indPrec)\
(\
  memSpace  * amgx::util::to_underlying(AMGX_MemorySpaceBase)  \
  + vecPrec * amgx::util::to_underlying(AMGX_VecPrecisionBase) \
  + matPrec * amgx::util::to_underlying(AMGX_MatPrecisionBase) \
  + indPrec * amgx::util::to_underlying(AMGX_IndPrecisionBase) \
)

// etc...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.