Skip to content

Commit 998a0f0

Browse files
The first implementation of GLog in dpctl
1 parent 22e3123 commit 998a0f0

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

libsyclinterface/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
6868
endif()
6969
endif()
7070

71+
find_package(Threads REQUIRED)
72+
find_package(glog CONFIG REQUIRED)
73+
7174
configure_file(
7275
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
7376
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h
@@ -161,11 +164,15 @@ target_include_directories(DPCTLSyclInterface
161164
${CMAKE_SOURCE_DIR}/include/
162165
${CMAKE_SOURCE_DIR}/helper/include/
163166
${IntelSycl_SYCL_INCLUDE_DIR}
167+
${GLOG_INCLUDE_DIRS}
164168
)
165169

170+
link_directories(${GLOG_LIB_DIR})
171+
166172
target_link_libraries(DPCTLSyclInterface
167173
PRIVATE ${IntelSycl_SYCL_LIBRARY}
168174
PRIVATE ${IntelSycl_OPENCL_LIBRARY}
175+
glog::glog
169176
)
170177

171178
include(GetProjectVersion)

libsyclinterface/helper/source/dpctl_error_handlers.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "dpctl_error_handlers.h"
2727
#include <cstring>
28+
#include <glog/logging.h>
2829

2930
void DPCTL_AsyncErrorHandler::operator()(
3031
const cl::sycl::exception_list &exceptions)
@@ -40,6 +41,29 @@ void DPCTL_AsyncErrorHandler::operator()(
4041
}
4142
}
4243

44+
class GLogHelper
45+
{
46+
public:
47+
GLogHelper()
48+
{
49+
google::InitGoogleLogging("");
50+
google::EnableLogCleaner(0);
51+
google::InstallFailureSignalHandler();
52+
FLAGS_colorlogtostderr = true;
53+
FLAGS_stderrthreshold = google::FATAL;
54+
if (FLAGS_log_dir.empty()) {
55+
FLAGS_log_dir = "/tmp";
56+
}
57+
}
58+
59+
~GLogHelper()
60+
{
61+
google::ShutdownGoogleLogging();
62+
}
63+
};
64+
65+
static GLogHelper gloginit;
66+
4367
inline int get_requested_level(void)
4468
{
4569
int requested_level = 0;
@@ -67,10 +91,9 @@ void error_handler(const std::exception &e,
6791
int requested_level = get_requested_level();
6892
int error_level = static_cast<int>(error_type);
6993

70-
if (requested_level <= error_level) {
71-
std::cerr << e.what() << " in " << func_name << " at " << file_name
72-
<< ":" << line_num << std::endl;
73-
}
94+
LOG_IF(ERROR, requested_level >= error_level)
95+
<< e.what() << " in " << func_name << " at " << file_name << ":"
96+
<< line_num << std::endl;
7497
}
7598

7699
void error_handler(const std::string &what,
@@ -82,8 +105,7 @@ void error_handler(const std::string &what,
82105
int error_level = static_cast<int>(error_type);
83106
int requested_level = get_requested_level();
84107

85-
if (requested_level <= error_level) {
86-
std::cerr << what << " In " << func_name << " at " << file_name << ":"
87-
<< line_num << std::endl;
88-
}
108+
LOG_IF(INFO, requested_level >= error_level)
109+
<< what << " In " << func_name << " at " << file_name << ":" << line_num
110+
<< std::endl;
89111
}

0 commit comments

Comments
 (0)