Skip to content

Fix enum math in verbs.h for CUDA C++20 upgrade via reversions and casts#2147

Closed
r-barnes wants to merge 1 commit intometa-pytorch:mainfrom
r-barnes:export-D89088011
Closed

Fix enum math in verbs.h for CUDA C++20 upgrade via reversions and casts#2147
r-barnes wants to merge 1 commit intometa-pytorch:mainfrom
r-barnes:export-D89088011

Conversation

@r-barnes
Copy link
Contributor

Summary:
Generated by running

hg backout D88882181
hg backout D89083275
hg backout D88911049

and then adding explicit casts.

infiniband/verbs.h caused C++20 compilation failures due to enum-enum math which could not simply be suppressed because it's a header file.

D88882181 converted enum to constants to allow the math to work and because the enums themselves seemed suspect. This caused compilation to succeed with C++20 and unblock a number of broken tests.

But it broke Rust! D89083275 and D88911049 fix Rust by artificially restoring the enum values. But that's a mess.

Here we back out both D88882181 and D89083275 and D88911049. Doing so brings us back to a state where the following compilation error would arise:

buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:573:59: error: bitwise operation between different enumeration types ('(unnamed enum at buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:562:1)' and 'ibv_create_cq_wc_flags') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion]
  573 | IBV_CREATE_CQ_SUP_WC_FLAGS = ((((((IBV_WC_STANDARD_FLAGS) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP)) | (IBV_WC_EX_WITH_CVLAN)) | (IBV_WC_EX_WITH_FLOW_TAG)) | (IBV_WC_EX_WITH_TM_INFO)) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK))
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This time we fix the error by adding explicit (int) casts to the affected Line 573.

The result is code that:

  • Compiles with C++20 by explicitly suppressing the issue causing the compilation failure
  • Retains the enums so that builds with Rust work.

Upstream PR: linux-rdma/rdma-core#1671

See discussion here.

Reviewed By: peterdelevoryas

Differential Revision: D89088011

Summary:
Generated by running
```
hg backout D88882181
hg backout D89083275
hg backout D88911049
```
and then adding explicit casts.

`infiniband/verbs.h` caused C++20 compilation failures due to enum-enum math which could not simply be suppressed because it's a header file.

D88882181 converted `enum` to constants to allow the math to work and because the enums themselves seemed suspect. This caused compilation to succeed with C++20 and unblock a number of broken tests.

But it broke Rust! D89083275 and D88911049 fix Rust by artificially restoring the `enum` values. But that's a mess.

Here we back out both D88882181 and D89083275 and D88911049. Doing so brings us back to a state where the following compilation error would arise:
```
buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:573:59: error: bitwise operation between different enumeration types ('(unnamed enum at buck-out/v2/gen/fbsource/third-party/rdma-core/stablev60/__ibverbs__/c01e142197f8fe04/buck-headers/infiniband/verbs.h:562:1)' and 'ibv_create_cq_wc_flags') is deprecated [-Werror,-Wdeprecated-anon-enum-enum-conversion]
  573 | IBV_CREATE_CQ_SUP_WC_FLAGS = ((((((IBV_WC_STANDARD_FLAGS) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP)) | (IBV_WC_EX_WITH_CVLAN)) | (IBV_WC_EX_WITH_FLOW_TAG)) | (IBV_WC_EX_WITH_TM_INFO)) | (IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK))
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
This time we fix the error by adding explicit `(int)` casts to the affected Line 573.

The result is code that:
* Compiles with C++20 by explicitly suppressing the issue causing the compilation failure
* Retains the enums so that builds with Rust work.

Upstream PR: linux-rdma/rdma-core#1671

See discussion [here](https://fb.workplace.com/groups/rust.language/permalink/30268407786114448/).

Reviewed By: peterdelevoryas

Differential Revision: D89088011
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 15, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 15, 2025

@r-barnes has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89088011.

@meta-codesync
Copy link

meta-codesync bot commented Dec 16, 2025

This pull request has been merged in 8c0401b.

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants