Skip to content

Commit f37ee08

Browse files
committed
[Code] Add sq vector base methods impl && setup misc vector testing
1 parent af23b7b commit f37ee08

29 files changed

+602
-293
lines changed

cubool/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ set(CUBOOL_SOURCES
4646
sources/core/vector.hpp
4747
sources/io/logger.cpp
4848
sources/io/logger.hpp
49-
sources/utils/exclusive_scan.hpp
49+
sources/utils/algo_utils.hpp
5050
sources/utils/timer.hpp
51-
sources/utils/csr_utils.cpp
52-
sources/utils/csr_utils.hpp)
51+
sources/utils/data_utils.cpp
52+
sources/utils/data_utils.hpp)
5353

5454
set(CUBOOL_C_API_SOURCES
5555
include/cubool/cubool.h
@@ -147,7 +147,9 @@ if (CUBOOL_WITH_SEQUENTIAL)
147147
sources/sequential/sq_reduce.cpp
148148
sources/sequential/sq_reduce.hpp
149149
sources/sequential/sq_submatrix.cpp
150-
sources/sequential/sq_submatrix.hpp)
150+
sources/sequential/sq_submatrix.hpp
151+
sources/sequential/sq_subvector.cpp
152+
sources/sequential/sq_subvector.hpp)
151153
endif()
152154

153155
# Shared library object config

