Laplacian Kernel for COO inputs#2891
Conversation
|
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. |
dantegd
left a comment
There was a problem hiding this comment.
Code looks good to me, very good test quality as well. Just had mainly comments about typos and a docstring and a perf question.
| 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(°rees_ptr[result_rows_ptr[idx]], result_values_ptr[idx]); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks for the review! I haven't profiled it but I applied your suggestion to use thrust::reduce_by_key in the PR
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>
|
/merge |
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
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
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 - Afor a COO input the following steps are used:AtoLby counting the number of nnz elements missing from diagonal ofA.Awith binary arraymarked_diagonal. Compute exclusive_scan in an arrayscan_diagonal. This is used to place the extra missing elements inL.L. Copy the indexes and values fromAintoL. Initialize the extra nnz elements required for the diagonal if any at the end.Dwhich is an array of degrees for each row ofALin place so that diagonal elements are subtracted from D, and off-diagonal elements are negated.