Skip to content

Commit 9098085

Browse files
committed
[Code] Minor fixes in setElement logic
1 parent a1467ce commit 9098085

File tree

12 files changed

+87
-25
lines changed

12 files changed

+87
-25
lines changed

cubool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ if (CUBOOL_WITH_CUDA)
140140

141141
# Settings: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
142142
target_compile_options(cubool PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
143+
-arch=sm_30
143144
-gencode=arch=compute_30,code=sm_30
144145
-gencode=arch=compute_35,code=sm_35
145146
-gencode=arch=compute_50,code=sm_50

cubool/include/cubool/cubool.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ typedef enum cuBool_Hint {
8484
CUBOOL_HINT_ACCUMULATE = 0x8,
8585
/** Finalize library state, even if not all resources were explicitly released */
8686
CUBOOL_HINT_RELAXED_FINALIZE = 0x16,
87-
/** Logging hint: log error message */
87+
/** Logging hint: log includes error message */
8888
CUBOOL_HINT_LOG_ERROR = 0x32,
89-
/** Logging hint: log warning message */
89+
/** Logging hint: log includes warning message */
9090
CUBOOL_HINT_LOG_WARNING = 0x64,
91-
/** Logging hint: log all messages */
91+
/** Logging hint: log includes all types of messages */
9292
CUBOOL_HINT_LOG_ALL = 0x128,
9393
/** No duplicates in the build data */
9494
CUBOOL_HINT_NO_DUPLICATES = 0x256
@@ -159,7 +159,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetVersion(
159159
* @note Pass `CUBOOL_HINT_LOG_WARNING` to include warning messages into log
160160
* @note Pass `CUBOOL_HINT_LOG_ALL` to include all messages into log
161161
*
162-
* @param logFileName File name in the encoding of the target platform.
162+
* @param logFileName UTF-8 encoded file name and path.
163163
* @param hints Logging hints to filter messages.
164164
*
165165
* @return Error code on this operation

cubool/sources/backend/matrix_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace cubool {
3838
virtual ~MatrixBase() = default;
3939

4040
virtual void setElement(index i, index j) = 0;
41-
virtual void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) = 0;
41+
virtual void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) = 0;
4242
virtual void extract(index* rows, index* cols, size_t &nvals) = 0;
4343
virtual void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols) = 0;
4444

cubool/sources/core/matrix.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ namespace cubool {
5252
mCachedJ.push_back(j);
5353
}
5454

55-
void Matrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) {
55+
void Matrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) {
5656
CHECK_RAISE_ERROR(rows != nullptr || nvals == 0, InvalidArgument, "Null ptr rows array");
5757
CHECK_RAISE_ERROR(cols != nullptr || nvals == 0, InvalidArgument, "Null ptr cols array");
5858

5959
this->releaseCache();
60-
mHnd->build(rows, cols, nvals, isSorted, hasDuplicates);
60+
mHnd->build(rows, cols, nvals, isSorted, noDuplicates);
6161
}
6262

6363
void Matrix::extract(index *rows, index *cols, size_t &nvals) {
@@ -205,6 +205,15 @@ namespace cubool {
205205
return mHnd->getNvals();
206206
}
207207

208+
void Matrix::setDebugMarker(const char *marker) {
209+
CHECK_RAISE_ERROR(marker, InvalidArgument, "Null pointer marker string");
210+
mMarker = marker;
211+
}
212+
213+
const char * Matrix::getDebugMarker() const {
214+
return mMarker.c_str();
215+
}
216+
208217
void Matrix::releaseCache() const {
209218
mCachedI.clear();
210219
mCachedJ.clear();
@@ -219,17 +228,22 @@ namespace cubool {
219228
if (cachedNvals == 0)
220229
return;
221230

222-
size_t currentNvals = mHnd->getNvals();
231+
bool isSorted = false;
232+
bool noDuplicates = false;
223233

224-
// Read values from backend matrix and join
225-
if (currentNvals > 0) {
226-
mCachedI.resize(cachedNvals + currentNvals);
227-
mCachedJ.resize(cachedNvals + currentNvals);
228-
mHnd->extract(mCachedI.data() + cachedNvals, mCachedJ.data() + cachedNvals, currentNvals);
229-
}
234+
// We will have to join old and new values
235+
if (mHnd->getNvals() > 0) {
236+
// Build tmp matrix with new values
237+
MatrixBase* tmp = mProvider->createMatrix(getNrows(), getNcols());
238+
tmp->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates);
230239

231-
// Build matrix
232-
mHnd->build(mCachedI.data(), mCachedJ.data(), cachedNvals + currentNvals, false, true);
240+
// Add new values to current matrix content
241+
mHnd->eWiseAdd(*mHnd, *tmp);
242+
}
243+
// Otherwise, new values are used to build matrix content
244+
else {
245+
mHnd->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates);
246+
}
233247

234248
// Clear arrays
235249
releaseCache();

cubool/sources/core/matrix.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace cubool {
3838
~Matrix() override;
3939

4040
void setElement(index i, index j) override;
41-
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) override;
41+
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override;
4242
void extract(index *rows, index *cols, size_t &nvals) override;
4343
void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols) override;
4444