cubool/sources/core/library.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace cubool {
4848
std::unordered_set<class Matrix*> Library::mAllocMatrices;
4949
std::unordered_set<class Vector*> Library::mAllocVectors;
5050
std::shared_ptr<class BackendBase> Library::mBackend = nullptr;
51-
std::shared_ptr<class Logger> Library::mLogger = std::make_shared<DummyLogger>();
51+
std::shared_ptr<class Logger> Library::mLogger = std::make_shared<DummyLogger>();
5252
bool Library::mRelaxedRelease = false;
5353

5454
void Library::initialize(hints initHints) {
@@ -130,11 +130,11 @@ namespace cubool {
130130
void Library::setupLogging(const char *logFileName, cuBool_Hints hints) {
131131
CHECK_RAISE_ERROR(logFileName != nullptr, InvalidArgument, "Null file name is not allowed");
132132

133-
auto lofFile = std::make_shared<std::ofstream>();
133+
auto logFile = std::make_shared<std::ofstream>();
134134

135-
lofFile->open(logFileName, std::ios::out);
135+
logFile->open(logFileName, std::ios::out);
136136

137-
if (!lofFile->is_open()) {
137+
if (!logFile->is_open()) {
138138
RAISE_ERROR(InvalidArgument, "Failed to create logging file");
139139
}
140140

@@ -152,7 +152,7 @@ namespace cubool {
152152
});
153153

154154
textLogger->addOnLoggerAction([=](size_t id, Logger::Level level, const std::string& message) {
155-
auto& file = *lofFile;
155+
auto& file = *logFile;
156156

157157
const auto idSize = 10;
158158
const auto levelSize = 20;

cubool/sources/core/vector.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <core/vector.hpp>
2626
#include <core/error.hpp>
27+
#include <core/library.hpp>
28+
#include <io/logger.hpp>
2729

2830
namespace cubool {
2931

@@ -50,19 +52,47 @@ namespace cubool {
5052
}
5153

5254
void Vector::build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) {
53-
RAISE_ERROR(NotImplemented, "This function is not implemented");
55+
CHECK_RAISE_ERROR(rows != nullptr || nvals == 0, InvalidArgument, "Null ptr rows array");
56+
57+
this->releaseCache();
58+
59+
LogStream stream(*Library::getLogger());
60+
stream << Logger::Level::Info
61+
<< "Vector:build:" << this->getDebugMarker() << " "
62+
<< "isSorted=" << isSorted << ", "
63+
<< "noDuplicates=" << noDuplicates << LogStream::cmt;
64+
65+
mHnd->build(rows, nvals, isSorted, noDuplicates);
5466
}
5567

5668
void Vector::extract(index *rows, size_t &nvals) {
57-
RAISE_ERROR(NotImplemented, "This function is not implemented");
69+
CHECK_RAISE_ERROR(rows != nullptr || getNvals() == 0, InvalidArgument, "Null ptr rows array");
70+
CHECK_RAISE_ERROR(getNvals() <= nvals, InvalidArgument, "Passed arrays size must be more or equal to the nvals of the vector");
71+
72+
this->commitCache();
73+
mHnd->extract(rows, nvals);
5874
}
5975

6076
void Vector::extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) {
6177
RAISE_ERROR(NotImplemented, "This function is not implemented");
6278
}
6379

6480
void Vector::clone(const VectorBase &otherBase) {
65-
RAISE_ERROR(NotImplemented, "This function is not implemented");
81+
const auto* other = dynamic_cast<const Vector*>(&otherBase);
82+
83+
CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed vector does not belong to core vector class");
84+
85+
if (this == other)
86+
return;
87+
88+
auto M = other->getNrows();
89+
90+
CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Cloned vector has incompatible size");
91+
92+
other->commitCache();
93+
this->releaseCache(); // Values of this vector won't be used any more
94+
95+
mHnd->clone(*other->mHnd);
6696
}
6797

6898
void Vector::reduce(index &result, bool checkTime) {
@@ -74,19 +104,20 @@ namespace cubool {
74104
}
75105

76106
index Vector::getNrows() const {
77-
RAISE_ERROR(NotImplemented, "This function is not implemented");
107+
return mHnd->getNrows();
78108
}
79109

80110
index Vector::getNvals() const {
81-
RAISE_ERROR(NotImplemented, "This function is not implemented");
111+
this->commitCache();
112+
return mHnd->getNvals();
82113
}
83114

84115
void Vector::releaseCache() const {
85-
RAISE_ERROR(NotImplemented, "This function is not implemented");
116+
mCachedI.clear();
86117
}
87118

88119
void Vector::commitCache() const {
89-
RAISE_ERROR(NotImplemented, "This function is not implemented");
120+
// todo
90121
}
91122

92123
}

cubool/sources/cuda/cuda_matrix_build.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**********************************************************************************/
2424

2525
#include <cuda/cuda_matrix.hpp>
26-
#include <utils/csr_utils.hpp>
26+
#include <utils/data_utils.hpp>
2727

2828
namespace cubool {
2929

@@ -37,7 +37,7 @@ namespace cubool {
3737
std::vector<index> rowOffsets;
3838
std::vector<index> colIndices;
3939

40-
CsrUtils::buildFromData(getNrows(), getNcols(), rows, cols, nvals, rowOffsets, colIndices, isSorted, noDuplicates);
40+
DataUtils::buildFromData(getNrows(), getNcols(), rows, cols, nvals, rowOffsets, colIndices, isSorted, noDuplicates);
4141

4242
// Move actual data to the matrix implementation
4343
this->transferToDevice(rowOffsets, colIndices);

cubool/sources/cuda/cuda_matrix_extract.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**********************************************************************************/
2424

2525
#include <cuda/cuda_matrix.hpp>
26-
#include <utils/csr_utils.hpp>
26+
#include <utils/data_utils.hpp>
2727

2828
namespace cubool {
2929

@@ -40,7 +40,7 @@ namespace cubool {
4040

4141
this->transferFromDevice(rowOffsets, colIndices);
4242

43-
CsrUtils::extractData(getNrows(), getNcols(), rows, cols, nvals, rowOffsets, colIndices);
43+
DataUtils::extractData(getNrows(), getNcols(), rows, cols, nvals, rowOffsets, colIndices);
4444
}
4545
}
4646

cubool/sources/sequential/sq_backend.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <sequential/sq_backend.hpp>
2626
#include <sequential/sq_matrix.hpp>
27+
#include <sequential/sq_vector.hpp>
2728
#include <core/library.hpp>
2829
#include <io/logger.hpp>
2930
#include <cassert>
@@ -54,7 +55,8 @@ namespace cubool {
5455
}
5556

5657
VectorBase* SqBackend::createVector(size_t nrows) {
57-
RAISE_ERROR(NotImplemented, "Not implemented");
58+
mVecCount++;
59+
return new SqVector(nrows);
5860
}
5961

6062
void SqBackend::releaseMatrix(MatrixBase *matrixBase) {
@@ -63,7 +65,8 @@ namespace cubool {
6365
}
6466

6567
void SqBackend::releaseVector(VectorBase *vectorBase) {
66-
RAISE_ERROR(NotImplemented, "Not implemented");
68+
mVecCount--;
69+
delete vectorBase;
6770
}
6871

6972
void SqBackend::queryCapabilities(cuBool_DeviceCaps &caps) {

cubool/sources/sequential/sq_backend.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace cubool {
4949

5050
private:
5151
size_t mMatCount = 0;
52+
size_t mVecCount = 0;
5253
};
5354

5455
}

cubool/sources/sequential/sq_ewiseadd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**********************************************************************************/
2424

2525
#include <sequential/sq_ewiseadd.hpp>
26-
#include <utils/exclusive_scan.hpp>
26+
#include <utils/algo_utils.hpp>
2727

2828
namespace cubool {
2929

cubool/sources/sequential/sq_kronecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**********************************************************************************/
2424

2525
#include <sequential/sq_kronecker.hpp>
26-
#include <utils/exclusive_scan.hpp>
26+
#include <utils/algo_utils.hpp>
2727

2828
namespace cubool {
2929

cubool/sources/sequential/sq_matrix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <sequential/sq_ewiseadd.hpp>
3030
#include <sequential/sq_spgemm.hpp>
3131
#include <sequential/sq_reduce.hpp>
32-
#include <utils/csr_utils.hpp>
32+
#include <utils/data_utils.hpp>
3333
#include <core/error.hpp>
3434
#include <cassert>
3535

@@ -55,7 +55,7 @@ namespace cubool {
5555
mData.colIndices.clear();
5656

5757
// Call utility to build csr row offsets and column indices and store in mData vectors
58-
CsrUtils::buildFromData(nrows, ncols, rows, cols, nvals, mData.rowOffsets, mData.colIndices, isSorted, noDuplicates);
58+
DataUtils::buildFromData(nrows, ncols, rows, cols, nvals, mData.rowOffsets, mData.colIndices, isSorted, noDuplicates);
5959

6060
mData.nvals = mData.colIndices.size();
6161
}
@@ -65,7 +65,7 @@ namespace cubool {
6565
nvals = getNvals();
6666

6767
if (nvals > 0) {
68-
CsrUtils::extractData(getNrows(), getNcols(), rows, cols, nvals, mData.rowOffsets, mData.colIndices);
68+
DataUtils::extractData(getNrows(), getNcols(), rows, cols, nvals, mData.rowOffsets, mData.colIndices);
6969
}
7070
}
7171

0 commit comments

Comments
 (0)