Files
rocm-systems/projects/rccl/src/include/checks.h
T

176 lines
6.0 KiB
C
Raw Normal View History

2018-12-13 15:56:12 -08:00
/*************************************************************************
2022-01-07 06:39:55 -08:00
* Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
2018-12-13 15:56:12 -08:00
*
* See LICENSE.txt for license information
************************************************************************/
2019-03-14 19:39:20 -07:00
#ifndef NCCL_CHECKS_H_
#define NCCL_CHECKS_H_
2018-12-13 15:56:12 -08:00
2019-03-14 19:39:20 -07:00
#include "debug.h"
2022-05-24 02:02:31 -07:00
// Check CUDA RT calls
2019-03-14 19:39:20 -07:00
#define CUDACHECK(cmd) do { \
2020-05-12 14:40:18 -07:00
cudaError_t err = cmd; \
if( err != cudaSuccess ) { \
WARN("Cuda failure '%s'", cudaGetErrorString(err)); \
2019-03-14 19:39:20 -07:00
return ncclUnhandledCudaError; \
} \
} while(false)
2023-06-13 00:19:57 -07:00
#define CUDACHECKGOTO(cmd, RES, label) do { \
2020-05-12 14:40:18 -07:00
cudaError_t err = cmd; \
if( err != cudaSuccess ) { \
WARN("Cuda failure '%s'", cudaGetErrorString(err)); \
2023-06-13 00:19:57 -07:00
RES = ncclUnhandledCudaError; \
2019-03-14 19:39:20 -07:00
goto label; \
} \
} while(false)
2021-04-12 16:00:11 -07:00
// Report failure but clear error and continue
#define CUDACHECKIGNORE(cmd) do { \
cudaError_t err = cmd; \
if( err != cudaSuccess ) { \
INFO(NCCL_ALL,"%s:%d Cuda failure '%s'", __FILE__, __LINE__, cudaGetErrorString(err)); \
(void) cudaGetLastError(); \
} \
} while(false)
2019-03-14 19:39:20 -07:00
#include <errno.h>
// Check system calls
2024-09-10 05:57:10 -07:00
#define SYSCHECK(statement, name) do { \
2019-03-14 19:39:20 -07:00
int retval; \
2024-09-10 05:57:10 -07:00
SYSCHECKSYNC((statement), name, retval); \
2019-03-14 19:39:20 -07:00
if (retval == -1) { \
2024-09-10 05:57:10 -07:00
WARN("Call to " name " failed: %s", strerror(errno)); \
2019-03-14 19:39:20 -07:00
return ncclSystemError; \
} \
} while (false)
2024-09-10 05:57:10 -07:00
#define SYSCHECKSYNC(statement, name, retval) do { \
retval = (statement); \
2019-03-14 19:39:20 -07:00
if (retval == -1 && (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN)) { \
INFO(NCCL_ALL,"Call to " name " returned %s, retrying", strerror(errno)); \
} else { \
break; \
} \
} while(true)
2024-09-10 05:57:10 -07:00
#define SYSCHECKGOTO(statement, name, RES, label) do { \
int retval; \
SYSCHECKSYNC((statement), name, retval); \
if (retval == -1) { \
WARN("Call to " name " failed: %s", strerror(errno)); \
RES = ncclSystemError; \
goto label; \
} \
} while (0)
// Pthread calls don't set errno and never return EINTR.
#define PTHREADCHECK(statement, name) do { \
int retval = (statement); \
if (retval != 0) { \
WARN("Call to " name " failed: %s", strerror(retval)); \
return ncclSystemError; \
} \
} while (0)
#define PTHREADCHECKGOTO(statement, name, RES, label) do { \
int retval = (statement); \
if (retval != 0) { \
WARN("Call to " name " failed: %s", strerror(retval)); \
RES = ncclSystemError; \
2022-01-07 06:39:55 -08:00
goto label; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2022-01-07 06:39:55 -08:00
#define NEQCHECK(statement, value) do { \
if ((statement) != value) { \
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
INFO(NCCL_ALL,"%s:%d -> %d (%s)", __FILE__, __LINE__, ncclSystemError, strerror(errno)); \
2022-01-07 06:39:55 -08:00
return ncclSystemError; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2022-01-07 06:39:55 -08:00
2023-06-13 00:19:57 -07:00
#define NEQCHECKGOTO(statement, value, RES, label) do { \
2022-01-07 06:39:55 -08:00
if ((statement) != value) { \
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
RES = ncclSystemError; \
INFO(NCCL_ALL,"%s:%d -> %d (%s)", __FILE__, __LINE__, RES, strerror(errno)); \
2022-01-07 06:39:55 -08:00
goto label; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2022-01-07 06:39:55 -08:00
#define EQCHECK(statement, value) do { \
if ((statement) == value) { \
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
INFO(NCCL_ALL,"%s:%d -> %d (%s)", __FILE__, __LINE__, ncclSystemError, strerror(errno)); \
2022-01-07 06:39:55 -08:00
return ncclSystemError; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2022-01-07 06:39:55 -08:00
2023-06-13 00:19:57 -07:00
#define EQCHECKGOTO(statement, value, RES, label) do { \
2022-01-07 06:39:55 -08:00
if ((statement) == value) { \
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
RES = ncclSystemError; \
INFO(NCCL_ALL,"%s:%d -> %d (%s)", __FILE__, __LINE__, RES, strerror(errno)); \
2022-01-07 06:39:55 -08:00
goto label; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2022-01-07 06:39:55 -08:00
2019-03-14 19:39:20 -07:00
// Propagate errors up
#define NCCLCHECK(call) do { \
2023-06-13 00:19:57 -07:00
ncclResult_t RES = call; \
if (RES != ncclSuccess && RES != ncclInProgress) { \
2019-03-14 19:39:20 -07:00
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
if (ncclDebugNoWarn == 0) INFO(NCCL_ALL,"%s:%d -> %d", __FILE__, __LINE__, RES); \
return RES; \
2019-03-14 19:39:20 -07:00
} \
2024-09-10 05:57:10 -07:00
} while (0)
2019-03-14 19:39:20 -07:00
2023-06-13 00:19:57 -07:00
#define NCCLCHECKGOTO(call, RES, label) do { \
RES = call; \
if (RES != ncclSuccess && RES != ncclInProgress) { \
2019-03-14 19:39:20 -07:00
/* Print the back trace*/ \
2023-06-13 00:19:57 -07:00
if (ncclDebugNoWarn == 0) INFO(NCCL_ALL,"%s:%d -> %d", __FILE__, __LINE__, RES); \
2019-03-14 19:39:20 -07:00
goto label; \
} \
2024-09-10 05:57:10 -07:00
} while (0)
2019-03-14 19:39:20 -07:00
2022-01-07 06:39:55 -08:00
#define NCCLWAIT(call, cond, abortFlagPtr) do { \
2024-06-11 01:28:01 -07:00
uint32_t* tmpAbortFlag = (abortFlagPtr); \
2023-06-13 00:19:57 -07:00
ncclResult_t RES = call; \
if (RES != ncclSuccess && RES != ncclInProgress) { \
if (ncclDebugNoWarn == 0) INFO(NCCL_ALL,"%s:%d -> %d", __FILE__, __LINE__, RES); \
2022-01-07 06:39:55 -08:00
return ncclInternalError; \
} \
2024-06-11 01:28:01 -07:00
if (__atomic_load(tmpAbortFlag, __ATOMIC_ACQUIRE)) NEQCHECK(*tmpAbortFlag, 0); \
2024-09-10 05:57:10 -07:00
} while (!(cond))
2022-01-07 06:39:55 -08:00
2023-06-13 00:19:57 -07:00
#define NCCLWAITGOTO(call, cond, abortFlagPtr, RES, label) do { \
2024-06-11 01:28:01 -07:00
uint32_t* tmpAbortFlag = (abortFlagPtr); \
2023-06-13 00:19:57 -07:00
RES = call; \
if (RES != ncclSuccess && RES != ncclInProgress) { \
if (ncclDebugNoWarn == 0) INFO(NCCL_ALL,"%s:%d -> %d", __FILE__, __LINE__, RES); \
2022-01-07 06:39:55 -08:00
goto label; \
} \
2024-06-11 01:28:01 -07:00
if (__atomic_load(tmpAbortFlag, __ATOMIC_ACQUIRE)) NEQCHECKGOTO(*tmpAbortFlag, 0, RES, label); \
2024-09-10 05:57:10 -07:00
} while (!(cond))
2022-01-07 06:39:55 -08:00
2022-05-24 02:02:31 -07:00
#define NCCLCHECKTHREAD(a, args) do { \
2022-08-18 02:53:17 -07:00
if (((args)->ret = (a)) != ncclSuccess && (args)->ret != ncclInProgress) { \
2022-05-24 02:02:31 -07:00
INFO(NCCL_INIT,"%s:%d -> %d [Async thread]", __FILE__, __LINE__, (args)->ret); \
2022-01-07 06:39:55 -08:00
return args; \
} \
} while(0)
#define CUDACHECKTHREAD(a) do { \
if ((a) != cudaSuccess) { \
INFO(NCCL_INIT,"%s:%d -> %d [Async thread]", __FILE__, __LINE__, args->ret); \
args->ret = ncclUnhandledCudaError; \
return args; \
} \
} while(0)
2019-03-14 19:39:20 -07:00
#endif