Skip to content

Commit 1544b6b

Browse files
committed
[Code] Fix cubool hint flags & build in py tset_app
1 parent eabed83 commit 1544b6b

File tree

9 files changed

+97
-40
lines changed

9 files changed

+97
-40
lines changed

cubool/include/cubool/cubool.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,27 @@ typedef enum cuBool_Status {
7373
/** Generic lib hits for matrix processing */
7474
typedef enum cuBool_Hint {
7575
/** No hints passed */
76-
CUBOOL_HINT_NO = 0x0,
76+
CUBOOL_HINT_NO = 0,
7777
/** Force Cpu based backend usage */
78-
CUBOOL_HINT_CPU_BACKEND = 0x1,
78+
CUBOOL_HINT_CPU_BACKEND = 1,
7979
/** Use managed gpu memory type instead of default (device) memory */
80-
CUBOOL_HINT_GPU_MEM_MANAGED = 0x2,
80+
CUBOOL_HINT_GPU_MEM_MANAGED = 2,
8181
/** Mark input data as row-col sorted */
82-
CUBOOL_HINT_VALUES_SORTED = 0x4,
82+
CUBOOL_HINT_VALUES_SORTED = 4,
8383
/** Accumulate result of the operation in the result matrix */
84-
CUBOOL_HINT_ACCUMULATE = 0x8,
84+
CUBOOL_HINT_ACCUMULATE = 8,
8585
/** Finalize library state, even if not all resources were explicitly released */
86-
CUBOOL_HINT_RELAXED_FINALIZE = 0x16,
86+
CUBOOL_HINT_RELAXED_FINALIZE = 16,
8787
/** Logging hint: log includes error message */
88-
CUBOOL_HINT_LOG_ERROR = 0x32,
88+
CUBOOL_HINT_LOG_ERROR = 32,
8989
/** Logging hint: log includes warning message */
90-
CUBOOL_HINT_LOG_WARNING = 0x64,
90+
CUBOOL_HINT_LOG_WARNING = 64,
9191
/** Logging hint: log includes all types of messages */
92-
CUBOOL_HINT_LOG_ALL = 0x128,
92+
CUBOOL_HINT_LOG_ALL = 128,
9393
/** No duplicates in the build data */
94-
CUBOOL_HINT_NO_DUPLICATES = 0x256,
94+
CUBOOL_HINT_NO_DUPLICATES = 256,
9595
/** Performs time measurement and logs elapsed operation time */
96-
CUBOOL_HINT_TIME_CHECK = 0x512
96+
CUBOOL_HINT_TIME_CHECK = 512
9797
} cuBool_Hint;
9898

9999
/** Hit mask */

cubool/sources/core/matrix.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ namespace cubool {
6969
CHECK_RAISE_ERROR(cols != nullptr || nvals == 0, InvalidArgument, "Null ptr cols array");
7070

7171
this->releaseCache();
72+
73+
LogStream stream(*Library::getLogger());
74+
stream << Logger::Level::Info
75+
<< "Matrix:build:" << this->getDebugMarker() << " "
76+
<< "isSorted=" << isSorted << ", "
77+
<< "noDuplicates=" << noDuplicates << LogStream::cmt;
78+
7279
mHnd->build(rows, cols, nvals, isSorted, noDuplicates);
7380
}
7481

cubool/sources/io/logger.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ namespace cubool {
6767
return mEntries.size();
6868
}
6969

70+
bool TextLogger::isDummy() const {
71+
return false;
72+
}
73+
7074
void TextLogger::addFilter(Filter filter) {
7175
mFilters.emplace_back(std::move(filter));
7276
}
@@ -90,4 +94,8 @@ namespace cubool {
9094
size_t DummyLogger::getMessagesCount() const {
9195
return 0;
9296
}
97+
98+
bool DummyLogger::isDummy() const {
99+
return true;
100+
}
93101
}

cubool/sources/io/logger.hpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace cubool {
4949
virtual void logInfo(const std::string &message);
5050
virtual void logWarning(const std::string &message);
5151
virtual void logError(const std::string &message);
52+
virtual bool isDummy() const = 0;
5253
virtual size_t getMessagesCount() const = 0;
5354
};
5455

@@ -69,6 +70,7 @@ namespace cubool {
6970
~TextLogger() override = default;
7071
void log(Level level, const std::string &message) override;
7172
size_t getMessagesCount() const override;
73+
bool isDummy() const override;
7274

7375
void addFilter(Filter filter);
7476
void removeAllFilters();
@@ -97,6 +99,7 @@ namespace cubool {
9799
~DummyLogger() override = default;
98100
void log(Level level, const std::string &message) override;
99101
size_t getMessagesCount() const override;
102+
bool isDummy() const override;
100103
};
101104

102105
/**
@@ -110,27 +113,39 @@ namespace cubool {
110113
explicit LogStream(Logger& logger)
111114
: mLogger(logger), mLevel(Logger::Level::Info) {
112115
};
116+
113117
LogStream(LogStream&& other) noexcept = default;
114118
~LogStream() = default;
115119

116120
void commit() {
117-
mLogger.log(mLevel, mStream.str());
118-
mStream.str(std::string());
121+
if (!mLogger.isDummy()) {
122+
mLogger.log(mLevel, mStream.str());
123+
mStream.str(std::string());
124+
}
119125
}
120126

121127
friend LogStream& operator<<(LogStream& stream, Logger::Level level) {
122-
stream.mLevel = level;
128+
if (!stream.mLogger.isDummy()) {
129+
stream.mLevel = level;
130+
}
131+
123132
return stream;
124133
}
125134

126135
friend LogStream& operator<<(LogStream& stream, Commit commit) {
127-
stream.commit();
136+
if (!stream.mLogger.isDummy()) {
137+
stream.commit();
138+
}
139+
128140
return stream;
129141
}
130142

131143
template<typename T>
132144
friend LogStream& operator<<(LogStream& stream, T&& t) {
133-
stream.mStream << std::forward<T>(t);
145+
if (!stream.mLogger.isDummy()) {
146+
stream.mStream << std::forward<T>(t);
147+
}
148+
134149
return stream;
135150
}
136151

cubool/sources/sequential/sq_matrix.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include <algorithm>
3535
#include <cassert>
3636

37-
#include <iostream>
38-
3937
namespace cubool {
4038

4139
SqMatrix::SqMatrix(size_t nrows, size_t ncols) {

cubool/tests/test_matrix_ewiseadd.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,32 @@ void testRun(cuBool_Index m, cuBool_Index n, cuBool_Hints setup) {
7373
EXPECT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS);
7474
}
7575

76-
TEST(cuBool_Matrix, AddSmall) {
76+
TEST(cuBool_Matrix, EWiseAddSmall) {
7777
cuBool_Index m = 60, n = 80;
7878
testRun(m, n, CUBOOL_HINT_NO);
7979
}
8080

81-
TEST(cuBool_Matrix, AddMedium) {
81+
TEST(cuBool_Matrix, EWiseAddMedium) {
8282
cuBool_Index m = 500, n = 800;
8383
testRun(m, n, CUBOOL_HINT_NO);
8484
}
8585

86-
TEST(cuBool_Matrix, AddLarge) {
86+
TEST(cuBool_Matrix, EWiseAddLarge) {
8787
cuBool_Index m = 2500, n = 1500;
8888
testRun(m, n, CUBOOL_HINT_NO);
8989
}
9090

91-
TEST(cuBool_Matrix, AddSmallFallback) {
91+
TEST(cuBool_Matrix, EWiseAddSmallFallback) {
9292
cuBool_Index m = 60, n = 80;
9393
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
9494
}
9595

96-
TEST(cuBool_Matrix, AddMediumFallback) {
96+
TEST(cuBool_Matrix, EWiseAddMediumFallback) {
9797
cuBool_Index m = 500, n = 800;
9898
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
9999
}
100100

101-
TEST(cuBool_Matrix, AddLargeFallback) {
101+
TEST(cuBool_Matrix, EWiseAddLargeFallback) {
102102
cuBool_Index m = 2500, n = 1500;
103103
testRun(m, n, CUBOOL_HINT_CPU_BACKEND);
104104
}

python/pycubool/bridge.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
"check"
1414
]
1515

16-
_hint_no = 0x0
17-
_hint_cpu_backend = 0x1
18-
_hint_gpu_mem_managed = 0x2
19-
_hint_values_sorted = 0x4
20-
_hint_accumulate = 0x8
21-
_hint_relaxed_release = 0x16
22-
_hint_log_error = 0x32
23-
_hint_log_warning = 0x64
24-
_hint_log_all = 0x128
25-
_hint_no_duplicates = 0x256
26-
_hint_time_check = 0x512
16+
_hint_no = 0
17+
_hint_cpu_backend = 1
18+
_hint_gpu_mem_managed = 2
19+
_hint_values_sorted = 4
20+
_hint_accumulate = 8
21+
_hint_relaxed_release = 16
22+
_hint_log_error = 32
23+
_hint_log_warning = 64
24+
_hint_log_all = 128
25+
_hint_no_duplicates = 256
26+
_hint_time_check = 512
2727

2828

2929
def get_log_hints(default=True, error=False, warning=False):

python/pycubool/matrix.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from . import wrapper
55
from . import bridge
66

7+
78
__all__ = [
89
"Matrix"
910
]
@@ -12,6 +13,30 @@
1213
class Matrix:
1314
"""
1415
Wrapper for cuBool Sparse boolean matrix type.
16+
17+
Matrix class supports all cuBool C API Matrix functions.
18+
Also Matrix class provides additional fancy functions/operators for better user experience.
19+
20+
Matrix creation:
21+
- empty
22+
- from lists data
23+
- random generated
24+
25+
Matrix operations:
26+
- mxm
27+
- ewiseadd
28+
- kronecker
29+
- reduce
30+
- transpose
31+
- matrix extraction
32+
33+
Matrix functions:
34+
- to string
35+
- values iterating
36+
- equality check
37+
38+
Debug features:
39+
- String markers
1540
"""
1641

1742
__slots__ = ["hnd"]
@@ -492,6 +517,7 @@ def mxm(self, other, out=None, accumulate=False, time_check=False):
492517
if out is None:
493518
shape = (self.nrows, other.ncols)
494519
out = Matrix.empty(shape)
520+
accumulate = False
495521

496522
status = wrapper.loaded_dll.cuBool_MxM(
497523
out.hnd,

python/test_app.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import random
2-
from python import pycubool
3-
from python.tests import test_transitive_closure
2+
import pycubool
3+
from tests import test_transitive_closure
44

55

66
def lists_to_pairs(rows, cols):
@@ -34,20 +34,23 @@ def gen_matrix_data(size, seed):
3434
def gen_matrix(size, seed):
3535
rows, cols, nvals = gen_matrix_data(size, seed)
3636
mat = pycubool.Matrix.empty(size)
37-
mat.build(rows, cols, nvals)
37+
mat.build(rows, cols, no_duplicates=True)
3838
return mat, lists_to_pairs(rows, cols)
3939

4040

41-
dim = (100, 100)
42-
to_gen = 500
41+
dim = (10, 10)
42+
to_gen = 50
4343

44+
# pycubool.setup_logger(pycubool.get_default_log_name())
4445
a, a_set = gen_matrix(dim, to_gen)
4546
b, b_set = gen_matrix(dim, to_gen)
4647

4748
print("Matrix a din:", a.shape, "values count:", a.nvals)
4849
print("Matrix b dim:", b.shape, "values count:", b.nvals)
4950

5051
r = a.ewiseadd(b, time_check=True)
52+
c = a.mxm(b, accumulate=True)
53+
print(a, b, c, sep="\n")
5154

5255
print("Matrix r values count:", r.nvals)
5356

0 commit comments

Comments
 (0)