Skip to content

mpl/gpu: fix conversions/comparisons between runtime/driver API enums - #7923

Merged
hzhou merged 7 commits into
pmodels:mainfrom
nmnobre:warnings
Oct 2, 2026
Merged

hzhou merged 7 commits into
pmodels:mainfrom
nmnobre:warnings

Conversation

@nmnobre

@nmnobre nmnobre commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Description

Fixes conversions and comparisons between different CUDA runtime and driver API enum types:

  CC       src/gpu/mpl_gpu_cuda.lo
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c: In function 'MPL_gpu_ipc_handle_create':
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c:146:9: warning: implicit conversion from 'CUresult' {aka 'enum cudaError_enum'} to 'cudaError_t' {aka 'enum cudaError'} [-Wenum-conversion]
  146 |     ret = cuPointerGetAttribute(&ipc_handle->id, CU_POINTER_ATTRIBUTE_BUFFER_ID, (CUdeviceptr) ptr);
      |         ^
In file included from ../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c:9:
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c: In function 'MPL_gpu_get_buffer_id':
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c:200:16: warning: comparison between 'CUresult' {aka 'enum cudaError_enum'} and 'enum cudaError' [-Wenum-compare]
  200 |     assert(ret == cudaSuccess);
      |                ^~
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c: In function 'MPL_gpu_ipc_handle_is_valid':
../../../mpich/src/mpl/src/gpu/mpl_gpu_cuda.c:211:16: warning: comparison between 'CUresult' {aka 'enum cudaError_enum'} and 'enum cudaError' [-Wenum-compare]
  211 |     assert(ret == cudaSuccess);
      |                ^~

Also removes HI_ERR_CHECK(), currently only used to check the return value of hipMemGetAddressRange(), which is of type hipError_t, so should compare with hipSuccess instead:

In file included from ../../../mpich/src/mpl/include/mpl.h:9:
../../../mpich/src/mpl/src/gpu/mpl_gpu_hip.c: In function 'MPL_gpu_get_buffer_bounds':
../../../mpich/src/mpl/src/gpu/mpl_gpu_hip.c:12:46: warning: comparison between 'hipError_t' and 'enum <anonymous>' [-Wenum-compare]
   12 | #define HI_ERR_CHECK(ret) if (unlikely((ret) != HIP_SUCCESS)) goto fn_fail
      |                                              ^~
../../../mpich/src/mpl/include/mpl_base.h:81:42: note: in definition of macro 'unlikely'
   81 | #define unlikely(x_) __builtin_expect(!!(x_),0)
      |                                          ^~
../../../mpich/src/mpl/src/gpu/mpl_gpu_hip.c:448:5: note: in expansion of macro 'HI_ERR_CHECK'
  448 |     HI_ERR_CHECK(hiret);
      |     ^~~~~~~~~~~~

Plus an unused variable:

../../../mpich/src/mpl/src/gpu/mpl_gpu_hip.c: In function 'MPL_gpu_init':
../../../mpich/src/mpl/src/gpu/mpl_gpu_hip.c:358:17: warning: unused variable 'global_dev_id' [-Wunused-variable]
  358 |             int global_dev_id;
      |                 ^~~~~~~~~~~~~

Plus unused code when no ZE:

../mpich/src/mpid/ch4/shm/ipc/gpu/gpu_post.c: In function 'MPIDI_GPU_ipc_local_mmap':
../mpich/src/mpid/ch4/shm/ipc/gpu/gpu_post.c:837:3: warning: label 'fn_fail' defined but not used [-Wunused-label]
  837 |   fn_fail:
      |   ^~~~~~~
../mpich/src/mpid/ch4/shm/ipc/gpu/gpu_post.c: At top level:
../mpich/src/mpid/ch4/shm/ipc/gpu/gpu_post.c:245:13: warning: 'ipc_track_cache_can_insert' defined but not used [-Wunused-function]
  245 | static bool ipc_track_cache_can_insert(void)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~

