Skip to content

Commit 0ebf25e

Browse files
Add --glog flag when building and fix output_message func
1 parent 0e140e6 commit 0ebf25e

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

libsyclinterface/helper/source/dpctl_error_handlers.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int requested_verbosity_level(void)
6565
return requested_level;
6666
}
6767

68-
void output_message(std::string ss_str, error_level error_type)
68+
void output_message(std::string ss_str, error_level error_type, bool to_output)
6969
{
7070
#ifdef ENABLE_GLOG
7171
switch (error_type) {
@@ -79,7 +79,7 @@ void output_message(std::string ss_str, error_level error_type)
7979
LOG(FATAL) << ss_str;
8080
}
8181
#else
82-
if (requested_level >= error_level) {
82+
if (to_output) {
8383
std::cerr << ss_str;
8484
}
8585
#endif
@@ -96,12 +96,14 @@ void error_handler(const std::exception &e,
9696
int requested_level = requested_verbosity_level();
9797
int error_level = static_cast<int>(error_type);
9898

99-
if (requested_level >= error_level) {
99+
bool to_output = requested_level >= error_level;
100+
101+
if (to_output) {
100102
std::stringstream ss;
101103
ss << e.what() << " in " << func_name << " at " << file_name << ":"
102104
<< line_num << std::endl;
103105

104-
output_message(ss.str(), error_type);
106+
output_message(ss.str(), error_type, to_output);
105107
}
106108
}
107109

@@ -114,11 +116,13 @@ void error_handler(const std::string &what,
114116
int requested_level = requested_verbosity_level();
115117
int error_level = static_cast<int>(error_type);
116118

117-
if (requested_level >= error_level) {
119+
bool to_output = requested_level >= error_level;
120+
121+
if (to_output) {
118122
std::stringstream ss;
119123
ss << what << " in " << func_name << " at " << file_name << ":"
120124
<< line_num << std::endl;
121125

122-
output_message(ss.str(), error_type);
126+
output_message(ss.str(), error_type, to_output);
123127
}
124128
}

scripts/build_backend.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def build_backend(
22-
l0_support=False, code_coverage=False, sycl_compiler_prefix=None
22+
l0_support=False, code_coverage=False, glog=False, sycl_compiler_prefix=None
2323
):
2424
import glob
2525
import os
@@ -99,6 +99,8 @@ def build_backend(
9999
"-DCMAKE_CXX_COMPILER:PATH="
100100
+ os.path.join(DPCPP_ROOT, "bin", "clang++"),
101101
]
102+
if glog:
103+
cmake_compiler_args.append("-DDPCTL_ENABLE_GLOG=ON")
102104
if code_coverage:
103105
cmake_args = (
104106
[
@@ -135,7 +137,6 @@ def build_backend(
135137
+ [
136138
"-DDPCTL_ENABLE_LO_PROGRAM_CREATION="
137139
+ ENABLE_LO_PROGRAM_CREATION,
138-
"-DDPCTL_ENABLE_GLOG=ON",
139140
backends,
140141
]
141142
)
@@ -178,6 +179,8 @@ def build_backend(
178179
"-DCMAKE_CXX_COMPILER:PATH="
179180
+ os.path.join(DPCPP_ROOT, "bin", "clang++.exe"),
180181
]
182+
if glog:
183+
cmake_compiler_args.append("-DDPCTL_ENABLE_GLOG=ON")
181184
cmake_args = (
182185
[
183186
"cmake",

setup.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_suppressed_warning_flags():
102102
return []
103103

104104

105-
def build_backend(l0_support, coverage, sycl_compiler_prefix):
105+
def build_backend(l0_support, coverage, glog, sycl_compiler_prefix):
106106
import os.path
107107
from importlib.util import module_from_spec, spec_from_file_location
108108

@@ -114,6 +114,7 @@ def build_backend(l0_support, coverage, sycl_compiler_prefix):
114114
builder_module.build_backend(
115115
l0_support=l0_support,
116116
code_coverage=coverage,
117+
glog=glog,
117118
sycl_compiler_prefix=sycl_compiler_prefix,
118119
)
119120

@@ -358,7 +359,9 @@ def finalize_options(self):
358359
super().finalize_options()
359360

360361
def run(self):
361-
build_backend(self.level_zero_support, False, self.sycl_compiler_prefix)
362+
build_backend(
363+
self.level_zero_support, False, False, self.sycl_compiler_prefix
364+
)
362365
if _coverage:
363366
pre_d = getattr(self, "define", None)
364367
if pre_d is None:
@@ -405,12 +408,18 @@ class develop(orig_develop.develop):
405408
"Whether to generate coverage report "
406409
"when building the backend library",
407410
),
411+
(
412+
"glog=",
413+
None,
414+
"Whether to use Google Logging for errors" "in the backend library",
415+
),
408416
]
409417

410418
def initialize_options(self):
411419
super().initialize_options()
412420
self.level_zero_support = "True"
413421
self.coverage = "False"
422+
self.glog = "False"
414423
self.sycl_compiler_prefix = None
415424

416425
def finalize_options(self):
@@ -430,6 +439,12 @@ def finalize_options(self):
430439
_coverage = self.coverage
431440
else:
432441
raise ValueError("--coverage value is invalid, use True/False")
442+
if isinstance(self.glog, str):
443+
self.glog = self.glog.capitalize()
444+
if self.glog in ["True", "False", "0", "1"]:
445+
self.glog = bool(eval(self.glog))
446+
else:
447+
raise ValueError("--glog value is invalid, use True/False")
433448
if isinstance(self.sycl_compiler_prefix, str):
434449
if not os.path.exists(os.path.join(self.sycl_compiler_prefix)):
435450
raise ValueError(
@@ -449,7 +464,10 @@ def finalize_options(self):
449464

450465
def run(self):
451466
build_backend(
452-
self.level_zero_support, self.coverage, self.sycl_compiler_prefix
467+
self.level_zero_support,
468+
self.coverage,
469+
self.glog,
470+
self.sycl_compiler_prefix,
453471
)
454472
if _coverage:
455473
pre_d = getattr(self, "define", None)

0 commit comments

Comments
 (0)