Skip to content

Updated supported CUDA verison to 12.8 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "deps/gtest"]
path = deps/gtest
url = https://github.com/google/googletest.git
[submodule "deps/cub"]
path = deps/cub
url = https://github.com/NVIDIA/cub.git
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ option(CUBOOL_WITH_NAIVE "Build library with naive and naive-shared dens
option(CUBOOL_BUILD_TESTS "Build project unit-tests with gtest" ON)
option(CUBOOL_COPY_TO_PY_PACKAGE "Copy compiled shared library into python package folder (for package use purposes)" ON)

option(CUBOOL_USE_NSPARSE_MERGE_FUNCTOR "Use nsparse optimiztion for matrix addition function" ON)

set(CUBOOL_VERSION_MAJOR 1)
set(CUBOOL_VERSION_MINOR 0)
set(CUBOOL_VERSION_SUB 0)
Expand All @@ -32,14 +34,6 @@ endif()

# Configure cuda dependencies
if (CUBOOL_WITH_CUDA)
message(STATUS "Add cub as cuda utility")
set(CUB_ENABLE_HEADER_TESTING OFF CACHE BOOL "" FORCE)
set(CUB_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(CUB_ENABLE_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(deps/cub)
add_library(cub INTERFACE IMPORTED)
target_link_libraries(cub INTERFACE CUB::CUB)

message(STATUS "Add nsparse library as crs matrix multiplication backend")
add_subdirectory(deps/nsparse-um)
endif()
Expand All @@ -61,4 +55,4 @@ add_subdirectory(cubool)
file(COPY scripts DESTINATION ${CMAKE_BINARY_DIR}/)

# Copy python related stuff
file(COPY python DESTINATION ${CMAKE_BINARY_DIR}/)
file(COPY python DESTINATION ${CMAKE_BINARY_DIR}/)
14 changes: 8 additions & 6 deletions cubool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(CUBOOL_C_API_SOURCES
sources/cuBool_Matrix_Reduce2.cpp
sources/cuBool_Matrix_EWiseAdd.cpp
sources/cuBool_Matrix_EWiseMult.cpp
sources/cuBool_Matrix_EWiseMultInverted.cpp
sources/cuBool_Vector_New.cpp
sources/cuBool_Vector_Build.cpp
sources/cuBool_Vector_SetElement.cpp
Expand Down Expand Up @@ -125,6 +126,7 @@ if (CUBOOL_WITH_CUDA)
sources/cuda/cuda_matrix.cu
sources/cuda/cuda_matrix_ewiseadd.cu
sources/cuda/cuda_matrix_ewisemult.cu
sources/cuda/cuda_matrix_ewisemult_inverted.cu
sources/cuda/cuda_matrix_kronecker.cu
sources/cuda/cuda_matrix_multiply.cu
sources/cuda/cuda_matrix_transpose.cu
Expand All @@ -147,6 +149,7 @@ if (CUBOOL_WITH_CUDA)
sources/cuda/kernels/spgemv_t.cuh
sources/cuda/kernels/spewiseadd.cuh
sources/cuda/kernels/spewisemult.cuh
sources/cuda/kernels/spewisemultinverted.cuh
sources/cuda/kernels/sptranspose.cuh
sources/cuda/kernels/sptranspose2.cuh
sources/cuda/kernels/spkron.cuh
Expand All @@ -173,6 +176,8 @@ if (CUBOOL_WITH_SEQUENTIAL)
sources/sequential/sq_ewiseadd.hpp
sources/sequential/sq_ewisemult.cpp
sources/sequential/sq_ewisemult.hpp
sources/sequential/sq_ewisemultinverted.cpp
sources/sequential/sq_ewisemultinverted.hpp
sources/sequential/sq_spgemm.cpp
sources/sequential/sq_spgemm.hpp
sources/sequential/sq_spgemv.cpp
Expand Down Expand Up @@ -201,11 +206,9 @@ target_compile_definitions(cubool PRIVATE CUBOOL_VERSION_MAJOR=${CUBOOL_VERSION_
target_compile_definitions(cubool PRIVATE CUBOOL_VERSION_MINOR=${CUBOOL_VERSION_MINOR})
target_compile_definitions(cubool PRIVATE CUBOOL_VERSION_SUB=${CUBOOL_VERSION_SUB})

target_compile_features(cubool PUBLIC cxx_std_14)
target_compile_definitions(cubool PRIVATE CUBOOL_USE_NSPARSE_MERGE_FUNCTOR=$<BOOL:${CUBOOL_USE_NSPARSE_MERGE_FUNCTOR}>)

target_compile_options(cubool PRIVATE $<$<COMPILE_LANGUAGE:CXX>: -Wall>)
target_compile_options(cubool PRIVATE $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>: -O2>)
target_compile_options(cubool PRIVATE $<$<AND:$<CONFIG:Release>,$<COMPILE_LANGUAGE:CXX>>: -O0>)
target_compile_features(cubool PUBLIC cxx_std_17)

set_target_properties(cubool PROPERTIES CXX_STANDARD 17)
set_target_properties(cubool PROPERTIES CXX_STANDARD_REQUIRED ON)
Expand All @@ -219,7 +222,6 @@ endforeach()
if (CUBOOL_WITH_CUDA)
set_target_properties(cubool PROPERTIES CUDA_STANDARD 14)
set_target_properties(cubool PROPERTIES CUDA_STANDARD_REQUIRED ON)
set_target_properties(cubool PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

# Settings: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/

Expand Down Expand Up @@ -256,4 +258,4 @@ if (CUBOOL_COPY_TO_PY_PACKAGE)
"${CMAKE_BINARY_DIR}/cubool/${LIBRARY_FILE_NAME}"
"${CMAKE_BINARY_DIR}/python/pycubool"
COMMENT "Copy ${LIBRARY_FILE_NAME} compiled lib into python folder")
endif()
endif()
26 changes: 26 additions & 0 deletions cubool/include/cubool/cubool.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,4 +925,30 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Kronecker(
cuBool_Hints hints
);

/**
* Performs result = left * ~right, where
* '*' is boolean semiring 'and' operation
* '~' is operation for invert matrix (0 swaps to 1 and 1 to 0)
*
* @note To perform this operation matrices must be compatible
* dim(left) = M x T
* dim(right) = T x N
* dim(result) = 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 inverted and multiplied
* @param hints Hints for the operation
*
* @return Error code on this operation
*/
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMulInverted(
cuBool_Matrix result,
cuBool_Matrix matrix,
cuBool_Matrix mask,
cuBool_Hints hints
);

#endif //CUBOOL_CUBOOL_H
3 changes: 2 additions & 1 deletion cubool/sources/backend/matrix_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace cubool {
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 void eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) = 0;

virtual index getNrows() const = 0;
virtual index getNcols() const = 0;
Expand All @@ -59,4 +60,4 @@ namespace cubool {

}

#endif //CUBOOL_MATRIX_BASE_HPP
#endif //CUBOOL_MATRIX_BASE_HPP
42 changes: 41 additions & 1 deletion cubool/sources/core/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,46 @@ namespace cubool {
mHnd->eWiseMult(*a->mHnd, *b->mHnd, false);
}

void Matrix::eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) {

const auto* mat = dynamic_cast<const Matrix*>(&matrix);
const auto* msk = dynamic_cast<const Matrix*>(&mask);

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

index M = mat->getNrows();
index N = msk->getNcols();

CHECK_RAISE_ERROR(M == msk->getNrows(), InvalidArgument, "Passed matrices have incompatible size");
CHECK_RAISE_ERROR(N == msk->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");

mat->commitCache();
msk->commitCache();
this->releaseCache();

if (checkTime) {
TIMER_ACTION(timer, mHnd->eWiseMultInverted(*mat->mHnd, *msk->mHnd, false));

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

return;
}

mHnd->eWiseMultInverted(*mat->mHnd, *msk->mHnd, false);
}



index Matrix::getNrows() const {
return mHnd->getNrows();
}
Expand Down Expand Up @@ -396,4 +436,4 @@ namespace cubool {
// Clear arrays
releaseCache();
}
}
}
3 changes: 2 additions & 1 deletion cubool/sources/core/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace cubool {
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;
void eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) override;

index getNrows() const override;
index getNcols() const override;
Expand All @@ -77,4 +78,4 @@ namespace cubool {

}

#endif //CUBOOL_MATRIX_HPP
#endif //CUBOOL_MATRIX_HPP
44 changes: 44 additions & 0 deletions cubool/sources/cuBool_Matrix_EWiseMultInverted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**********************************************************************************/
/* 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_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMulInverted(
cuBool_Matrix result,
cuBool_Matrix matrix,
cuBool_Matrix mask,
cuBool_Hints hints
) {
CUBOOL_BEGIN_BODY
CUBOOL_VALIDATE_LIBRARY
CUBOOL_ARG_NOT_NULL(result)
CUBOOL_ARG_NOT_NULL(matrix)
CUBOOL_ARG_NOT_NULL(mask)
auto resultM = (cubool::Matrix *) result;
auto matrixM = (cubool::Matrix *) matrix;
auto maskM = (cubool::Matrix *) mask;

resultM->eWiseMultInverted(*matrixM, *maskM, hints & CUBOOL_HINT_TIME_CHECK);
CUBOOL_END_BODY
}
3 changes: 2 additions & 1 deletion cubool/sources/cuda/cuda_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace cubool {
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;
void eWiseMultInverted(const MatrixBase &a, const MatrixBase &b, bool checkTime) override;

index getNrows() const override;
index getNcols() const override;
Expand All @@ -79,4 +80,4 @@ namespace cubool {
};
};

#endif //CUBOOL_CUDA_MATRIX_HPP
#endif //CUBOOL_CUDA_MATRIX_HPP
63 changes: 63 additions & 0 deletions cubool/sources/cuda/cuda_matrix_ewisemult_inverted.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**********************************************************************************/
/* 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 <cuda/cuda_matrix.hpp>
#include <cuda/kernels/spewisemultinverted.cuh>

namespace cubool {

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

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

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


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

assert(b->getNrows() == M);
assert(b->getNcols() == N);

if (a->isMatrixEmpty() || b->isMatrixEmpty()) {
this->clearAndResizeStorageToDim();
return;
}

// Ensure csr proper csr format even if empty
a->resizeStorageToDim();
b->resizeStorageToDim();

kernels::SpVectorEWiseMultInverted<index, DeviceAlloc<index>> spFunctor;
auto result = spFunctor(a->mMatrixImpl, b->mMatrixImpl);

// Assign the actual impl result to this storage
this->mMatrixImpl = std::move(result);
}

}
2 changes: 2 additions & 0 deletions cubool/sources/cuda/cuda_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <utils/data_utils.hpp>
#include <limits>

#include <thrust/sort.h>

namespace cubool {

CudaVector::CudaVector(size_t nrows, CudaInstance &instance)
Expand Down
2 changes: 2 additions & 0 deletions cubool/sources/cuda/kernels/spewiseadd.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <cuda/details/sp_vector.hpp>

#include <thrust/set_operations.h>

namespace cubool {
namespace kernels {

Expand Down
2 changes: 2 additions & 0 deletions cubool/sources/cuda/kernels/spewisemult.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <nsparse/matrix.h>
#include <cmath>

#include <thrust/set_operations.h>

namespace cubool {
namespace kernels {

Expand Down
Loading