@@ -54,6 +54,9 @@ namespace cubool {
5454
index getNcols() const override;
5555
index getNvals() const override;
5656

57+
void setDebugMarker(const char* marker);
58+
const char* getDebugMarker() const;
59+
5760
private:
5861

5962
void releaseCache() const;
@@ -63,6 +66,9 @@ namespace cubool {
6366
mutable std::vector<index> mCachedI;
6467
mutable std::vector<index> mCachedJ;
6568

69+
// Marker for debugging
70+
std::string mMarker;
71+
6672
// Implementation handle references
6773
MatrixBase* mHnd = nullptr;
6874
BackendBase* mProvider = nullptr;

cubool/sources/cuBool_Matrix_Build.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ cuBool_Status cuBool_Matrix_Build(
3535
CUBOOL_VALIDATE_LIBRARY
3636
CUBOOL_ARG_NOT_NULL(matrix)
3737
auto m = (cubool::Matrix *) matrix;
38-
m->build(rows, cols, nvals, hints & CUBOOL_HINT_VALUES_SORTED, !(hints & CUBOOL_HINT_NO_DUPLICATES));
38+
m->build(rows, cols, nvals, hints & CUBOOL_HINT_VALUES_SORTED, hints & CUBOOL_HINT_NO_DUPLICATES);
3939
CUBOOL_END_BODY
4040
}

cubool/sources/cuda/matrix_csr.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace cubool {
3838
RAISE_ERROR(NotImplemented, "This function is not supported for this matrix class");
3939
}
4040

41-
void MatrixCsr::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) {
41+
void MatrixCsr::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) {
4242
if (nvals == 0) {
4343
mMatrixImpl.zero_dim(); // no content, empty matrix
4444
return;
@@ -87,7 +87,7 @@ namespace cubool {
8787
}
8888

8989
// Reduce duplicated values
90-
if (hasDuplicates) {
90+
if (!noDuplicates) {
9191
size_t unique = 0;
9292
for (size_t i = 0; i < getNrows(); i++) {
9393
index prev = std::numeric_limits<index>::max();

cubool/sources/cuda/matrix_csr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace cubool {
4444
~MatrixCsr() override = default;
4545

4646
void setElement(index i, index j) override;
47-
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) override;
47+
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override;
4848
void extract(index* rows, index* cols, size_t &nvals) override;
4949
void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols) override;
5050

cubool/sources/cuda/matrix_dense.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace cubool {
5454
MatrixDense(MatrixDense&& other) noexcept = delete;
5555
~MatrixDense() override = default;
5656

57-
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) override;
57+
void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override;
5858
void extract(index* rows, index* cols, size_t& nvals) override;
5959

6060
void clone(const MatrixBase& other) override;

cubool/sources/sequential/sq_matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace cubool {
5050
RAISE_ERROR(NotImplemented, "This function is not supported for this matrix class");
5151
}
5252

53-
void SqMatrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool hasDuplicates) {
53+
void SqMatrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) {
5454
auto nrows = mData.nrows;
5555
auto ncols = mData.ncols;
5656

@@ -98,7 +98,7 @@ namespace cubool {
9898
}
9999
}
100100

101-
if (hasDuplicates) {
101+
if (!noDuplicates) {
102102
size_t unique = 0;
103103
for (size_t i = 0; i < getNrows(); i++) {
104104
index prev = std::numeric_limits<index>::max();

0 commit comments

Comments
 (0)