Skip to content

Commit 462732f

Browse files
authored
Merge pull request #9735 from awlauria/v5.0.x_mpix_cuda
v5.0.x: CUDA: Enhance MPIX_Query_cuda_support() with runtime support check
2 parents c66bc93 + 6689f96 commit 462732f

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

ompi/mpiext/cuda/c/MPIX_Query_cuda_support.3in

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,33 @@ There is no C++ binding for this function.
2424
.SH DESCRIPTION
2525
.ft R
2626

27+
This routine return 1 if MPI library is build with CUDA and runtime supports CUDA buffers.
28+
This routine must be called after MPI is initialized by a call to MPI_Init or MPI_Init_thread.
29+
2730
.SH Examples
2831
.ft R
32+
.nf
33+
34+
#include <stdio.h>
35+
#include "mpi.h"
36+
37+
#include "mpi-ext.h" /* Needed for CUDA-aware check */
38+
39+
int main(int argc, char *argv[])
40+
{
41+
42+
MPI_Init(&argc, &argv);
43+
44+
if (MPIX_Query_cuda_support()) {
45+
printf("This MPI library has CUDA-aware support.\n");
46+
} else {
47+
printf("This MPI library does not have CUDA-aware support.\n");
48+
}
49+
MPI_Finalize();
50+
51+
return 0;
52+
}
53+
.fi
2954

3055
.SH See Also
3156
.ft R

ompi/mpiext/cuda/c/mpiext_cuda.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include <string.h>
2222

2323
#include "opal/constants.h"
24+
#include "opal/runtime/opal_params.h"
2425
#include "ompi/mpiext/cuda/c/mpiext_cuda_c.h"
2526

2627
/* If CUDA-aware support is configured in, return 1. Otherwise, return 0.
2728
* This API may be extended to return more features in the future. */
2829
int MPIX_Query_cuda_support(void)
2930
{
30-
return OPAL_CUDA_SUPPORT;
31+
return opal_built_with_cuda_support && opal_cuda_runtime_initialized;
3132
}

opal/mca/common/cuda/common_cuda.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ int mca_common_cuda_stage_one_init(void)
456456
#if OPAL_CUDA_GET_ATTRIBUTES
457457
OPAL_CUDA_DLSYM(libcuda_handle, cuPointerGetAttributes);
458458
#endif /* OPAL_CUDA_GET_ATTRIBUTES */
459+
opal_cuda_runtime_initialized = true;
459460
return 0;
460461
}
461462

opal/runtime/opal_params.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bool opal_timing_overhead = true;
6161
#endif
6262

6363
bool opal_built_with_cuda_support = OPAL_INT_TO_BOOL(OPAL_CUDA_SUPPORT);
64+
bool opal_cuda_runtime_initialized = false;
6465
bool opal_cuda_support = false;
6566
bool opal_warn_on_missing_libcuda = true;
6667

opal/runtime/opal_params.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ OPAL_DECLSPEC extern bool opal_built_with_cuda_support;
4848
* */
4949
OPAL_DECLSPEC extern bool opal_cuda_support;
5050

51+
/**
52+
* Whether cuda runtime support is initialized or not.
53+
*/
54+
OPAL_DECLSPEC extern bool opal_cuda_runtime_initialized;
55+
5156
/**
5257
* * Whether we want to warn the user when libcuda is missing.
5358
* */

0 commit comments

Comments
 (0)