mirror of
https://github.com/microsoft/mscclpp.git
synced 2026-05-24 23:06:17 +00:00
Add a makefile and logging functions
This commit is contained in:
61
src/debug.cc
Normal file
61
src/debug.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
#include "debug.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int mscclDebugLevel = -1;
|
||||
|
||||
void mscclppDebugInit()
|
||||
{
|
||||
int lev = -1;
|
||||
const char *mscclpp_debug = getenv("MSCCLPP_DEBUG");
|
||||
if (mscclpp_debug == nullptr) {
|
||||
lev = MSCCLPP_LOG_NONE;
|
||||
} else {
|
||||
string mscclpp_debug_str(mscclpp_debug);
|
||||
if (mscclpp_debug_str == "INFO") {
|
||||
lev = MSCCLPP_LOG_INFO;
|
||||
} else if (mscclpp_debug_str == "DEBUG") {
|
||||
lev = MSCCLPP_LOG_DEBUG;
|
||||
} else if (mscclpp_debug_str == "ABORT") {
|
||||
lev = MSCCLPP_LOG_ABORT;
|
||||
} else {
|
||||
throw runtime_error("Unknown debug level given: " + mscclpp_debug_str);
|
||||
}
|
||||
}
|
||||
mscclDebugLevel = lev;
|
||||
}
|
||||
|
||||
void mscclppDebugLog(mscclDebugLogLevel level, const char *filefunc, int line,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
if (mscclDebugLevel == -1) {
|
||||
mscclppDebugInit();
|
||||
}
|
||||
if (level < mscclDebugLevel) {
|
||||
return;
|
||||
}
|
||||
string lev_str;
|
||||
if (level == MSCCLPP_LOG_INFO) {
|
||||
lev_str = "INFO";
|
||||
} else if (level == MSCCLPP_LOG_DEBUG) {
|
||||
lev_str = "DEBUG";
|
||||
} else if (level == MSCCLPP_LOG_ABORT) {
|
||||
lev_str = "ABORT";
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
char buffer[1024];
|
||||
va_list vargs;
|
||||
va_start(vargs, fmt);
|
||||
vsnprintf(buffer, 1024, fmt, vargs);
|
||||
va_end(vargs);
|
||||
stringstream ss;
|
||||
ss << "MSCCL " << lev_str << ": (" << filefunc << ":" << line << ") "
|
||||
<< buffer << endl;
|
||||
cerr << ss.str();
|
||||
}
|
||||
20
src/include/debug.h
Normal file
20
src/include/debug.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef MSCCLPP_DEBUG_H_
|
||||
#define MSCCLPP_DEBUG_H_
|
||||
|
||||
extern int mscclDebugLevel;
|
||||
|
||||
typedef enum {
|
||||
MSCCLPP_LOG_NONE = 0,
|
||||
MSCCLPP_LOG_INFO = 1,
|
||||
MSCCLPP_LOG_DEBUG = 2,
|
||||
MSCCLPP_LOG_ABORT = 3,
|
||||
} mscclDebugLogLevel;
|
||||
|
||||
void mscclppDebugLog(mscclDebugLogLevel level, const char *filefunc, int line,
|
||||
const char *fmt, ...);
|
||||
|
||||
#define INFO(...) mscclppDebugLog(MSCCLPP_LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define DEBUG(...) mscclppDebugLog(MSCCLPP_LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define ABORT(...) mscclppDebugLog(MSCCLPP_LOG_ABORT, __FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#endif // MSCCLPP_DEBUG_H_
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef MSCCLPP_H_
|
||||
#define MSCCLPP_H_
|
||||
|
||||
#define MSCCLPP_MAJOR 0
|
||||
#define MSCCLPP_MINOR 1
|
||||
|
||||
@@ -15,4 +18,6 @@ typedef enum { mscclppSuccess = 0,
|
||||
mscclppResult_t mscclppGetUniqueId(mscclppUniqueId* uniqueId);
|
||||
|
||||
//mscclppResult_t mscclppCommInitRank(mscclppComm_t* comm, int nranks, mscclppUniqueId commId, int rank);
|
||||
//mscclppResult_t mscclppCommDestroy(mscclppComm_t comm);
|
||||
//mscclppResult_t mscclppCommDestroy(mscclppComm_t comm);
|
||||
|
||||
#endif // MSCCLPP_H_
|
||||
14
src/init_test.cc
Normal file
14
src/init_test.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <cassert>
|
||||
#include "debug.h"
|
||||
#include "mscclpp.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
mscclppUniqueId uid;
|
||||
mscclppResult_t res = mscclppGetUniqueId(&uid);
|
||||
if (res != mscclppSuccess) {
|
||||
ABORT("mscclppGetUniqueId failed");
|
||||
}
|
||||
INFO("init_test succeed");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user