Skip to content

Laplacian Kernel for COO inputs#2891

Merged
rapids-bot[bot] merged 14 commits into
NVIDIA:mainfrom
aamijar:laplacian-coo-input
Jan 10, 2026
Merged

Laplacian Kernel for COO inputs#2891
rapids-bot[bot] merged 14 commits into
NVIDIA:mainfrom
aamijar:laplacian-coo-input

Conversation

@aamijar

@aamijar aamijar commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

Resolves #2831 and Resolves #2875.

The laplacian kernel implementation needs to be reimagined to work with COO input since the previous CSR version isn't compatible.
The implementation in this PR also crucially addresses the issue of allocating the correct output size.
To calculate the laplacian L = D - A for a COO input the following steps are used:

  1. Count the number of extra nnz elements required to go from A to L by counting the number of nnz elements missing from diagonal of A.
  2. Keep track of which diagonal nnz elements are missing from A with binary array marked_diagonal. Compute exclusive_scan in an array scan_diagonal. This is used to place the extra missing elements in L.
  3. Allocate and initialize the output L. Copy the indexes and values from A into L. Initialize the extra nnz elements required for the diagonal if any at the end.
  4. Calculate D which is an array of degrees for each row of A
  5. Edit L in place so that diagonal elements are subtracted from D, and off-diagonal elements are negated.

@copy-pr-bot

copy-pr-bot Bot commented Dec 10, 2025

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@aamijar aamijar self-assigned this Dec 10, 2025
@aamijar aamijar added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Dec 10, 2025
@aamijar aamijar moved this from Todo to In Progress in Unstructured Data Processing Dec 10, 2025
@aamijar aamijar marked this pull request as ready for review January 7, 2026 06:09
@aamijar aamijar requested a review from a team as a code owner January 7, 2026 06:09

@dantegd dantegd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, very good test quality as well. Just had mainly comments about typos and a docstring and a perf question.

Comment thread cpp/include/raft/sparse/linalg/detail/laplacian.cuh Outdated
Comment thread cpp/include/raft/sparse/linalg/laplacian.cuh Outdated
Comment thread cpp/include/raft/sparse/linalg/laplacian.cuh Outdated
Comment thread cpp/include/raft/sparse/linalg/laplacian.cuh Outdated
Comment thread cpp/include/raft/sparse/linalg/laplacian.cuh Outdated
raft::linalg::map_offset(res,
raft::make_device_vector_view(result_values_ptr, result_nnz),
[result_rows_ptr, result_values_ptr, degrees_ptr] __device__(auto idx) {
atomicAdd(&degrees_ptr[result_rows_ptr[idx]], result_values_ptr[idx]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a bit of a performance bottleneck I wonder if you've profiled/benchmarked it?

My though comes from the fact that if you have a row with many connections (common in power-law graphs for example), many threads will contend on the same degrees_ptr[row] location simultaneously. Probably not a huge deal, but if it's a bottleneck something we could try (maybe a follow up) is either of:

  • Segmented reduction: If COO is sorted by row, use thrust::reduce_by_key instead of atomics
  • Histogram-style approaches: Use shared memory atomics first, then global atomics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I haven't profiled it but I applied your suggestion to use thrust::reduce_by_key in the PR

aamijar and others added 7 commits January 8, 2026 19:53
Co-authored-by: Dante Gama Dessavre <dante.gamadessavre@gmail.com>
Co-authored-by: Dante Gama Dessavre <dante.gamadessavre@gmail.com>
Co-authored-by: Dante Gama Dessavre <dante.gamadessavre@gmail.com>
Co-authored-by: Dante Gama Dessavre <dante.gamadessavre@gmail.com>
Co-authored-by: Dante Gama Dessavre <dante.gamadessavre@gmail.com>
@dantegd

dantegd commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot rapids-bot Bot merged commit 93871c7 into NVIDIA:main Jan 10, 2026
109 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Unstructured Data Processing Jan 10, 2026
rapids-bot Bot pushed a commit to NVIDIA/cuvs that referenced this pull request Jan 13, 2026
Resolves #1243. Depends on NVIDIA/raft#2891.

This PR adds a `NNZType` to the spectral embedding public api with precomputed connectivity graph.
The transform api for the precomputed connectivity graph has been switched to use the COO codepath all the way through the algorithm.

The spectral embedding api which passes in a dataset also has been switched to use the COO codepath and use int64_t by default.

Authors:
  - Anupam (https://github.com/aamijar)

Approvers:
  - Victor Lafargue (https://github.com/viclafargue)
  - Tarang Jain (https://github.com/tarang-jain)

URL: #1628
landrumb pushed a commit to landrumb/cuvs that referenced this pull request Jul 8, 2026
Resolves NVIDIA#1243. Depends on NVIDIA/raft#2891.

This PR adds a `NNZType` to the spectral embedding public api with precomputed connectivity graph.
The transform api for the precomputed connectivity graph has been switched to use the COO codepath all the way through the algorithm.

The spectral embedding api which passes in a dataset also has been switched to use the COO codepath and use int64_t by default.

Authors:
  - Anupam (https://github.com/aamijar)

Approvers:
  - Victor Lafargue (https://github.com/viclafargue)
  - Tarang Jain (https://github.com/tarang-jain)

URL: NVIDIA#1628
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Update public header for lanczos solver to support nnz_t Laplacian Kernel with COO input

3 participants