Skip to content
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

Moving cusparse wrappers to detail API in RAFT. #4547

Merged
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
1 change: 0 additions & 1 deletion cpp/src/common/cumlHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <raft/linalg/detail/cusolver_wrappers.hpp>
#include <raft/mr/device/allocator.hpp>
#include <raft/mr/host/allocator.hpp>
#include <raft/sparse/cusparse_wrappers.h>

namespace ML {

Expand Down
64 changes: 33 additions & 31 deletions cpp/src/glm/qn/simple_mat/sparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
#include <raft/cuda_utils.cuh>
#include <raft/cudart_utils.h>
#include <raft/handle.hpp>

#include <raft/linalg/add.hpp>
#include <raft/linalg/map_then_reduce.hpp>
#include <raft/linalg/norm.hpp>
#include <raft/linalg/unary_op.hpp>
#include <raft/mr/device/allocator.hpp>
#include <raft/sparse/detail/cusparse_wrappers.h>
#include <rmm/device_uvector.hpp>

namespace ML {
Expand Down Expand Up @@ -94,7 +96,7 @@ struct SimpleSparseMat : SimpleMat<T> {
// to swap arguments A and B in cusparseSpMM.
cusparseDnMatDescr_t descrC;
auto order = C.ord == COL_MAJOR ? CUSPARSE_ORDER_ROW : CUSPARSE_ORDER_COL;
RAFT_CUSPARSE_TRY(raft::sparse::cusparsecreatednmat(
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsecreatednmat(
&descrC, C.n, C.m, order == CUSPARSE_ORDER_COL ? C.n : C.m, C.data, order));

/*
Expand All @@ -115,49 +117,49 @@ struct SimpleSparseMat : SimpleMat<T> {
ldX' - leading dimension - m or n, depending on order and transX
*/
cusparseDnMatDescr_t descrA;
RAFT_CUSPARSE_TRY(raft::sparse::cusparsecreatednmat(&descrA,
C.ord == A.ord ? A.n : A.m,
C.ord == A.ord ? A.m : A.n,
A.ord == COL_MAJOR ? A.m : A.n,
A.data,
order));
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsecreatednmat(&descrA,
C.ord == A.ord ? A.n : A.m,
C.ord == A.ord ? A.m : A.n,
A.ord == COL_MAJOR ? A.m : A.n,
A.data,
order));
auto opA =
transA ^ (C.ord == A.ord) ? CUSPARSE_OPERATION_NON_TRANSPOSE : CUSPARSE_OPERATION_TRANSPOSE;

cusparseSpMatDescr_t descrB;
RAFT_CUSPARSE_TRY(
raft::sparse::cusparsecreatecsr(&descrB, B.m, B.n, B.nnz, B.row_ids, B.cols, B.values));
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsecreatecsr(
&descrB, B.m, B.n, B.nnz, B.row_ids, B.cols, B.values));
auto opB = transB ? CUSPARSE_OPERATION_NON_TRANSPOSE : CUSPARSE_OPERATION_TRANSPOSE;

auto alg = order == CUSPARSE_ORDER_COL ? CUSPARSE_SPMM_CSR_ALG1 : CUSPARSE_SPMM_CSR_ALG2;

size_t bufferSize;
RAFT_CUSPARSE_TRY(raft::sparse::cusparsespmm_bufferSize(handle.get_cusparse_handle(),
opB,
opA,
&alpha,
descrB,
descrA,
&beta,
descrC,
alg,
&bufferSize,
stream));
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsespmm_bufferSize(handle.get_cusparse_handle(),
opB,
opA,
&alpha,
descrB,
descrA,
&beta,
descrC,
alg,
&bufferSize,
stream));

RAFT_CUDA_TRY(cudaStreamSynchronize(stream));
rmm::device_uvector<T> tmp(bufferSize, stream);

RAFT_CUSPARSE_TRY(raft::sparse::cusparsespmm(handle.get_cusparse_handle(),
opB,
opA,
&alpha,
descrB,
descrA,
&beta,
descrC,
alg,
tmp.data(),
stream));
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsespmm(handle.get_cusparse_handle(),
opB,
opA,
&alpha,
descrB,
descrA,
&beta,
descrC,
alg,
tmp.data(),
stream));

RAFT_CUSPARSE_TRY(cusparseDestroyDnMat(descrA));
RAFT_CUSPARSE_TRY(cusparseDestroySpMat(descrB));
Expand Down
37 changes: 20 additions & 17 deletions cpp/src/random_projection/rproj.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

#include <raft/cuda_utils.cuh>
#include <raft/cudart_utils.h>

// TODO: This needs to be removed.
#include <raft/sparse/detail/cusparse_wrappers.h>
// #TODO: Replace with public header when ready
#include <raft/linalg/detail/cublas_wrappers.hpp>
#include <raft/sparse/cusparse_wrappers.h>

#include <cstddef>
#include <random>
Expand Down Expand Up @@ -181,7 +183,7 @@ void RPROJtransform(const raft::handle_t& handle,
stream));

} else if (random_matrix->type == sparse) {
cusparseHandle_t cusparse_handle = handle.get_cusparse_handle();
auto cusparse_handle = handle.get_cusparse_handle();

const math_t alfa = 1;
const math_t beta = 0;
Expand All @@ -194,21 +196,22 @@ void RPROJtransform(const raft::handle_t& handle,
auto& lda = m;
auto& ldc = m;

RAFT_CUSPARSE_TRY(raft::sparse::cusparsegemmi(cusparse_handle,
m,
n,
k,
nnz,
&alfa,
input,
lda,
random_matrix->sparse_data.data(),
random_matrix->indptr.data(),
random_matrix->indices.data(),
&beta,
output,
ldc,
stream));
// TODO: Need to wrap this in a RAFT public API.
RAFT_CUSPARSE_TRY(raft::sparse::detail::cusparsegemmi(cusparse_handle,
m,
n,
k,
nnz,
&alfa,
input,
lda,
random_matrix->sparse_data.data(),
random_matrix->indptr.data(),
random_matrix->indices.data(),
&beta,
output,
ldc,
stream));
} else {
ASSERT(false,
"Could not find a random matrix. Please perform a fit operation "
Expand Down
1 change: 0 additions & 1 deletion cpp/src/umap/knn_graph/algo.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <raft/cudart_utils.h>

#include <raft/error.hpp>
#include <raft/sparse/cusparse_wrappers.h>

namespace UMAPAlgo {
namespace kNNGraph {
Expand Down