Skip to content

Add KDE kernel#1915

Merged
rapids-bot[bot] merged 11 commits intorapidsai:mainfrom
Intron7:tiled_kde_kernel
Apr 8, 2026
Merged

Add KDE kernel#1915
rapids-bot[bot] merged 11 commits intorapidsai:mainfrom
Intron7:tiled_kde_kernel

Conversation

@Intron7
Copy link
Copy Markdown
Contributor

@Intron7 Intron7 commented Mar 13, 2026

@cjnolet moved the kernel for KDE from cuml to cuvs. This PR is needed for rapidsai/cuml#7833

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Mar 13, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment thread cpp/include/cuvs/distance/kde.hpp Outdated
*/
template <typename T>
void kde_score_samples(raft::resources const& handle,
const T* query,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we accept mdspans here instead of raw pointers? That would also simplify the function signatures for the public APIs. Can still expose pointers at the cuml layer for now (for the python layer) if that's easier.

Comment thread cpp/include/cuvs/distance/kde.hpp Outdated
* @param[in] metric_arg Metric parameter (e.g. p for Minkowski; ignored otherwise)
*/
template <typename T>
void kde_score_samples(raft::resources const& handle,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense just call this "kde" or is there signficant enough post processing being done after calling this?

Comment thread cpp/include/cuvs/distance/kde.hpp Outdated
* These are the smoothing kernels used in KDE — distinct from the dot-product
* kernels (RBF, Polynomial, etc.) in cuvs::distance::kernels used by SVMs.
*/
enum class DensityKernelType : int {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we at least consolidate this struct w/ the existing KernelType struct in distance.hpp?

@aamijar aamijar moved this to In Progress in Unstructured Data Processing Mar 13, 2026
@aamijar aamijar added non-breaking Introduces a non-breaking change improvement Improves an existing functionality labels Mar 13, 2026
@aamijar
Copy link
Copy Markdown
Member

aamijar commented Mar 13, 2026

/ok to test 4690f8d

@aamijar
Copy link
Copy Markdown
Member

aamijar commented Mar 13, 2026

@Intron7, thanks for the PR!
Please run pre-commit to enforce style checks.

@aamijar aamijar changed the title add kde kernel Add KDE kernel Mar 13, 2026
@aamijar
Copy link
Copy Markdown
Member

aamijar commented Mar 15, 2026

/ok to test 66d923b

@aamijar
Copy link
Copy Markdown
Member

aamijar commented Mar 18, 2026

/ok to test 8c852d5

Copy link
Copy Markdown
Contributor

@viclafargue viclafargue left a comment

Choose a reason for hiding this comment

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

Thanks @Intron7! LGTM for the most part, but we need testing.

It's hard to have confidence in the correctness without tests. We have to validate against scikit-learn's KernelDensity either through cuML or by adding Python bindings directly in cuVS. At minimum, this PR should include a C++ gtest covering:

  • Each metric with the Gaussian kernel (isolates distance correctness)
  • Each kernel with Euclidean metric (isolates kernel evaluation + normalization)
  • Single-pass vs. multi-pass (force multi-pass with small n_query, verify results match)
  • Weighted vs. unweighted inputs

Comment thread cpp/src/distance/kde.cu
Comment thread cpp/src/distance/kde.cu
std::optional<raft::device_vector_view<const T, std::int64_t>> weights,
raft::device_vector_view<T, std::int64_t> output,
T bandwidth,
T sum_weights,
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.

Is there a reason sum_weights is caller-provided rather than computed internally from weights? A mismatch silently produces incorrectly scaled output, and a device reduction would eliminate that risk.

@cjnolet
Copy link
Copy Markdown
Member

cjnolet commented Apr 1, 2026

Tests look good, thanks so much @Intron7. It looks like CI just complaining on the branch being too old. If you can update the branch with upstream main, we can get this merged.

@aamijar
Copy link
Copy Markdown
Member

aamijar commented Apr 1, 2026

/ok to test d0e8e5c

Copy link
Copy Markdown
Contributor

@viclafargue viclafargue left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests. We're almost there, but the tiling system isn't being sufficiently exercised. All tests use d=3, which means the feature tiling loop only ever runs a single iteration. The core cross-tile accumulation path is never tested. We need at least one test with d > 64.

Comment thread cpp/tests/distance/kde.cu
@cjnolet
Copy link
Copy Markdown
Member

cjnolet commented Apr 2, 2026

/ok to test 6832169

Copy link
Copy Markdown
Contributor

@viclafargue viclafargue left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@aamijar
Copy link
Copy Markdown
Member

aamijar commented Apr 8, 2026

/ok to test dd28037

@cjnolet
Copy link
Copy Markdown
Member

cjnolet commented Apr 8, 2026

/merge

@rapids-bot rapids-bot bot merged commit 22fd272 into rapidsai:main Apr 8, 2026
152 of 155 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Unstructured Data Processing Apr 8, 2026
enp1s0 pushed a commit to enp1s0/cuvs that referenced this pull request Apr 10, 2026
@cjnolet moved the kernel for KDE from cuml to cuvs. This PR is needed for rapidsai/cuml#7833

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

Approvers:
  - Victor Lafargue (https://github.com/viclafargue)
  - Corey J. Nolet (https://github.com/cjnolet)

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

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants