Skip to content

Commit 611fd71

Browse files
yhmtsaiMarcelKoch
andcommitted
use stringify_object
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
1 parent c293157 commit 611fd71

File tree

2 files changed

+26
-72
lines changed

2 files changed

+26
-72
lines changed

core/log/profiler_hook.cpp

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,6 @@
2323

2424
namespace gko {
2525
namespace log {
26-
namespace {
27-
28-
29-
std::string check_vector_type(const LinOp* linop)
30-
{
31-
#define GKO_CHECK_TYPE(_class, _type) \
32-
if (dynamic_cast<const _class<_type>*>(linop)) { \
33-
return #_class "<" #_type ">"; \
34-
} else if (dynamic_cast<const _class<std::complex<_type>>*>(linop)) { \
35-
return #_class "<complex<" #_type ">>"; \
36-
} \
37-
static_assert(true, \
38-
"This assert is used to counter the false positive extra " \
39-
"semi-colon warnings")
40-
41-
using gko::matrix::Dense;
42-
GKO_CHECK_TYPE(Dense, double);
43-
GKO_CHECK_TYPE(Dense, float);
44-
#if GINKGO_ENABLE_HALF
45-
GKO_CHECK_TYPE(Dense, half);
46-
#endif
47-
#if GINKGO_ENABLE_BFLOAT16
48-
GKO_CHECK_TYPE(Dense, bfloat16);
49-
#endif
50-
51-
#if GINKGO_BUILD_MPI
52-
using gko::experimental::distributed::Vector;
53-
GKO_CHECK_TYPE(Vector, double);
54-
GKO_CHECK_TYPE(Vector, float);
55-
#if GINKGO_ENABLE_HALF
56-
GKO_CHECK_TYPE(Vector, half);
57-
#endif
58-
#if GINKGO_ENABLE_BFLOAT16
59-
GKO_CHECK_TYPE(Vector, bfloat16);
60-
#endif
61-
#endif
62-
63-
#undef GKO_CHECK_TYPE
64-
65-
return "linop";
66-
}
67-
68-
69-
} // namespace
7026

7127

7228
void ProfilerHook::on_allocation_started(const gko::Executor* exec,
@@ -188,8 +144,8 @@ void ProfilerHook::on_linop_apply_started(const LinOp* A, const LinOp* b,
188144
const LinOp* x) const
189145
{
190146
std::stringstream ss;
191-
ss << "apply(" << stringify_object(A) << "*" << check_vector_type(b) << "="
192-
<< check_vector_type(x) << ")";
147+
ss << "apply(" << stringify_object(A) << " * " << stringify_object(b)
148+
<< " = " << stringify_object(x) << ")";
193149
this->begin_hook_(ss.str().c_str(), profile_event_category::linop);
194150
if (dynamic_cast<const solver::IterativeBase*>(A)) {
195151
this->begin_hook_("iteration", profile_event_category::solver);
@@ -201,8 +157,8 @@ void ProfilerHook::on_linop_apply_completed(const LinOp* A, const LinOp* b,
201157
const LinOp* x) const
202158
{
203159
std::stringstream ss;
204-
ss << "apply(" << stringify_object(A) << "*" << check_vector_type(b) << "="
205-
<< check_vector_type(x) << ")";
160+
ss << "apply(" << stringify_object(A) << " * " << stringify_object(b)
161+
<< " = " << stringify_object(x) << ")";
206162
if (dynamic_cast<const solver::IterativeBase*>(A)) {
207163
this->end_hook_("iteration", profile_event_category::solver);
208164
}
@@ -217,9 +173,9 @@ void ProfilerHook::on_linop_advanced_apply_started(const LinOp* A,
217173
const LinOp* x) const
218174
{
219175
std::stringstream ss;
220-
ss << "advanced_apply(" << check_vector_type(alpha) << "*"
221-
<< stringify_object(A) << "*" << check_vector_type(b) << "+"
222-
<< check_vector_type(beta) << "*" << check_vector_type(x) << ")";
176+
ss << "advanced_apply(" << stringify_object(alpha) << " * "
177+
<< stringify_object(A) << " * " << stringify_object(b) << " + "
178+
<< stringify_object(beta) << " * " << stringify_object(x) << ")";
223179
this->begin_hook_(ss.str().c_str(), profile_event_category::linop);
224180
if (dynamic_cast<const solver::IterativeBase*>(A)) {
225181
this->begin_hook_("iteration", profile_event_category::solver);
@@ -234,9 +190,9 @@ void ProfilerHook::on_linop_advanced_apply_completed(const LinOp* A,
234190
const LinOp* x) const
235191
{
236192
std::stringstream ss;
237-
ss << "advanced_apply(" << check_vector_type(alpha) << "*"
238-
<< stringify_object(A) << "*" << check_vector_type(b) << "+"
239-
<< check_vector_type(beta) << "*" << check_vector_type(x) << ")";
193+
ss << "advanced_apply(" << stringify_object(alpha) << " * "
194+
<< stringify_object(A) << " * " << stringify_object(b) << " + "
195+
<< stringify_object(beta) << " * " << stringify_object(x) << ")";
240196
if (dynamic_cast<const solver::IterativeBase*>(A)) {
241197
this->end_hook_("iteration", profile_event_category::solver);
242198
}

core/test/log/profiler_hook.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ TEST(ProfilerHook, LogsPolymorphicObjectLinOp)
110110
"end:copy(obj,obj)",
111111
"begin:move(obj_copy,obj)",
112112
"end:move(obj_copy,obj)",
113-
"begin:apply(obj*linop=linop)",
113+
"begin:apply(obj * obj = obj)",
114114
"begin:op",
115115
"end:op",
116-
"end:apply(obj*linop=linop)",
117-
"begin:advanced_apply(linop*obj*linop+linop*linop)",
116+
"end:apply(obj * obj = obj)",
117+
"begin:advanced_apply(DummyLinOp * obj * obj + DummyLinOp * obj)",
118118
"begin:op",
119119
"end:op",
120-
"end:advanced_apply(linop*obj*linop+linop*linop)",
120+
"end:advanced_apply(DummyLinOp * obj * obj + DummyLinOp * obj)",
121121
"begin:generate(obj_factory)",
122122
"begin:op",
123123
"end:op",
@@ -160,24 +160,22 @@ TEST(ProfilerHook, LogsPolymorphicObjectLinOpApplyWithType)
160160
{
161161
// clang-format off
162162
std::vector<std::string> expected{
163-
"begin:apply(obj*Dense<float>=Dense<complex<double>>)",
163+
"begin:apply(obj * gko::matrix::Dense<float> = gko::matrix::Dense<std::complex<double> >)",
164164
"begin:op",
165165
"end:op",
166-
"end:apply(obj*Dense<float>=Dense<complex<double>>)",
167-
"begin:advanced_apply(Dense<complex<double>>*obj*Dense<float>+Dense<float>*Dense<complex<double>>)",
166+
"end:apply(obj * gko::matrix::Dense<float> = gko::matrix::Dense<std::complex<double> >)",
167+
"begin:advanced_apply(gko::matrix::Dense<std::complex<double> > * obj * gko::matrix::Dense<float> + gko::matrix::Dense<float> * gko::matrix::Dense<std::complex<double> >)",
168168
"begin:op",
169169
"end:op",
170-
"end:advanced_apply(Dense<complex<double>>*obj*Dense<float>+Dense<float>*Dense<complex<double>>)",
171-
"begin:apply(obj*linop=Dense<complex<double>>)",
170+
"end:advanced_apply(gko::matrix::Dense<std::complex<double> > * obj * gko::matrix::Dense<float> + gko::matrix::Dense<float> * gko::matrix::Dense<std::complex<double> >)",
171+
"begin:apply(obj * obj = gko::matrix::Dense<std::complex<double> >)",
172172
"begin:op",
173173
"end:op",
174-
"end:apply(obj*linop=Dense<complex<double>>)",
175-
"begin:advanced_apply(Dense<complex<double>>*obj*Dense<float>+linop*"
176-
"linop)",
174+
"end:apply(obj * obj = gko::matrix::Dense<std::complex<double> >)",
175+
"begin:advanced_apply(gko::matrix::Dense<std::complex<double> > * obj * gko::matrix::Dense<float> + DummyLinOp * obj)",
177176
"begin:op",
178177
"end:op",
179-
"end:advanced_apply(Dense<complex<double>>*obj*Dense<float>+linop*"
180-
"linop)"};
178+
"end:advanced_apply(gko::matrix::Dense<std::complex<double> > * obj * gko::matrix::Dense<float> + DummyLinOp * obj)"};
181179
// clang-format on
182180
std::vector<std::string> output;
183181
auto hooks = make_hooks(output);
@@ -210,14 +208,14 @@ TEST(ProfilerHook, LogsIteration)
210208
using Vec = gko::matrix::Dense<>;
211209
// clang-format off
212210
std::vector<std::string> expected{
213-
"begin:apply(solver*Dense<double>=Dense<double>)",
211+
"begin:apply(solver * mtx = mtx)",
214212
"begin:iteration",
215213
"end:iteration",
216-
"end:apply(solver*Dense<double>=Dense<double>)",
217-
"begin:advanced_apply(Dense<double>*solver*Dense<double>+Dense<double>*Dense<double>)",
214+
"end:apply(solver * mtx = mtx)",
215+
"begin:advanced_apply(gko::matrix::Dense<double> * solver * mtx + gko::matrix::Dense<double> * mtx)",
218216
"begin:iteration",
219217
"end:iteration",
220-
"end:advanced_apply(Dense<double>*solver*Dense<double>+Dense<double>*Dense<double>)"};
218+
"end:advanced_apply(gko::matrix::Dense<double> * solver * mtx + gko::matrix::Dense<double> * mtx)"};
221219
// clang-format on
222220
std::vector<std::string> output;
223221
auto hooks = make_hooks(output);

0 commit comments

Comments
 (0)