Plus (solved by initialising the ptr):

../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pup.c: In function 'ipup':
../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pup.c:37:33: warning: 'infopriv' may be used uninitialized [-Wmaybe-uninitialized]
   37 |             if (info && infopriv->gpudriver_id != YAKSURI_GPUDRIVER_ID__UNSET &&
      |                         ~~~~~~~~^~~~~~~~~~~~~~
../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/src/yaksur_pup.c:22:21: note: 'infopriv' was declared here
   22 |     yaksuri_info_s *infopriv;
      |                     ^~~~~~~~

Plus (solved by adding error check):

In function 'MPIDI_SHM_am_send_hdr',
    inlined from 'reply_ipc_write' at ../mpich/src/mpid/ch4/shm/ipc/src/ipc_control.c:229:5:
../mpich/src/mpid/ch4/shm/src/shm_am.h:21:11: warning: 'hdr_sz' may be used uninitialized [-Wmaybe-uninitialized]
   21 |     ret = MPIDI_POSIX_am_send_hdr(rank, comm, handler_id, am_hdr, am_hdr_sz, src_vci, dst_vci);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../mpich/src/mpid/ch4/shm/ipc/src/ipc_control.c: In function 'reply_ipc_write':
../mpich/src/mpid/ch4/shm/ipc/src/ipc_control.c:219:14: note: 'hdr_sz' was declared here
  219 |     MPI_Aint hdr_sz;
      |              ^~~~~~

@nmnobre nmnobre changed the title Warnings Fix conversions and comparisons between CUDA runtime and driver API enum types: Aug 5, 2026
@nmnobre nmnobre changed the title Fix conversions and comparisons between CUDA runtime and driver API enum types: Fix conversions/comparisons between CUDA runtime/driver API enums Aug 5, 2026
@nmnobre nmnobre changed the title Fix conversions/comparisons between CUDA runtime/driver API enums mpl/gpu/cuda: fix conversions/comparisons between CUDA runtime/driver API enums Aug 5, 2026
@nmnobre nmnobre changed the title mpl/gpu/cuda: fix conversions/comparisons between CUDA runtime/driver API enums mpl/gpu: fix conversions/comparisons between runtime/driver API enums Aug 5, 2026

@hzhou hzhou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hzhou

hzhou commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

test:mpich/ch4/gpu

@nmnobre
nmnobre force-pushed the warnings branch 2 times, most recently from 3683a75 to 8932560 Compare October 1, 2026 12:57
@nmnobre

nmnobre commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased and patched a few more warnings.

Only one other left:

../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c: In function 'yaksuri_cuda_init_hook':
../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c:212:36: warning: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
  212 |     yaksuri_cudai_global.streams = calloc(yaksuri_cudai_global.ndevices, sizeof(cudai_stream));
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/external/yuthash.h:31,
                 from ../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/frontend/include/yaksi.h:12,
                 from ../../../../../../mpich/src/mpi/datatype/typerep/yaksa/src/backend/cuda/hooks/yaksuri_cuda_init_hooks.c:6:
/usr/include/stdlib.h:675:14: note: in a call to allocation function 'calloc' declared here
  675 | extern void *calloc (size_t __nmemb, size_t __size)
      |              ^~~~~~

The least bad way I found of getting rid of it is by adding a check just before the calloc(). yaksuri_cudai_global.ndevices is a global and the compiler can't guarantee that it's positive due to the opaque cudaDeviceGetAttribute() in between... something like:

    if (yaksuri_cudai_global.ndevices <= 0) {
        /* no devices to initialize; also lets the compiler know ndevices is non-negative below */
        goto fn_exit;
    }

@hzhou

hzhou commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

test:mpich/ch4/ofi
test:mpich/ch4/ucx

@hzhou
hzhou merged commit 3f818f3 into pmodels:main Oct 2, 2026
8 checks passed
@nmnobre
nmnobre deleted the warnings branch October 3, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants