Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ prototyping algorithms on a local computer for later running on a powerful serve
- Cuda backend for computations
- Cpu backend for computations
- Matrix/vector creation (empty, from data, with random data)
- Matrix-matrix operations (multiplication, element-wise addition, kronecker product)
- Matrix-matrix operations (multiplication, element-wise addition, element-wise multiplication, kronecker product)
- Matrix-vector operations (matrix-vector and vector-matrix multiplication)
- Vector-vector operations (element-wise addition)
- Vector-vector operations (element-wise addition, element-wise multiplication)
- Matrix operations (equality, transpose, reduce to vector, extract sub-matrix)
- Vector operations (equality, reduce to value, extract sub-vector)
- Matrix/vector data extraction (as lists, as list of pairs)
Expand Down Expand Up @@ -367,7 +367,7 @@ cuBool
title = {cuBool: sparse Boolean linear algebra for Nvidia Cuda},
year = 2021,
url = {https://github.com/JetBrains-Research/cuBool},
note = {Version 1.1.0}
note = {Version 1.2.0}
}
```

Expand Down
7 changes: 7 additions & 0 deletions cubool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(CUBOOL_C_API_SOURCES
sources/cuBool_Matrix_Reduce.cpp
sources/cuBool_Matrix_Reduce2.cpp
sources/cuBool_Matrix_EWiseAdd.cpp
sources/cuBool_Matrix_EWiseMult.cpp
sources/cuBool_Vector_New.cpp
sources/cuBool_Vector_Build.cpp
sources/cuBool_Vector_SetElement.cpp
Expand All @@ -99,6 +100,7 @@ set(CUBOOL_C_API_SOURCES
sources/cuBool_Vector_Free.cpp
sources/cuBool_Vector_Reduce.cpp
sources/cuBool_Vector_EWiseAdd.cpp
sources/cuBool_Vector_EWiseMult.cpp
sources/cuBool_MxM.cpp
sources/cuBool_MxV.cpp
sources/cuBool_VxM.cpp
Expand All @@ -122,6 +124,7 @@ if (CUBOOL_WITH_CUDA)
sources/cuda/cuda_matrix.hpp
sources/cuda/cuda_matrix.cu
sources/cuda/cuda_matrix_ewiseadd.cu
sources/cuda/cuda_matrix_ewisemult.cu
sources/cuda/cuda_matrix_kronecker.cu
sources/cuda/cuda_matrix_multiply.cu
sources/cuda/cuda_matrix_transpose.cu
Expand All @@ -132,6 +135,7 @@ if (CUBOOL_WITH_CUDA)
sources/cuda/cuda_vector_mxv.cu
sources/cuda/cuda_vector_vxm.cu
sources/cuda/cuda_vector_ewiseadd.cu
sources/cuda/cuda_vector_ewisemult.cu
sources/cuda/cuda_vector_reduce.cu
sources/cuda/details/meta.hpp
sources/cuda/details/sp_vector.hpp
Expand All @@ -142,6 +146,7 @@ if (CUBOOL_WITH_CUDA)
sources/cuda/kernels/spgemv.cuh
sources/cuda/kernels/spgemv_t.cuh
sources/cuda/kernels/spewiseadd.cuh
sources/cuda/kernels/spewisemult.cuh
sources/cuda/kernels/sptranspose.cuh
sources/cuda/kernels/sptranspose2.cuh
sources/cuda/kernels/spkron.cuh
Expand All @@ -166,6 +171,8 @@ if (CUBOOL_WITH_SEQUENTIAL)
sources/sequential/sq_kronecker.hpp
sources/sequential/sq_ewiseadd.cpp
sources/sequential/sq_ewiseadd.hpp
sources/sequential/sq_ewisemult.cpp
sources/sequential/sq_ewisemult.hpp
sources/sequential/sq_spgemm.cpp
sources/sequential/sq_spgemm.hpp
sources/sequential/sq_spgemv.cpp
Expand Down
60 changes: 54 additions & 6 deletions cubool/include/cubool/cubool.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce2(
);

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

/**
* Performs result = left * right, where '*' is boolean semiring 'and' operation.
*
* @note Matrices must be compatible
* dim(result) = M x N
* dim(left) = M x N
* dim(right) = M x N
*
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
*
* @param result[out] Destination matrix to store result
* @param left Source matrix to be multiplied
* @param right Source matrix to be multiplied
* @param hints Hints for the operation
*
* @return Error code on this operation
*/
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMult(
cuBool_Matrix result,
cuBool_Matrix left,
cuBool_Matrix right,
cuBool_Hints hints
);

/**
* Creates new sparse vector with specified size.
*
Expand Down Expand Up @@ -754,7 +778,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce(
);

/**
* Performs result = left + right, where '+' is boolean semiring operation.
* Performs result = left + right, where '+' is boolean semiring 'or' operation.
*
* @note Matrices must be compatible
* dim(result) = M
Expand All @@ -771,10 +795,34 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce(
* @return Error code on this operation
*/
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseAdd(
cuBool_Vector result,
cuBool_Vector left,
cuBool_Vector right,
cuBool_Hints hints
cuBool_Vector result,
cuBool_Vector left,
cuBool_Vector right,
cuBool_Hints hints
);

/**
* Performs result = left * right, where '*' is boolean semiring 'and' operation.
*
* @note Matrices must be compatible
* dim(result) = M
* dim(left) = M
* dim(right) = M
*
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
*
* @param result[out]Destination vector to store result
* @param left Source vector to be multiplied
* @param right Source vector to be multiplied
* @param hints Hints for the operation
*
* @return Error code on this operation
*/
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseMult(
cuBool_Vector result,
cuBool_Vector left,
cuBool_Vector right,
cuBool_Hints hints
);

/**
Expand Down
1 change: 1 addition & 0 deletions cubool/sources/backend/matrix_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace cubool {
virtual void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) = 0;
virtual void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
virtual void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
virtual void eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;

virtual index getNrows() const = 0;
virtual index getNcols() const = 0;
Expand Down
1 change: 1 addition & 0 deletions cubool/sources/backend/vector_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace cubool {
virtual void reduce(index &result, bool checkTime) = 0;
virtual void reduceMatrix(const class MatrixBase& matrix, bool transpose, bool checkTime) = 0;

virtual void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0;
virtual void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0;
virtual void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) = 0;
virtual void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) = 0;
Expand Down
37 changes: 37 additions & 0 deletions cubool/sources/core/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,43 @@ namespace cubool {
mHnd->eWiseAdd(*a->mHnd, *b->mHnd, false);
}

void Matrix::eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) {
const auto* a = dynamic_cast<const Matrix*>(&aBase);
const auto* b = dynamic_cast<const Matrix*>(&bBase);

CHECK_RAISE_ERROR(a != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class");
CHECK_RAISE_ERROR(b != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class");

index M = a->getNrows();
index N = a->getNcols();

CHECK_RAISE_ERROR(M == b->getNrows(), InvalidArgument, "Passed matrices have incompatible size");
CHECK_RAISE_ERROR(N == b->getNcols(), InvalidArgument, "Passed matrices have incompatible size");

CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Matrix has incompatible size for operation result");
CHECK_RAISE_ERROR(N == this->getNcols(), InvalidArgument, "Matrix has incompatible size for operation result");

a->commitCache();
b->commitCache();
this->releaseCache();

if (checkTime) {
TIMER_ACTION(timer, mHnd->eWiseMult(*a->mHnd, *b->mHnd, false));

LogStream stream(*Library::getLogger());
stream << Logger::Level::Info
<< "Time: " << timer.getElapsedTimeMs() << " ms "
<< "Matrix::eWiseMult: "
<< this->getDebugMarker() << " = "
<< a->getDebugMarker() << " + "
<< b->getDebugMarker() << LogStream::cmt;

return;
}

mHnd->eWiseMult(*a->mHnd, *b->mHnd, false);
}

index Matrix::getNrows() const {
return mHnd->getNrows();
}
Expand Down
1 change: 1 addition & 0 deletions cubool/sources/core/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace cubool {
void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) override;
void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override;
void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override;
void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;

index getNrows() const override;
index getNcols() const override;
Expand Down
33 changes: 33 additions & 0 deletions cubool/sources/core/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ namespace cubool {
mHnd->reduceMatrix(*matrix->mHnd, transpose, false);
}

void Vector::eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) {
const auto* a = dynamic_cast<const Vector*>(&aBase);
const auto* b = dynamic_cast<const Vector*>(&bBase);

CHECK_RAISE_ERROR(a != nullptr, InvalidArgument, "Passed vector does not belong to core vector class");
CHECK_RAISE_ERROR(b != nullptr, InvalidArgument, "Passed vector does not belong to core vector class");

index M = a->getNrows();

CHECK_RAISE_ERROR(M == b->getNrows(), InvalidArgument, "Passed vectors have incompatible size");
CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Vector has incompatible size for operation result");

a->commitCache();
b->commitCache();
this->releaseCache();

if (checkTime) {
TIMER_ACTION(timer, mHnd->eWiseMult(*a->mHnd, *b->mHnd, false));

LogStream stream(*Library::getLogger());
stream << Logger::Level::Info
<< "Time: " << timer.getElapsedTimeMs() << " ms "
<< "Vector::eWiseMult: "
<< this->getDebugMarker() << " = "
<< a->getDebugMarker() << " & "
<< b->getDebugMarker() << LogStream::cmt;

return;
}

mHnd->eWiseMult(*a->mHnd, *b->mHnd, false);
}

void Vector::eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) {
const auto* a = dynamic_cast<const Vector*>(&aBase);
const auto* b = dynamic_cast<const Vector*>(&bBase);
Expand Down
1 change: 1 addition & 0 deletions cubool/sources/core/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace cubool {
void reduce(index &result, bool checkTime) override;
void reduceMatrix(const MatrixBase &matrix, bool transpose, bool checkTime) override;

void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override;
void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override;
void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) override;
void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) override;
Expand Down
43 changes: 43 additions & 0 deletions cubool/sources/cuBool_Matrix_EWiseMult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2020, 2021 JetBrains-Research */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in all */
/* copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/**********************************************************************************/

#include <cuBool_Common.hpp>

cuBool_Status cuBool_Matrix_EWiseMult(
cuBool_Matrix result,
cuBool_Matrix left,
cuBool_Matrix right,
cuBool_Hints hints
) {
CUBOOL_BEGIN_BODY
CUBOOL_VALIDATE_LIBRARY
CUBOOL_ARG_NOT_NULL(result)
CUBOOL_ARG_NOT_NULL(left)
CUBOOL_ARG_NOT_NULL(right)
auto resultM = (cubool::Matrix *) result;
auto leftM = (cubool::Matrix *) left;
auto rightM = (cubool::Matrix *) right;
resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK);
CUBOOL_END_BODY
}
43 changes: 43 additions & 0 deletions cubool/sources/cuBool_Vector_EWiseMult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2020, 2021 JetBrains-Research */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in all */
/* copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/**********************************************************************************/

#include <cuBool_Common.hpp>

cuBool_Status cuBool_Vector_EWiseMult(
cuBool_Vector result,
cuBool_Vector left,
cuBool_Vector right,
cuBool_Hints hints
) {
CUBOOL_BEGIN_BODY
CUBOOL_VALIDATE_LIBRARY
CUBOOL_ARG_NOT_NULL(result)
CUBOOL_ARG_NOT_NULL(left)
CUBOOL_ARG_NOT_NULL(right)
auto resultM = (cubool::Vector *) result;
auto leftM = (cubool::Vector *) left;
auto rightM = (cubool::Vector *) right;
resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK);
CUBOOL_END_BODY
}
1 change: 1 addition & 0 deletions cubool/sources/cuda/cuda_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace cubool {
void multiply(const MatrixBase &a, const MatrixBase &b, bool accumulate, bool checkTime) override;
void kronecker(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;
void eWiseAdd(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;
void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;

index getNrows() const override;
index getNcols() const override;
Expand Down
Loading