Skip to content

Commit

Permalink
All done
Browse files Browse the repository at this point in the history
  • Loading branch information
argentea committed Jul 7, 2023
1 parent bea6e36 commit 4eb6653
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 105 deletions.
28 changes: 28 additions & 0 deletions mllib-dal/src/main/native/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ int println(MessageType message_type, const char *format, ...) {
return ret;
}

int printerr(MessageType message_type, const std::string &msg) {
int ret = print2stream(message_type, stdout, msg.c_str());
return ret;
}

int printerr(MessageType message_type, const char *format, ...) {
va_list args;
va_start(args, format);
int ret = print2streamFromArgs(message_type, stderr, format, args);
va_end(args);
return ret;
}

int printerrln(MessageType message_type, const std::string &msg) {
int ret = print2stream(message_type, stderr, msg.c_str());
fprintf(stderr, "\n");
return ret;
}

int printerrln(MessageType message_type, const char *format, ...) {
va_list args;
va_start(args, format);
int ret = print2streamFromArgs(message_type, stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
return ret;
}

int print(MessageType message_type, const oneapi::dal::table &table) {
auto [prefix, enable] = get_prefix(message_type);
if (!enable)
Expand Down
5 changes: 5 additions & 0 deletions mllib-dal/src/main/native/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ int print(MessageType message_type, const char *format, ...);
int print(MessageType message_type, const oneapi::dal::table &table);
int println(MessageType message_type, const char *format, ...);
int println(MessageType message_type, const std::string &msg);

int printerr(MessageType message_type, const std::string &msg);
int printerr(MessageType message_type, const char *format, ...);
int printerrln(MessageType message_type, const char *format, ...);
int printerrln(MessageType message_type, const std::string &msg);
}; // namespace logger
20 changes: 10 additions & 10 deletions mllib-dal/src/main/native/OneCCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "OneCCL.h"
#include "com_intel_oap_mllib_OneCCL__.h"
#include "Logger.h"

extern const size_t ccl_root = 0;

Expand All @@ -47,7 +48,8 @@ JNIEXPORT jint JNICALL Java_com_intel_oap_mllib_OneCCL_00024_c_1init(
JNIEnv *env, jobject obj, jint size, jint rank, jstring ip_port,
jobject param) {

std::cerr << "OneCCL (native): init" << std::endl;
logger::printerrln(logger::INFO, "OneCCL (native): init");


auto t1 = std::chrono::high_resolution_clock::now();

Expand All @@ -68,8 +70,7 @@ JNIEXPORT jint JNICALL Java_com_intel_oap_mllib_OneCCL_00024_c_1init(
auto t2 = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count();
std::cerr << "OneCCL (native): init took " << duration << " secs"
<< std::endl;
logger::printerrln(logger::INFO, "OneCCL (native): init took %d secs", duration);

rank_id = getComm().rank();
comm_size = getComm().size();
Expand All @@ -92,15 +93,15 @@ JNIEXPORT jint JNICALL Java_com_intel_oap_mllib_OneCCL_00024_c_1init(
*/
JNIEXPORT jint JNICALL
Java_com_intel_oap_mllib_OneCCL_00024_c_1initDpcpp(JNIEnv *env, jobject) {
std::cerr << "OneCCL (native): init dpcpp" << std::endl;
logger::printerrln(logger::INFO, "OneCCL (native): init dpcpp");
ccl::init();

return 1;
}

JNIEXPORT void JNICALL
Java_com_intel_oap_mllib_OneCCL_00024_c_1cleanup(JNIEnv *env, jobject obj) {
std::cerr << "OneCCL (native): cleanup" << std::endl;
logger::printerrln(logger::INFO, "OneCCL (native): cleanup");
g_kvs.pop_back();
g_comms.pop_back();
}
Expand Down Expand Up @@ -135,7 +136,7 @@ static int fill_local_host_ip() {
int family = AF_UNSPEC;
char local_ip[CCL_IP_LEN];
if (getifaddrs(&ifaddr) < 0) {
std::cerr << "OneCCL (native): can not get host IP" << std::endl;
logger::printerrln(logger::ERROR, "OneCCL (native): can not get host IP");
return -1;
}

Expand All @@ -157,16 +158,15 @@ static int fill_local_host_ip() {
if (res != 0) {
std::string s("OneCCL (native): getnameinfo error > ");
s.append(gai_strerror(res));
std::cerr << s << std::endl;
logger::printerrln(logger::ERROR, s);
return -1;
}
local_host_ips.push_back(local_ip);
}
}
}
if (local_host_ips.empty()) {
std::cerr << "OneCCL (native): can't find interface to get host IP"
<< std::endl;
logger::printerrln(logger::ERROR, "OneCCL (native): can't find interface to get host IP");
return -1;
}

Expand All @@ -177,7 +177,7 @@ static int fill_local_host_ip() {

static bool is_valid_ip(char ip[]) {
if (fill_local_host_ip() == -1) {
std::cerr << "OneCCL (native): get local host ip error" << std::endl;
logger::printerrln(logger::ERROR, "OneCCL (native): get local host ip error");
return false;
};

Expand Down
Loading

0 comments on commit 4eb6653

Please sign in to comment.