Skip to content

Commit

Permalink
cugraph sparse updates
Browse files Browse the repository at this point in the history
  • Loading branch information
divyegala committed Feb 12, 2025
1 parent 9345860 commit fb48043
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
25 changes: 15 additions & 10 deletions cpp/include/raft/spectral/detail/modularity_maximization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ namespace detail {
* performed.
* @return error flag.
*/
template <typename vertex_t, typename weight_t, typename EigenSolver, typename ClusterSolver>
template <typename vertex_t,
typename weight_t,
typename nnz_t,
typename EigenSolver,
typename ClusterSolver>
std::tuple<vertex_t, weight_t, vertex_t> modularity_maximization(
raft::resources const& handle,
raft::spectral::matrix::sparse_matrix_t<vertex_t, weight_t> const& csr_m,
raft::spectral::matrix::sparse_matrix_t<vertex_t, weight_t, nnz_t> const& csr_m,
EigenSolver const& eigen_solver,
ClusterSolver const& cluster_solver,
vertex_t* __restrict__ clusters,
Expand All @@ -89,7 +93,7 @@ std::tuple<vertex_t, weight_t, vertex_t> modularity_maximization(
// Compute eigenvectors of Modularity Matrix

// Initialize Modularity Matrix
raft::spectral::matrix::modularity_matrix_t<vertex_t, weight_t> B{handle, csr_m};
raft::spectral::matrix::modularity_matrix_t<vertex_t, weight_t, nnz_t> B{handle, csr_m};

auto eigen_config = eigen_solver.get_config();
auto nEigVecs = eigen_config.n_eigVecs;
Expand Down Expand Up @@ -125,12 +129,13 @@ std::tuple<vertex_t, weight_t, vertex_t> modularity_maximization(
* @param clusters (Input, device memory, n entries) Cluster assignments.
* @param modularity On exit, modularity
*/
template <typename vertex_t, typename weight_t>
void analyzeModularity(raft::resources const& handle,
raft::spectral::matrix::sparse_matrix_t<vertex_t, weight_t> const& csr_m,
vertex_t nClusters,
vertex_t const* __restrict__ clusters,
weight_t& modularity)
template <typename vertex_t, typename weight_t, typename nnz_t>
void analyzeModularity(
raft::resources const& handle,
raft::spectral::matrix::sparse_matrix_t<vertex_t, weight_t, nnz_t> const& csr_m,
vertex_t nClusters,
vertex_t const* __restrict__ clusters,
weight_t& modularity)
{
RAFT_EXPECTS(clusters != nullptr, "Null clusters buffer.");

Expand All @@ -149,7 +154,7 @@ void analyzeModularity(raft::resources const& handle,
RAFT_CUBLAS_TRY(linalg::detail::cublassetpointermode(cublas_h, CUBLAS_POINTER_MODE_HOST, stream));

// Initialize Modularity
raft::spectral::matrix::modularity_matrix_t<vertex_t, weight_t> B{handle, csr_m};
raft::spectral::matrix::modularity_matrix_t<vertex_t, weight_t, nnz_t> B{handle, csr_m};

// Initialize output
modularity = 0;
Expand Down
16 changes: 10 additions & 6 deletions cpp/include/raft/spectral/modularity_maximization.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ namespace spectral {
* @param eigVecs Output eigenvector array pointer on device
* @return statistics: number of eigensolver iterations, .
*/
template <typename vertex_t, typename weight_t, typename EigenSolver, typename ClusterSolver>
template <typename vertex_t,
typename weight_t,
typename nnz_t,
typename EigenSolver,
typename ClusterSolver>
std::tuple<vertex_t, weight_t, vertex_t> modularity_maximization(
raft::resources const& handle,
matrix::sparse_matrix_t<vertex_t, weight_t> const& csr_m,
matrix::sparse_matrix_t<vertex_t, weight_t, nnz_t> const& csr_m,
EigenSolver const& eigen_solver,
ClusterSolver const& cluster_solver,
vertex_t* __restrict__ clusters,
weight_t* eigVals,
weight_t* eigVecs)
{
return raft::spectral::detail::
modularity_maximization<vertex_t, weight_t, EigenSolver, ClusterSolver>(
modularity_maximization<vertex_t, weight_t, nnz_t, EigenSolver, ClusterSolver>(
handle, csr_m, eigen_solver, cluster_solver, clusters, eigVals, eigVecs);
}
//===================================================
Expand All @@ -69,14 +73,14 @@ std::tuple<vertex_t, weight_t, vertex_t> modularity_maximization(
* @param clusters (Input, device memory, n entries) Cluster assignments.
* @param modularity On exit, modularity
*/
template <typename vertex_t, typename weight_t>
template <typename vertex_t, typename weight_t, typename nnz_t>
void analyzeModularity(raft::resources const& handle,
matrix::sparse_matrix_t<vertex_t, weight_t> const& csr_m,
matrix::sparse_matrix_t<vertex_t, weight_t, nnz_t> const& csr_m,
vertex_t nClusters,
vertex_t const* __restrict__ clusters,
weight_t& modularity)
{
raft::spectral::detail::analyzeModularity<vertex_t, weight_t>(
raft::spectral::detail::analyzeModularity<vertex_t, weight_t, nnz_t>(
handle, csr_m, nClusters, clusters, modularity);
}

Expand Down

0 comments on commit fb48043

Please sign in to comment.