2018-09-24 16:06:59 -07:00
|
|
|
/*************************************************************************
|
2022-01-07 06:39:55 -08:00
|
|
|
* Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved.
|
2023-02-04 01:43:38 +00:00
|
|
|
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
2018-09-24 16:06:59 -07:00
|
|
|
*
|
|
|
|
|
* See LICENSE.txt for license information
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef NCCL_PARAM_H_
|
|
|
|
|
#define NCCL_PARAM_H_
|
|
|
|
|
|
2022-03-30 02:25:49 -07:00
|
|
|
#include <stdint.h>
|
2018-09-24 16:06:59 -07:00
|
|
|
|
2022-03-30 02:25:49 -07:00
|
|
|
const char* userHomeDir();
|
|
|
|
|
void setEnvFile(const char* fileName);
|
|
|
|
|
void initEnv();
|
2023-09-26 05:47:28 -07:00
|
|
|
const char *ncclGetEnv(const char *name);
|
2018-09-24 16:06:59 -07:00
|
|
|
|
2022-03-30 02:25:49 -07:00
|
|
|
void ncclLoadParam(char const* env, int64_t deftVal, int64_t uninitialized, int64_t* cache);
|
2018-09-24 16:06:59 -07:00
|
|
|
|
2022-03-30 02:25:49 -07:00
|
|
|
#define NCCL_PARAM(name, env, deftVal) \
|
|
|
|
|
int64_t ncclParam##name() { \
|
|
|
|
|
constexpr int64_t uninitialized = INT64_MIN; \
|
|
|
|
|
static_assert(deftVal != uninitialized, "default value cannot be the uninitialized value."); \
|
|
|
|
|
static int64_t cache = uninitialized; \
|
|
|
|
|
if (__builtin_expect(__atomic_load_n(&cache, __ATOMIC_RELAXED) == uninitialized, false)) { \
|
|
|
|
|
ncclLoadParam("NCCL_" env, deftVal, uninitialized, &cache); \
|
2018-09-24 16:06:59 -07:00
|
|
|
} \
|
2022-03-30 02:25:49 -07:00
|
|
|
return cache; \
|
|
|
|
|
}
|
2018-09-24 16:06:59 -07:00
|
|
|
|
2022-09-06 10:29:46 -06:00
|
|
|
#define RCCL_PARAM_DECLARE(name) \
|
|
|
|
|
int64_t rcclParam##name()
|
|
|
|
|
|
2023-02-04 01:43:38 +00:00
|
|
|
#define RCCL_PARAM(name, env, deftVal) \
|
2020-03-18 17:03:03 -07:00
|
|
|
pthread_mutex_t rcclParamMutex##name = PTHREAD_MUTEX_INITIALIZER; \
|
|
|
|
|
int64_t rcclParam##name() { \
|
2023-02-04 01:43:38 +00:00
|
|
|
constexpr int64_t uninitialized = INT64_MIN; \
|
|
|
|
|
static_assert(deftVal != uninitialized, "default value cannot be the uninitialized value."); \
|
|
|
|
|
static int64_t cache = uninitialized; \
|
|
|
|
|
if (__builtin_expect(__atomic_load_n(&cache, __ATOMIC_RELAXED) == uninitialized, false)) { \
|
|
|
|
|
ncclLoadParam("RCCL_" env, deftVal, uninitialized, &cache); \
|
2020-03-18 17:03:03 -07:00
|
|
|
} \
|
2023-02-04 01:43:38 +00:00
|
|
|
return cache; \
|
|
|
|
|
}
|
2020-03-18 17:03:03 -07:00
|
|
|
|
2018-09-24 16:06:59 -07:00
|
|
|
#endif
|