Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 3 additions & 3 deletions cpp/src/genetic/fitness.cuh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

#include <raft/core/handle.hpp>
#include <raft/linalg/eltwise.cuh>
#include <raft/linalg/matrix_vector_op.cuh>
#include <raft/linalg/sqrt.cuh>
#include <raft/linalg/strided_reduction.cuh>
#include <raft/linalg/unary_op.cuh>
#include <raft/matrix/math.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include <raft/stats/stddev.cuh>
Expand Down Expand Up @@ -310,7 +310,7 @@ void rootMeanSquareError(const raft::handle_t& h,
meanSquareError(h, n_samples, n_progs, Y, Y_pred, W, out);

// Take sqrt on all entries
raft::matrix::seqRoot(out, n_progs, stream);
raft::linalg::sqrt(out, out, n_progs, stream);
}

template <typename math_t = float>
Expand Down
16 changes: 10 additions & 6 deletions cpp/src/glm/ols.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -11,11 +11,11 @@
#include <raft/linalg/gemv.cuh>
#include <raft/linalg/lstsq.cuh>
#include <raft/linalg/map.cuh>
#include <raft/linalg/matrix_vector.cuh>
#include <raft/linalg/norm.cuh>
#include <raft/linalg/power.cuh>
#include <raft/linalg/sqrt.cuh>
#include <raft/linalg/subtract.cuh>
#include <raft/matrix/math.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include <raft/stats/stddev.cuh>
Expand Down Expand Up @@ -81,8 +81,10 @@ void olsFit(const raft::handle_t& handle,

if (sample_weight != nullptr) {
raft::linalg::sqrt(sample_weight, sample_weight, n_rows, stream);
raft::matrix::matrixVectorBinaryMult<false, false>(
input, sample_weight, n_rows, n_cols, stream);
raft::linalg::binary_mult<raft::Apply::ALONG_COLUMNS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(input, n_rows, n_cols),
raft::make_device_vector_view<const math_t, size_t>(sample_weight, n_rows));
raft::linalg::map_k(
labels,
n_rows,
Expand Down Expand Up @@ -110,8 +112,10 @@ void olsFit(const raft::handle_t& handle,
raft::common::nvtx::pop_range();

if (sample_weight != nullptr) {
raft::matrix::matrixVectorBinaryDivSkipZero<false, false>(
input, sample_weight, n_rows, n_cols, stream);
raft::linalg::binary_div_skip_zero<raft::Apply::ALONG_COLUMNS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(input, n_rows, n_cols),
raft::make_device_vector_view<const math_t, size_t>(sample_weight, n_rows));
raft::linalg::map_k(
labels,
n_rows,
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/glm/preprocess.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -8,8 +8,6 @@
#include <raft/core/handle.hpp>
#include <raft/linalg/gemm.cuh>
#include <raft/linalg/subtract.cuh>
#include <raft/matrix/math.cuh>
#include <raft/matrix/matrix.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include <raft/stats/meanvar.cuh>
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/glm/preprocess_mg.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -12,7 +12,6 @@
#include <raft/core/comms.hpp>
#include <raft/linalg/gemm.cuh>
#include <raft/linalg/subtract.cuh>
#include <raft/matrix/math.cuh>
#include <raft/util/cuda_utils.cuh>
#include <raft/util/cudart_utils.hpp>

Expand Down
11 changes: 7 additions & 4 deletions cpp/src/glm/qn/mg/standardization.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -12,10 +12,11 @@
#include <raft/core/operators.hpp>
#include <raft/linalg/binary_op.cuh>
#include <raft/linalg/divide.cuh>
#include <raft/linalg/matrix_vector.cuh>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
#include <raft/linalg/matrix_vector_op.cuh>
#include <raft/linalg/multiply.cuh>
#include <raft/linalg/sqrt.cuh>
#include <raft/linalg/subtract.cuh>
#include <raft/matrix/math.hpp>
#include <raft/sparse/op/row_op.cuh>
#include <raft/stats/stddev.cuh>
#include <raft/stats/sum.cuh>
Expand Down Expand Up @@ -354,8 +355,10 @@ struct Standardizer {
SimpleDenseMat<T> Gweights;
col_slice(G, Gweights, 0, D);

raft::matrix::matrixVectorBinaryMult<false, true>(
Gweights.data, std_inv.data, Gweights.m, D, stream);
raft::linalg::binary_mult<raft::Apply::ALONG_ROWS>(
handle,
raft::make_device_matrix_view<T, int, raft::col_major>(Gweights.data, Gweights.m, D),
raft::make_device_vector_view<const T, int>(std_inv.data, D));

if (has_bias) {
SimpleVec<T> Gbias;
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/glm/qn/qn.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -16,7 +16,7 @@

#include <cuml/linear_model/qn.h>

#include <raft/matrix/math.cuh>
#include <raft/matrix/argmax.cuh>

#include <rmm/device_uvector.hpp>

Expand Down Expand Up @@ -264,7 +264,10 @@ void qn_predict(
if (C == 2) {
P.assign_unary(Z, [] __device__(const T z) { return z > 0.0 ? T(1) : T(0); }, stream);
} else {
raft::matrix::argmax(Z.data, C, X.m, preds, stream);
raft::matrix::argmax(handle,
raft::make_device_matrix_view<const T, int, raft::row_major>(
Z.data, static_cast<int>(X.m), C),
raft::make_device_vector_view<T, int>(preds, static_cast<int>(X.m)));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
} else {
P.copy_async(Z, stream);
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/glm/qn_mg.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -20,7 +20,7 @@
#include <raft/linalg/matrix_vector.cuh>
#include <raft/linalg/matrix_vector_op.cuh>
#include <raft/linalg/sqrt.cuh>
#include <raft/matrix/math.hpp>
// #include <raft/matrix/math.hpp>
Comment thread
aamijar marked this conversation as resolved.
Resolved
#include <raft/stats/mean_center.cuh>
#include <raft/stats/stddev.cuh>
#include <raft/stats/sum.cuh>
Expand Down
40 changes: 28 additions & 12 deletions cpp/src/glm/ridge.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2018-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,10 +10,13 @@
#include <raft/linalg/add.cuh>
#include <raft/linalg/gemm.cuh>
#include <raft/linalg/map.cuh>
#include <raft/linalg/matrix_vector.cuh>
#include <raft/linalg/norm.cuh>
#include <raft/linalg/power.cuh>
#include <raft/linalg/sqrt.cuh>
#include <raft/linalg/subtract.cuh>
#include <raft/linalg/svd.cuh>
#include <raft/matrix/math.cuh>
#include <raft/matrix/threshold.cuh>
#include <raft/stats/mean.cuh>
#include <raft/stats/mean_center.cuh>
#include <raft/stats/stddev.cuh>
Expand Down Expand Up @@ -49,15 +52,24 @@ void ridgeSolve(const raft::handle_t& handle,
math_t beta = math_t(0);
math_t thres = math_t(1e-10);

raft::matrix::setSmallValuesZero(S, n_cols, stream, thres);
raft::matrix::zero_small_values(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(S, size_t(1), n_cols),
thres);

raft::copy(S_nnz, S, n_cols, stream);
raft::matrix::power(S_nnz, n_cols, stream);
raft::linalg::powerScalar(S_nnz, S_nnz, math_t(2), n_cols, stream);
raft::linalg::addScalar(S_nnz, S_nnz, alpha[0], n_cols, stream);
raft::matrix::matrixVectorBinaryDivSkipZero<false, true>(
S, S_nnz, (size_t)1, n_cols, stream, true);

raft::matrix::matrixVectorBinaryMult<false, true>(V, S, n_cols, n_cols, stream);
raft::linalg::binary_div_skip_zero<raft::Apply::ALONG_ROWS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(S, size_t(1), n_cols),
raft::make_device_vector_view<const math_t, size_t>(S_nnz, n_cols),
true);

raft::linalg::binary_mult<raft::Apply::ALONG_ROWS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(V, n_cols, n_cols),
raft::make_device_vector_view<const math_t, size_t>(S, n_cols));
raft::linalg::gemm(
handle, U, n_rows, n_cols, b, S_nnz, n_cols, 1, CUBLAS_OP_T, CUBLAS_OP_N, alp, beta, stream);

Expand Down Expand Up @@ -179,8 +191,10 @@ void ridgeFit(const raft::handle_t& handle,
}
if (sample_weight != nullptr) {
raft::linalg::sqrt(sample_weight, sample_weight, n_rows, stream);
raft::matrix::matrixVectorBinaryMult<false, false>(
input, sample_weight, n_rows, n_cols, stream);
raft::linalg::binary_mult<raft::Apply::ALONG_COLUMNS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(input, n_rows, n_cols),
raft::make_device_vector_view<const math_t, size_t>(sample_weight, n_rows));
raft::linalg::map_k(
labels,
n_rows,
Expand All @@ -201,8 +215,10 @@ void ridgeFit(const raft::handle_t& handle,
}

if (sample_weight != nullptr) {
raft::matrix::matrixVectorBinaryDivSkipZero<false, false>(
input, sample_weight, n_rows, n_cols, stream);
raft::linalg::binary_div_skip_zero<raft::Apply::ALONG_COLUMNS>(
handle,
raft::make_device_matrix_view<math_t, size_t, raft::col_major>(input, n_rows, n_cols),
raft::make_device_vector_view<const math_t, size_t>(sample_weight, n_rows));
raft::linalg::map_k(
labels,
n_rows,
Expand Down
35 changes: 28 additions & 7 deletions cpp/src/glm/ridge_mg.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -12,7 +12,9 @@
#include <raft/core/comms.hpp>
#include <raft/linalg/add.cuh>
#include <raft/linalg/gemm.cuh>
#include <raft/matrix/math.cuh>
#include <raft/linalg/matrix_vector.cuh>
#include <raft/linalg/power.cuh>
#include <raft/matrix/threshold.cuh>
#include <raft/util/cuda_utils.cuh>
#include <raft/util/cudart_utils.hpp>

Expand Down Expand Up @@ -44,17 +46,36 @@ void ridgeSolve(const raft::handle_t& handle,
T beta = T(0);
T thres = T(1e-10);

raft::matrix::setSmallValuesZero(S, UDesc.N, streams[0], thres);
// raft::matrix::setSmallValuesZero(S, UDesc.N, streams[0], thres);
// raft::resource::set_cuda_stream(handle, streams[0]);
Comment thread
aamijar marked this conversation as resolved.
Resolved
raft::resources handle_stream_zero;
raft::resource::set_cuda_stream(handle_stream_zero, streams[0]);
raft::matrix::zero_small_values(
handle_stream_zero,
raft::make_device_matrix_view<T, std::size_t, raft::col_major>(S, std::size_t(1), UDesc.N),
thres);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

rmm::device_uvector<T> S_nnz_vector(UDesc.N, streams[0]);
S_nnz = S_nnz_vector.data();
raft::copy(S_nnz, S, UDesc.N, streams[0]);
raft::matrix::power(S_nnz, UDesc.N, streams[0]);
// raft::matrix::power(S_nnz, UDesc.N, streams[0]);
Comment thread
aamijar marked this conversation as resolved.
Resolved
raft::linalg::powerScalar(S_nnz, S_nnz, T(2), UDesc.N, streams[0]);
raft::linalg::addScalar(S_nnz, S_nnz, alpha[0], UDesc.N, streams[0]);
raft::matrix::matrixVectorBinaryDivSkipZero<false, true>(
S, S_nnz, size_t(1), UDesc.N, streams[0], true);

raft::matrix::matrixVectorBinaryMult<false, true>(V, S, UDesc.N, UDesc.N, streams[0]);
// raft::matrix::matrixVectorBinaryDivSkipZero<false, true>(
// S, S_nnz, size_t(1), UDesc.N, streams[0], true);

// raft::matrix::matrixVectorBinaryMult<false, true>(V, S, UDesc.N, UDesc.N, streams[0]);
Comment thread
aamijar marked this conversation as resolved.
Resolved
raft::linalg::binary_div_skip_zero<raft::Apply::ALONG_ROWS>(
handle_stream_zero,
raft::make_device_matrix_view<T, std::size_t, raft::col_major>(S, std::size_t(1), UDesc.N),
raft::make_device_vector_view<const T, std::size_t>(S_nnz, UDesc.N),
true);

raft::linalg::binary_mult<raft::Apply::ALONG_ROWS>(
handle_stream_zero,
raft::make_device_matrix_view<T, std::size_t, raft::col_major>(V, UDesc.N, UDesc.N),
raft::make_device_vector_view<const T, std::size_t>(S, UDesc.N));

MLCommon::Matrix::Data<T> S_nnz_data;
S_nnz_data.totalSize = UDesc.N;
Expand Down
17 changes: 13 additions & 4 deletions cpp/src/hdbscan/detail/soft_clustering.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -17,7 +17,7 @@
#include <raft/label/classlabels.cuh>
#include <raft/linalg/matrix_vector_op.cuh>
#include <raft/matrix/argmax.cuh>
#include <raft/matrix/matrix.cuh>
#include <raft/matrix/copy.cuh>
#include <raft/sparse/convert/csr.cuh>
#include <raft/sparse/op/sort.cuh>
#include <raft/util/cuda_utils.cuh>
Expand Down Expand Up @@ -46,6 +46,7 @@ namespace Predict {
template <typename value_idx, typename value_t>
void dist_membership_vector(const raft::handle_t& handle,
const value_t* X,
size_t n_X_rows,
const value_t* query,
size_t n_queries,
size_t n,
Expand All @@ -64,8 +65,14 @@ void dist_membership_vector(const raft::handle_t& handle,
rmm::device_uvector<value_t> exemplars_dense(n_exemplars * n, stream);

// use the exemplar point indices to obtain the exemplar points as a dense array
raft::matrix::copyRows<value_t, value_idx, size_t>(
X, n_exemplars, n, exemplars_dense.data(), exemplar_idx, n_exemplars, stream, true);
// exemplar_idx indexes into X, which has n_X_rows rows (training data)
auto X_view =
raft::make_device_matrix_view<const value_t, size_t, raft::row_major>(X, n_X_rows, n);
auto exemplars_dense_view = raft::make_device_matrix_view<value_t, size_t, raft::row_major>(
exemplars_dense.data(), n_exemplars, n);
auto exemplar_idx_view = raft::make_device_vector_view<const size_t, size_t>(
reinterpret_cast<const size_t*>(exemplar_idx), n_exemplars);
Comment thread
aamijar marked this conversation as resolved.
Resolved
raft::matrix::copy_rows(handle, X_view, exemplars_dense_view, exemplar_idx_view);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// compute the number of batches based on the batch size
value_idx n_batches;
Expand Down Expand Up @@ -414,6 +421,7 @@ void all_points_membership_vectors(const raft::handle_t& handle,

dist_membership_vector(handle,
X,
m,
X,
m,
n,
Expand Down Expand Up @@ -525,6 +533,7 @@ void membership_vector(const raft::handle_t& handle,

dist_membership_vector(handle,
X,
m,
points_to_predict,
n_prediction_points,
n,
Expand Down
Loading
Loading