Skip to content

Commit 1134ad9

Browse files
yhmtsaiMarcelKoch
andcommitted
use logger to check the calling path
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
1 parent 7429712 commit 1134ad9

4 files changed

Lines changed: 201 additions & 8 deletions

File tree

reference/test/factorization/ic_kernels.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

55
#include <algorithm>
66
#include <memory>
7+
#include <string>
78
#include <vector>
89

910
#include <gtest/gtest.h>
1011

1112
#include <ginkgo/core/base/executor.hpp>
1213
#include <ginkgo/core/factorization/ic.hpp>
14+
#include <ginkgo/core/log/logger.hpp>
1315
#include <ginkgo/core/matrix/coo.hpp>
1416
#include <ginkgo/core/matrix/csr.hpp>
1517
#include <ginkgo/core/matrix/dense.hpp>
1618

1719
#include "core/test/utils.hpp"
1820

1921

22+
struct CheckOperationLogger : gko::log::Logger {
23+
void on_operation_launched(const gko::Executor*,
24+
const gko::Operation* op) const override
25+
{
26+
std::string s = op->get_name();
27+
if (s.find("sparselib") != std::string::npos) {
28+
contains_sparselib = true;
29+
}
30+
}
31+
32+
mutable bool contains_sparselib = false;
33+
};
34+
35+
2036
class DummyLinOp : public gko::EnableLinOp<DummyLinOp>,
2137
public gko::EnableCreateMethod<DummyLinOp> {
2238
public:
@@ -69,7 +85,7 @@ class Ic : public ::testing::Test {
6985
tol{r<value_type>::value}
7086
{}
7187

72-
std::shared_ptr<const gko::ReferenceExecutor> ref;
88+
std::shared_ptr<gko::ReferenceExecutor> ref;
7389
std::shared_ptr<const gko::Executor> exec;
7490
std::shared_ptr<Csr> identity;
7591
std::shared_ptr<Csr> banded;
@@ -118,6 +134,40 @@ TYPED_TEST(Ic, SetStrategy)
118134
}
119135

120136

137+
TYPED_TEST(Ic, UsesSyncFreeAlgorithm)
138+
{
139+
using value_type = typename TestFixture::value_type;
140+
using index_type = typename TestFixture::index_type;
141+
auto logger = std::make_shared<CheckOperationLogger>();
142+
this->ref->add_logger(logger);
143+
144+
auto fact =
145+
gko::factorization::Ic<value_type, index_type>::build()
146+
.with_algorithm(gko::factorization::incomplete_algorithm::syncfree)
147+
.on(this->ref)
148+
->generate(this->mtx_system);
149+
150+
ASSERT_FALSE(logger->contains_sparselib);
151+
}
152+
153+
154+
TYPED_TEST(Ic, UsesSparseLibAlgorithm)
155+
{
156+
using value_type = typename TestFixture::value_type;
157+
using index_type = typename TestFixture::index_type;
158+
auto logger = std::make_shared<CheckOperationLogger>();
159+
this->ref->add_logger(logger);
160+
161+
auto fact =
162+
gko::factorization::Ic<value_type, index_type>::build()
163+
.with_algorithm(gko::factorization::incomplete_algorithm::sparselib)
164+
.on(this->ref)
165+
->generate(this->mtx_system);
166+
167+
ASSERT_TRUE(logger->contains_sparselib);
168+
}
169+
170+
121171
TYPED_TEST(Ic, IsConsistentWithComposition)
122172
{
123173
auto fact = this->fact_fact->generate(this->mtx_system);

reference/test/factorization/ilu_kernels.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -11,14 +11,26 @@
1111

1212
#include <ginkgo/core/base/executor.hpp>
1313
#include <ginkgo/core/factorization/ilu.hpp>
14+
#include <ginkgo/core/log/logger.hpp>
1415
#include <ginkgo/core/matrix/coo.hpp>
1516
#include <ginkgo/core/matrix/csr.hpp>
1617
#include <ginkgo/core/matrix/dense.hpp>
1718

1819
#include "core/test/utils.hpp"
1920

2021

21-
namespace {
22+
struct CheckOperationLogger : gko::log::Logger {
23+
void on_operation_launched(const gko::Executor*,
24+
const gko::Operation* op) const override
25+
{
26+
std::string s = op->get_name();
27+
if (s.find("sparselib") != std::string::npos) {
28+
contains_sparselib = true;
29+
}
30+
}
31+
32+
mutable bool contains_sparselib = false;
33+
};
2234

2335

2436
class DummyLinOp : public gko::EnableLinOp<DummyLinOp>,
@@ -147,7 +159,7 @@ class Ilu : public ::testing::Test {
147159
mtx_csr_small2 = std::move(tmp_csr2);
148160
}
149161

150-
std::shared_ptr<const gko::ReferenceExecutor> ref;
162+
std::shared_ptr<gko::ReferenceExecutor> ref;
151163
std::shared_ptr<const gko::Executor> exec;
152164
std::shared_ptr<const Dense> identity;
153165
std::shared_ptr<const Dense> lower_triangular;
@@ -229,6 +241,40 @@ TYPED_TEST(Ilu, SetUStrategy)
229241
}
230242

231243

244+
TYPED_TEST(Ilu, UsesSyncFreeAlgorithm)
245+
{
246+
using value_type = typename TestFixture::value_type;
247+
using index_type = typename TestFixture::index_type;
248+
auto logger = std::make_shared<CheckOperationLogger>();
249+
this->ref->add_logger(logger);
250+
251+
auto fact =
252+
gko::factorization::Ilu<value_type, index_type>::build()
253+
.with_algorithm(gko::factorization::incomplete_algorithm::syncfree)
254+
.on(this->ref)
255+
->generate(this->mtx_small);
256+
257+
ASSERT_FALSE(logger->contains_sparselib);
258+
}
259+
260+
261+
TYPED_TEST(Ilu, UsesSparseLibAlgorithm)
262+
{
263+
using value_type = typename TestFixture::value_type;
264+
using index_type = typename TestFixture::index_type;
265+
auto logger = std::make_shared<CheckOperationLogger>();
266+
this->ref->add_logger(logger);
267+
268+
auto fact =
269+
gko::factorization::Ilu<value_type, index_type>::build()
270+
.with_algorithm(gko::factorization::incomplete_algorithm::sparselib)
271+
.on(this->ref)
272+
->generate(this->mtx_small);
273+
274+
ASSERT_TRUE(logger->contains_sparselib);
275+
}
276+
277+
232278
TYPED_TEST(Ilu, LUFactorFunctionsSetProperly)
233279
{
234280
auto factors = this->ilu_factory_skip->generate(this->mtx_small);
@@ -565,6 +611,3 @@ TYPED_TEST(Ilu, GenerateForReverseCsrSmall)
565611
GKO_ASSERT_MTX_NEAR(l_factor, this->small_l_expected, r<value_type>::value);
566612
GKO_ASSERT_MTX_NEAR(u_factor, this->small_u_expected, r<value_type>::value);
567613
}
568-
569-
570-
} // namespace

test/factorization/ic_kernels.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,28 @@
1313
#include <ginkgo/core/base/executor.hpp>
1414
#include <ginkgo/core/factorization/ic.hpp>
1515
#include <ginkgo/core/factorization/par_ic.hpp>
16+
#include <ginkgo/core/log/logger.hpp>
1617

1718
#include "core/test/utils.hpp"
1819
#include "core/test/utils/unsort_matrix.hpp"
1920
#include "matrices/config.hpp"
2021
#include "test/utils/common_fixture.hpp"
2122

2223

24+
struct CheckOperationLogger : gko::log::Logger {
25+
void on_operation_launched(const gko::Executor*,
26+
const gko::Operation* op) const override
27+
{
28+
std::string s = op->get_name();
29+
if (s.find("sparselib") != std::string::npos) {
30+
contains_sparselib = true;
31+
}
32+
}
33+
34+
mutable bool contains_sparselib = false;
35+
};
36+
37+
2338
class Ic : public CommonTestFixture {
2439
protected:
2540
using Csr = gko::matrix::Csr<value_type, index_type>;
@@ -38,6 +53,41 @@ class Ic : public CommonTestFixture {
3853
};
3954

4055

56+
TEST_F(Ic, UsesSyncFreeAlgorithm)
57+
{
58+
auto logger = std::make_shared<CheckOperationLogger>();
59+
exec->add_logger(logger);
60+
61+
auto dfact =
62+
gko::factorization::Ic<>::build()
63+
.with_algorithm(gko::factorization::incomplete_algorithm::syncfree)
64+
.on(exec)
65+
->generate(dmtx);
66+
67+
ASSERT_FALSE(logger->contains_sparselib);
68+
}
69+
70+
71+
TEST_F(Ic, UsesSparseLibAlgorithm)
72+
{
73+
auto logger = std::make_shared<CheckOperationLogger>();
74+
exec->add_logger(logger);
75+
76+
auto dfact =
77+
gko::factorization::Ic<>::build()
78+
.with_algorithm(gko::factorization::incomplete_algorithm::sparselib)
79+
.on(exec)
80+
->generate(dmtx);
81+
82+
#ifdef GKO_COMPILING_OMP
83+
// OMP does not have sparselib algorithm
84+
ASSERT_FALSE(logger->contains_sparselib);
85+
#else
86+
ASSERT_TRUE(logger->contains_sparselib);
87+
#endif
88+
}
89+
90+
4191
TEST_F(Ic, ComputeICBySyncfreeIsEquivalentToRefSorted)
4292
{
4393
auto fact =

test/factorization/ilu_kernels.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,28 @@
1313
#include <ginkgo/core/base/executor.hpp>
1414
#include <ginkgo/core/factorization/ilu.hpp>
1515
#include <ginkgo/core/factorization/par_ilu.hpp>
16+
#include <ginkgo/core/log/logger.hpp>
1617

1718
#include "core/test/utils.hpp"
1819
#include "core/test/utils/unsort_matrix.hpp"
1920
#include "matrices/config.hpp"
2021
#include "test/utils/common_fixture.hpp"
2122

2223

24+
struct CheckOperationLogger : gko::log::Logger {
25+
void on_operation_launched(const gko::Executor*,
26+
const gko::Operation* op) const override
27+
{
28+
std::string s = op->get_name();
29+
if (s.find("sparselib") != std::string::npos) {
30+
contains_sparselib = true;
31+
}
32+
}
33+
34+
mutable bool contains_sparselib = false;
35+
};
36+
37+
2338
class Ilu : public CommonTestFixture {
2439
protected:
2540
using Csr = gko::matrix::Csr<value_type, index_type>;
@@ -38,6 +53,41 @@ class Ilu : public CommonTestFixture {
3853
};
3954

4055

56+
TEST_F(Ilu, UsesSyncFreeAlgorithm)
57+
{
58+
auto logger = std::make_shared<CheckOperationLogger>();
59+
exec->add_logger(logger);
60+
61+
auto dfact =
62+
gko::factorization::Ilu<>::build()
63+
.with_algorithm(gko::factorization::incomplete_algorithm::syncfree)
64+
.on(exec)
65+
->generate(dmtx);
66+
67+
ASSERT_FALSE(logger->contains_sparselib);
68+
}
69+
70+
71+
TEST_F(Ilu, UsesSparseLibAlgorithm)
72+
{
73+
auto logger = std::make_shared<CheckOperationLogger>();
74+
exec->add_logger(logger);
75+
76+
auto dfact =
77+
gko::factorization::Ilu<>::build()
78+
.with_algorithm(gko::factorization::incomplete_algorithm::sparselib)
79+
.on(exec)
80+
->generate(dmtx);
81+
82+
#ifdef GKO_COMPILING_OMP
83+
// OMP does not have sparselib algorithm
84+
ASSERT_FALSE(logger->contains_sparselib);
85+
#else
86+
ASSERT_TRUE(logger->contains_sparselib);
87+
#endif
88+
}
89+
90+
4191
TEST_F(Ilu, ComputeILUBySyncfreeIsEquivalentToRefSorted)
4292
{
4393
auto fact =

0 commit comments

Comments
 (0)