[PGNCCL] Simplify support macro definition (#145964)

- Promotes usage of `NCCL_VERSION_CODE >= NCCL_VERSION(X, Y, Z)`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/145964
Approved by: https://github.com/fduwjj, https://github.com/shuqiangzhang
ghstack dependencies: #145893
This commit is contained in:
Ke Wen
2025-01-29 16:25:30 -08:00
committed by PyTorch MergeBot
parent 4280232f21
commit 9fdc20809a

View File

@ -18,71 +18,43 @@
constexpr int64_t kCommInitBusyWaitMillis = 2; constexpr int64_t kCommInitBusyWaitMillis = 2;
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 14, 0)
(NCCL_MINOR >= 14)
#define NCCL_HAS_COMM_NONBLOCKING #define NCCL_HAS_COMM_NONBLOCKING
#endif #endif
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 18, 0)
(NCCL_MINOR >= 18)
#define NCCL_HAS_COMM_SPLIT #define NCCL_HAS_COMM_SPLIT
#endif #endif
// ncclGetLastError() is enabled only for NCCL versions 2.13+ // ncclGetLastError() is enabled only for NCCL versions 2.13+
// ncclRemoteError only exists in NCCL versions 2.13+ // ncclRemoteError only exists in NCCL versions 2.13+
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 13, 0)
(NCCL_MINOR >= 13)
#define ENABLE_NCCL_GET_LAST_ERROR
#define NCCL_REMOTE_ERROR
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
#define ENABLE_NCCL_GET_LAST_ERROR #define ENABLE_NCCL_GET_LAST_ERROR
#define NCCL_REMOTE_ERROR #define NCCL_REMOTE_ERROR
#endif #endif
static_assert( static_assert(
(NCCL_MAJOR == 2 && NCCL_MINOR >= 7) || (NCCL_MAJOR > 2), NCCL_VERSION_CODE >= NCCL_VERSION(2, 7, 0),
"NCCL version must be 2.7 or later"); "NCCL version must be 2.7 or later");
// The following macros represent features supported prior to NCCL 2.7,
// Error checking is enabled only for NCCL versions 2.4+ since ncclCommAbort() // therefore we can define them unconditionally, given the static_assert above.
// and ncclCommGetAsyncError() are not supported in earlier versions. // TODO: remove these macros from code.
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
(NCCL_MINOR >= 4)
#define ENABLE_NCCL_ERROR_CHECKING #define ENABLE_NCCL_ERROR_CHECKING
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
#define ENABLE_NCCL_ERROR_CHECKING
#endif
// P2P is enabled only for NCCL versions 2.7+ since ncclSend()
// and ncclRecv() are not supported in earlier versions.
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
(NCCL_MINOR >= 7)
#define ENABLE_NCCL_P2P_SUPPORT #define ENABLE_NCCL_P2P_SUPPORT
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3) // End of macros for NCCL 2.7 and below.
#define ENABLE_NCCL_P2P_SUPPORT
#endif
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 11, 0)
(NCCL_MINOR >= 11)
#define ENABLE_NCCL_PREMUL_SUM_SUPPORT
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
#define ENABLE_NCCL_PREMUL_SUM_SUPPORT #define ENABLE_NCCL_PREMUL_SUM_SUPPORT
#endif #endif
// Note: the first version that supports ncclConfig_t is 2.14. Here we // Note: the first version that supports ncclConfig_t is 2.14. Here we
// fast-forward the version requirement to 2.17 where ncclConfig_t has CTA and // fast-forward the version requirement to 2.17 where ncclConfig_t has CTA and
// CGA fields because they have already been pybinded out. // CGA fields because they have already been pybinded out.
#if defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 17, 0)
(NCCL_MINOR >= 17)
#define NCCL_HAS_CONFIG
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
#define NCCL_HAS_CONFIG #define NCCL_HAS_CONFIG
#endif #endif
#if defined(NCCL_REGISTRATION_SUPPORTED) || \ #if NCCL_VERSION_CODE >= NCCL_VERSION(2, 19, 0)
((defined(NCCL_MAJOR) && (NCCL_MAJOR == 2) && defined(NCCL_MINOR) && \
(NCCL_MINOR >= 19)))
#define NCCL_HAS_COMM_REGISTER
#elif defined(NCCL_MAJOR) && (NCCL_MAJOR >= 3)
#define NCCL_HAS_COMM_REGISTER #define NCCL_HAS_COMM_REGISTER
#endif #endif