Skip to content

Commit d1d2f80

Browse files
committed
[Code] Add ewisemult func setup
1 parent 1725c14 commit d1d2f80

21 files changed

+400
-6
lines changed

cubool/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ set(CUBOOL_C_API_SOURCES
8686
sources/cuBool_Matrix_Reduce.cpp
8787
sources/cuBool_Matrix_Reduce2.cpp
8888
sources/cuBool_Matrix_EWiseAdd.cpp
89+
sources/cuBool_Matrix_EWiseMult.cpp
8990
sources/cuBool_Vector_New.cpp
9091
sources/cuBool_Vector_Build.cpp
9192
sources/cuBool_Vector_SetElement.cpp
@@ -99,6 +100,7 @@ set(CUBOOL_C_API_SOURCES
99100
sources/cuBool_Vector_Free.cpp
100101
sources/cuBool_Vector_Reduce.cpp
101102
sources/cuBool_Vector_EWiseAdd.cpp
103+
sources/cuBool_Vector_EWiseMult.cpp
102104
sources/cuBool_MxM.cpp
103105
sources/cuBool_MxV.cpp
104106
sources/cuBool_VxM.cpp
@@ -122,6 +124,7 @@ if (CUBOOL_WITH_CUDA)
122124
sources/cuda/cuda_matrix.hpp
123125
sources/cuda/cuda_matrix.cu
124126
sources/cuda/cuda_matrix_ewiseadd.cu
127+
sources/cuda/cuda_matrix_ewisemult.cu
125128
sources/cuda/cuda_matrix_kronecker.cu
126129
sources/cuda/cuda_matrix_multiply.cu
127130
sources/cuda/cuda_matrix_transpose.cu
@@ -132,6 +135,7 @@ if (CUBOOL_WITH_CUDA)
132135
sources/cuda/cuda_vector_mxv.cu
133136
sources/cuda/cuda_vector_vxm.cu
134137
sources/cuda/cuda_vector_ewiseadd.cu
138+
sources/cuda/cuda_vector_ewisemult.cu
135139
sources/cuda/cuda_vector_reduce.cu
136140
sources/cuda/details/meta.hpp
137141
sources/cuda/details/sp_vector.hpp
@@ -142,6 +146,7 @@ if (CUBOOL_WITH_CUDA)
142146
sources/cuda/kernels/spgemv.cuh
143147
sources/cuda/kernels/spgemv_t.cuh
144148
sources/cuda/kernels/spewiseadd.cuh
149+
sources/cuda/kernels/spewisemult.cuh
145150
sources/cuda/kernels/sptranspose.cuh
146151
sources/cuda/kernels/sptranspose2.cuh
147152
sources/cuda/kernels/spkron.cuh
@@ -166,6 +171,8 @@ if (CUBOOL_WITH_SEQUENTIAL)
166171
sources/sequential/sq_kronecker.hpp
167172
sources/sequential/sq_ewiseadd.cpp
168173
sources/sequential/sq_ewiseadd.hpp
174+
sources/sequential/sq_ewisemult.cpp
175+
sources/sequential/sq_ewisemult.hpp
169176
sources/sequential/sq_spgemm.cpp
170177
sources/sequential/sq_spgemm.hpp
171178
sources/sequential/sq_spgemv.cpp

cubool/include/cubool/cubool.h

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce2(
531531
);
532532

533533
/**
534-
* Performs result = left + right, where '+' is boolean semiring operation.
534+
* Performs result = left + right, where '+' is boolean semiring 'or' operation.
535535
*
536536
* @note Matrices must be compatible
537537
* dim(result) = M x N
@@ -554,6 +554,30 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd(
554554
cuBool_Hints hints
555555
);
556556

557+
/**
558+
* Performs result = left * right, where '*' is boolean semiring 'and' operation.
559+
*
560+
* @note Matrices must be compatible
561+
* dim(result) = M x N
562+
* dim(left) = M x N
563+
* dim(right) = M x N
564+
*
565+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
566+
*
567+
* @param result[out] Destination matrix to store result
568+
* @param left Source matrix to be multiplied
569+
* @param right Source matrix to be multiplied
570+
* @param hints Hints for the operation
571+
*
572+
* @return Error code on this operation
573+
*/
574+
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMult(
575+
cuBool_Matrix result,
576+
cuBool_Matrix left,
577+
cuBool_Matrix right,
578+
cuBool_Hints hints
579+
);
580+
557581
/**
558582
* Creates new sparse vector with specified size.
559583
*
@@ -754,7 +778,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce(
754778
);
755779

756780
/**
757-
* Performs result = left + right, where '+' is boolean semiring operation.
781+
* Performs result = left + right, where '+' is boolean semiring 'or' operation.
758782
*
759783
* @note Matrices must be compatible
760784
* dim(result) = M
@@ -771,10 +795,34 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce(
771795
* @return Error code on this operation
772796
*/
773797
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseAdd(
774-
cuBool_Vector result,
775-
cuBool_Vector left,
776-
cuBool_Vector right,
777-
cuBool_Hints hints
798+
cuBool_Vector result,
799+
cuBool_Vector left,
800+
cuBool_Vector right,
801+
cuBool_Hints hints
802+
);
803+
804+
/**
805+
* Performs result = left * right, where '*' is boolean semiring 'and' operation.
806+
*
807+
* @note Matrices must be compatible
808+
* dim(result) = M
809+
* dim(left) = M
810+
* dim(right) = M
811+
*
812+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
813+
*
814+
* @param result[out]Destination vector to store result
815+
* @param left Source vector to be multiplied
816+
* @param right Source vector to be multiplied
817+
* @param hints Hints for the operation
818+
*
819+
* @return Error code on this operation
820+
*/
821+
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseMult(
822+
cuBool_Vector result,
823+
cuBool_Vector left,
824+
cuBool_Vector right,
825+
cuBool_Hints hints
778826
);
779827

780828
/**

cubool/sources/backend/matrix_base.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace cubool {
4848
virtual void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) = 0;
4949
virtual void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
5050
virtual void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
51+
virtual void eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
5152

5253
virtual index getNrows() const = 0;
5354
virtual index getNcols() const = 0;

cubool/sources/backend/vector_base.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace cubool {
4747
virtual void reduce(index &result, bool checkTime) = 0;
4848
virtual void reduceMatrix(const class MatrixBase& matrix, bool transpose, bool checkTime) = 0;
4949

50+
virtual void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0;
5051
virtual void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0;
5152
virtual void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) = 0;
5253
virtual void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) = 0;

cubool/sources/core/matrix.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,43 @@ namespace cubool {
312312
mHnd->eWiseAdd(*a->mHnd, *b->mHnd, false);
313313
}
314314

315+
void Matrix::eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) {
316+
const auto* a = dynamic_cast<const Matrix*>(&aBase);
317+
const auto* b = dynamic_cast<const Matrix*>(&bBase);
318+
319+
CHECK_RAISE_ERROR(a != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class");
320+
CHECK_RAISE_ERROR(b != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class");
321+
322+
index M = a->getNrows();
323+
index N = a->getNcols();
324+
325+
CHECK_RAISE_ERROR(M == b->getNrows(), InvalidArgument, "Passed matrices have incompatible size");
326+
CHECK_RAISE_ERROR(N == b->getNcols(), InvalidArgument, "Passed matrices have incompatible size");
327+
328+
CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Matrix has incompatible size for operation result");
329+
CHECK_RAISE_ERROR(N == this->getNcols(), InvalidArgument, "Matrix has incompatible size for operation result");
330+
331+
a->commitCache();
332+
b->commitCache();
333+
this->releaseCache();
334+
335+
if (checkTime) {
336+
TIMER_ACTION(timer, mHnd->eWiseMult(*a->mHnd, *b->mHnd, false));
337+
338+
LogStream stream(*Library::getLogger());
339+
stream << Logger::Level::Info
340+
<< "Time: " << timer.getElapsedTimeMs() << " ms "
341+
<< "Matrix::eWiseMult: "
342+
<< this->getDebugMarker() << " = "
343+
<< a->getDebugMarker() << " + "
344+
<< b->getDebugMarker() << LogStream::cmt;
345+
346+
return;
347+
}
348+
349+
mHnd->eWiseMult(*a->mHnd, *b->mHnd, false);
350+
}
351+
315352
index Matrix::getNrows() const {
316353
return mHnd->getNrows();
317354
}

cubool/sources/core/matrix.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace cubool {
5555
void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) override;
5656
void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override;
5757
void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override;
58+
void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;
5859

5960
index getNrows() const override;
6061
index getNcols() const override;

cubool/sources/core/vector.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,39 @@ namespace cubool {
203203
mHnd->reduceMatrix(*matrix->mHnd, transpose, false);
204204
}
205205

206+
void Vector::eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) {
207+
const auto* a = dynamic_cast<const Vector*>(&aBase);
208+
const auto* b = dynamic_cast<const Vector*>(&bBase);
209+
210+
CHECK_RAISE_ERROR(a != nullptr, InvalidArgument, "Passed vector does not belong to core vector class");
211+
CHECK_RAISE_ERROR(b != nullptr, InvalidArgument, "Passed vector does not belong to core vector class");
212+
213+
index M = a->getNrows();
214+
215+
CHECK_RAISE_ERROR(M == b->getNrows(), InvalidArgument, "Passed vectors have incompatible size");
216+
CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Vector has incompatible size for operation result");
217+
218+
a->commitCache();
219+
b->commitCache();
220+
this->releaseCache();
221+
222+
if (checkTime) {
223+
TIMER_ACTION(timer, mHnd->eWiseMult(*a->mHnd, *b->mHnd, false));
224+
225+
LogStream stream(*Library::getLogger());
226+
stream << Logger::Level::Info
227+
<< "Time: " << timer.getElapsedTimeMs() << " ms "
228+
<< "Vector::eWiseMult: "
229+
<< this->getDebugMarker() << " = "
230+
<< a->getDebugMarker() << " & "
231+
<< b->getDebugMarker() << LogStream::cmt;
232+
233+
return;
234+
}
235+
236+
mHnd->eWiseMult(*a->mHnd, *b->mHnd, false);
237+
}
238+
206239
void Vector::eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) {
207240
const auto* a = dynamic_cast<const Vector*>(&aBase);
208241
const auto* b = dynamic_cast<const Vector*>(&bBase);

cubool/sources/core/vector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace cubool {
5050
void reduce(index &result, bool checkTime) override;
5151
void reduceMatrix(const MatrixBase &matrix, bool transpose, bool checkTime) override;
5252

53+
void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override;
5354
void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override;
5455
void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) override;
5556
void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) override;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**********************************************************************************/
2+
/* MIT License */
3+
/* */
4+
/* Copyright (c) 2020, 2021 JetBrains-Research */
5+
/* */
6+
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
7+
/* of this software and associated documentation files (the "Software"), to deal */
8+
/* in the Software without restriction, including without limitation the rights */
9+
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
10+
/* copies of the Software, and to permit persons to whom the Software is */
11+
/* furnished to do so, subject to the following conditions: */
12+
/* */
13+
/* The above copyright notice and this permission notice shall be included in all */
14+
/* copies or substantial portions of the Software. */
15+
/* */
16+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
17+
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
18+
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
19+
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
20+
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
21+
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
22+
/* SOFTWARE. */
23+
/**********************************************************************************/
24+
25+
#include <cuBool_Common.hpp>
26+
27+
cuBool_Status cuBool_Matrix_EWiseMult(
28+
cuBool_Matrix result,
29+
cuBool_Matrix left,
30+
cuBool_Matrix right,
31+
cuBool_Hints hints
32+
) {
33+
CUBOOL_BEGIN_BODY
34+
CUBOOL_VALIDATE_LIBRARY
35+
CUBOOL_ARG_NOT_NULL(result)
36+
CUBOOL_ARG_NOT_NULL(left)
37+
CUBOOL_ARG_NOT_NULL(right)
38+
auto resultM = (cubool::Matrix *) result;
39+
auto leftM = (cubool::Matrix *) left;
40+
auto rightM = (cubool::Matrix *) right;
41+
resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK);
42+
CUBOOL_END_BODY
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**********************************************************************************/
2+
/* MIT License */
3+
/* */
4+
/* Copyright (c) 2020, 2021 JetBrains-Research */
5+
/* */
6+
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
7+
/* of this software and associated documentation files (the "Software"), to deal */
8+
/* in the Software without restriction, including without limitation the rights */
9+
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
10+
/* copies of the Software, and to permit persons to whom the Software is */
11+
/* furnished to do so, subject to the following conditions: */
12+
/* */
13+
/* The above copyright notice and this permission notice shall be included in all */
14+
/* copies or substantial portions of the Software. */
15+
/* */
16+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
17+
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
18+
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
19+
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
20+
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
21+
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
22+
/* SOFTWARE. */
23+
/**********************************************************************************/
24+
25+
#include <cuBool_Common.hpp>
26+
27+
cuBool_Status cuBool_Vector_EWiseMult(
28+
cuBool_Vector result,
29+
cuBool_Vector left,
30+
cuBool_Vector right,
31+
cuBool_Hints hints
32+
) {
33+
CUBOOL_BEGIN_BODY
34+
CUBOOL_VALIDATE_LIBRARY
35+
CUBOOL_ARG_NOT_NULL(result)
36+
CUBOOL_ARG_NOT_NULL(left)
37+
CUBOOL_ARG_NOT_NULL(right)
38+
auto resultM = (cubool::Vector *) result;
39+
auto leftM = (cubool::Vector *) left;
40+
auto rightM = (cubool::Vector *) right;
41+
resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK);
42+
CUBOOL_END_BODY
43+
}

0 commit comments

Comments
 (0)