Skip to content

Commit 080952e

Browse files
authored
Merge branch 'release/25.12' into java/relax-cuvs-version-checks
2 parents 9954f99 + 2f424b1 commit 080952e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1452
-1254
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
date: ${{ inputs.date }}
5959
container_image: "rapidsai/ci-wheel:25.12-cuda${{ matrix.cuda_version }}-rockylinux8-py3.10"
6060
node_type: "cpu16"
61-
name: "${{ matrix.cuda_version }}, amd64, rockylinux8"
6261
# requires_license_builder: false
6362
script: "ci/build_standalone_c.sh"
6463
artifact-name: "libcuvs_c_${{ matrix.cuda_version }}.tar.gz"

.github/workflows/pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
with:
188188
build_type: pull-request
189189
arch: "amd64"
190-
date: ${{ inputs.date }}_c
190+
date: ${{ inputs.date }}
191191
container_image: "rapidsai/ci-wheel:25.12-cuda${{ matrix.cuda_version }}-rockylinux8-py3.10"
192192
node_type: "cpu16"
193193
# requires_license_builder: false
@@ -210,7 +210,7 @@ jobs:
210210
build_type: pull-request
211211
node_type: "gpu-l4-latest-1"
212212
arch: "amd64"
213-
date: ${{ inputs.date }}_c
213+
date: ${{ inputs.date }}
214214
container_image: "rapidsai/ci-wheel:25.12-cuda${{ matrix.cuda_version }}-rockylinux8-py3.10"
215215
script: "ci/test_standalone_c.sh"
216216
sha: ${{ inputs.sha }}

c/include/cuvs/core/c_api.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <cuda_runtime.h>
99
#include <dlpack/dlpack.h>
10-
#include <rapids_logger/log_levels.h>
1110
#include <stdbool.h>
1211
#include <stdint.h>
1312

@@ -48,13 +47,13 @@ void cuvsSetLastErrorText(const char* error);
4847
*
4948
*/
5049
typedef enum {
51-
CUVS_LOG_LEVEL_TRACE = RAPIDS_LOGGER_LOG_LEVEL_TRACE,
52-
CUVS_LOG_LEVEL_DEBUG = RAPIDS_LOGGER_LOG_LEVEL_DEBUG,
53-
CUVS_LOG_LEVEL_INFO = RAPIDS_LOGGER_LOG_LEVEL_INFO,
54-
CUVS_LOG_LEVEL_WARN = RAPIDS_LOGGER_LOG_LEVEL_WARN,
55-
CUVS_LOG_LEVEL_ERROR = RAPIDS_LOGGER_LOG_LEVEL_ERROR,
56-
CUVS_LOG_LEVEL_CRITICAL = RAPIDS_LOGGER_LOG_LEVEL_CRITICAL,
57-
CUVS_LOG_LEVEL_OFF = RAPIDS_LOGGER_LOG_LEVEL_OFF
50+
CUVS_LOG_LEVEL_TRACE = 0,
51+
CUVS_LOG_LEVEL_DEBUG = 1,
52+
CUVS_LOG_LEVEL_INFO = 2,
53+
CUVS_LOG_LEVEL_WARN = 3,
54+
CUVS_LOG_LEVEL_ERROR = 4,
55+
CUVS_LOG_LEVEL_CRITICAL = 5,
56+
CUVS_LOG_LEVEL_OFF = 6
5857
} cuvsLogLevel_t;
5958

6059
/** @brief Returns the current log level

c/src/core/c_api.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extern "C" cuvsError_t cuvsRMMPoolMemoryResourceEnable(int initial_pool_size_per
185185
extern "C" cuvsError_t cuvsRMMMemoryResourceReset()
186186
{
187187
return cuvs::core::translate_exceptions([=] {
188-
rmm::mr::set_current_device_resource(nullptr);
188+
rmm::mr::set_current_device_resource(rmm::mr::detail::initial_resource());
189189
pool_mr.reset();
190190
});
191191
}
@@ -214,7 +214,32 @@ extern "C" const char* cuvsGetLastErrorText()
214214

215215
extern "C" void cuvsSetLogLevel(cuvsLogLevel_t verbosity)
216216
{
217-
raft::default_logger().set_level(static_cast<rapids_logger::level_enum>(verbosity));
217+
rapids_logger::level_enum level = rapids_logger::level_enum::trace;
218+
switch (verbosity) {
219+
case CUVS_LOG_LEVEL_TRACE:
220+
level = rapids_logger::level_enum::trace;
221+
break;
222+
case CUVS_LOG_LEVEL_DEBUG:
223+
level = rapids_logger::level_enum::debug;
224+
break;
225+
case CUVS_LOG_LEVEL_INFO:
226+
level = rapids_logger::level_enum::info;
227+
break;
228+
case CUVS_LOG_LEVEL_WARN:
229+
level = rapids_logger::level_enum::warn;
230+
break;
231+
case CUVS_LOG_LEVEL_ERROR:
232+
level = rapids_logger::level_enum::error;
233+
break;
234+
case CUVS_LOG_LEVEL_CRITICAL:
235+
level = rapids_logger::level_enum::critical;
236+
break;
237+
case CUVS_LOG_LEVEL_OFF:
238+
level = rapids_logger::level_enum::off;
239+
break;
240+
default: RAFT_FAIL("Unsupported cuvsLogLevel_t value provided");
241+
}
242+
raft::default_logger().set_level(level);
218243
}
219244

220245
extern "C" cuvsLogLevel_t cuvsGetLogLevel()

cpp/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ if(NOT BUILD_CPU_ONLY)
328328

329329
add_library(
330330
cuvs_objs OBJECT
331-
src/cluster/kmeans_balanced_fit_float.cu
331+
src/cluster/detail/minClusterDistanceCompute.cu
332332
src/cluster/kmeans_cluster_cost.cu
333333
src/cluster/kmeans_fit_mg_float.cu
334334
src/cluster/kmeans_fit_mg_double.cu
@@ -340,11 +340,15 @@ if(NOT BUILD_CPU_ONLY)
340340
src/cluster/kmeans_predict_double.cu
341341
src/cluster/kmeans_predict_float.cu
342342
src/cluster/kmeans_balanced_fit_float.cu
343+
src/cluster/kmeans_balanced_fit_half.cu
343344
src/cluster/kmeans_balanced_fit_predict_float.cu
344345
src/cluster/kmeans_balanced_predict_float.cu
346+
src/cluster/kmeans_balanced_predict_half.cu
345347
src/cluster/kmeans_balanced_fit_int8.cu
348+
src/cluster/kmeans_balanced_fit_uint8.cu
346349
src/cluster/kmeans_balanced_fit_predict_int8.cu
347350
src/cluster/kmeans_balanced_predict_int8.cu
351+
src/cluster/kmeans_balanced_predict_uint8.cu
348352
src/cluster/kmeans_transform_double.cu
349353
src/cluster/kmeans_transform_float.cu
350354
src/cluster/single_linkage_float.cu

cpp/include/cuvs/cluster/kmeans.hpp

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,74 @@ void fit(const raft::resources& handle,
455455
raft::device_matrix_view<const int8_t, int64_t> X,
456456
raft::device_matrix_view<float, int64_t> centroids);
457457

458+
/**
459+
* @brief Find balanced clusters with k-means algorithm.
460+
*
461+
* @code{.cpp}
462+
* #include <raft/core/resources.hpp>
463+
* #include <cuvs/cluster/kmeans.hpp>
464+
* using namespace cuvs::cluster;
465+
* ...
466+
* raft::resources handle;
467+
* cuvs::cluster::kmeans::balanced_params params;
468+
* int64_t n_features = 15, n_clusters = 8;
469+
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
470+
*
471+
* kmeans::fit(handle,
472+
* params,
473+
* X,
474+
* centroids);
475+
* @endcode
476+
*
477+
* @param[in] handle The raft handle.
478+
* @param[in] params Parameters for KMeans model.
479+
* @param[in] X Training instances to cluster. The data must
480+
* be in row-major format.
481+
* [dim = n_samples x n_features]
482+
* @param[inout] centroids [out] The generated centroids from the
483+
* kmeans algorithm are stored at the address
484+
* pointed by 'centroids'.
485+
* [dim = n_clusters x n_features]
486+
*/
487+
void fit(const raft::resources& handle,
488+
cuvs::cluster::kmeans::balanced_params const& params,
489+
raft::device_matrix_view<const half, int64_t> X,
490+
raft::device_matrix_view<float, int64_t> centroids);
491+
492+
/**
493+
* @brief Find balanced clusters with k-means algorithm.
494+
*
495+
* @code{.cpp}
496+
* #include <raft/core/resources.hpp>
497+
* #include <cuvs/cluster/kmeans.hpp>
498+
* using namespace cuvs::cluster;
499+
* ...
500+
* raft::resources handle;
501+
* cuvs::cluster::kmeans::balanced_params params;
502+
* int64_t n_features = 15, n_clusters = 8;
503+
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
504+
*
505+
* kmeans::fit(handle,
506+
* params,
507+
* X,
508+
* centroids);
509+
* @endcode
510+
*
511+
* @param[in] handle The raft handle.
512+
* @param[in] params Parameters for KMeans model.
513+
* @param[in] X Training instances to cluster. The data must
514+
* be in row-major format.
515+
* [dim = n_samples x n_features]
516+
* @param[inout] centroids [out] The generated centroids from the
517+
* kmeans algorithm are stored at the address
518+
* pointed by 'centroids'.
519+
* [dim = n_clusters x n_features]
520+
*/
521+
void fit(const raft::resources& handle,
522+
cuvs::cluster::kmeans::balanced_params const& params,
523+
raft::device_matrix_view<const uint8_t, int64_t> X,
524+
raft::device_matrix_view<float, int64_t> centroids);
525+
458526
/**
459527
* @brief Predict the closest cluster each sample in X belongs to.
460528
*
@@ -819,6 +887,138 @@ void predict(const raft::resources& handle,
819887
raft::device_matrix_view<const float, int64_t> centroids,
820888
raft::device_vector_view<int, int64_t> labels);
821889

890+
/**
891+
* @brief Predict the closest cluster each sample in X belongs to.
892+
*
893+
* @code{.cpp}
894+
* #include <raft/core/resources.hpp>
895+
* #include <cuvs/cluster/kmeans.hpp>
896+
* using namespace cuvs::cluster;
897+
* ...
898+
* raft::resources handle;
899+
* cuvs::cluster::kmeans::balanced_params params;
900+
* int64_t n_features = 15, n_clusters = 8;
901+
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
902+
*
903+
* kmeans::fit(handle,
904+
* params,
905+
* X,
906+
* centroids.view());
907+
* ...
908+
* auto labels = raft::make_device_vector<uint32_t, int64_t>(handle, X.extent(0));
909+
*
910+
* kmeans::predict(handle,
911+
* params,
912+
* X,
913+
* centroids.view(),
914+
* labels.view());
915+
* @endcode
916+
*
917+
* @param[in] handle The raft handle.
918+
* @param[in] params Parameters for KMeans model.
919+
* @param[in] X New data to predict.
920+
* [dim = n_samples x n_features]
921+
* @param[in] centroids Cluster centroids. The data must be in
922+
* row-major format.
923+
* [dim = n_clusters x n_features]
924+
* @param[out] labels Index of the cluster each sample in X
925+
* belongs to.
926+
* [len = n_samples]
927+
*/
928+
void predict(const raft::resources& handle,
929+
cuvs::cluster::kmeans::balanced_params const& params,
930+
raft::device_matrix_view<const float, int64_t> X,
931+
raft::device_matrix_view<const float, int64_t> centroids,
932+
raft::device_vector_view<uint32_t, int64_t> labels);
933+
934+
/**
935+
* @brief Predict the closest cluster each sample in X belongs to.
936+
*
937+
* @code{.cpp}
938+
* #include <raft/core/resources.hpp>
939+
* #include <cuvs/cluster/kmeans.hpp>
940+
* using namespace cuvs::cluster;
941+
* ...
942+
* raft::resources handle;
943+
* cuvs::cluster::kmeans::balanced_params params;
944+
* int64_t n_features = 15, n_clusters = 8;
945+
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
946+
*
947+
* kmeans::fit(handle,
948+
* params,
949+
* X,
950+
* centroids.view());
951+
* ...
952+
* auto labels = raft::make_device_vector<uint32_t, int64_t>(handle, X.extent(0));
953+
*
954+
* kmeans::predict(handle,
955+
* params,
956+
* X,
957+
* centroids.view(),
958+
* labels.view());
959+
* @endcode
960+
*
961+
* @param[in] handle The raft handle.
962+
* @param[in] params Parameters for KMeans model.
963+
* @param[in] X New data to predict.
964+
* [dim = n_samples x n_features]
965+
* @param[in] centroids Cluster centroids. The data must be in
966+
* row-major format.
967+
* [dim = n_clusters x n_features]
968+
* @param[out] labels Index of the cluster each sample in X
969+
* belongs to.
970+
* [len = n_samples]
971+
*/
972+
void predict(const raft::resources& handle,
973+
cuvs::cluster::kmeans::balanced_params const& params,
974+
raft::device_matrix_view<const half, int64_t> X,
975+
raft::device_matrix_view<const float, int64_t> centroids,
976+
raft::device_vector_view<uint32_t, int64_t> labels);
977+
978+
/**
979+
* @brief Predict the closest cluster each sample in X belongs to.
980+
*
981+
* @code{.cpp}
982+
* #include <raft/core/resources.hpp>
983+
* #include <cuvs/cluster/kmeans.hpp>
984+
* using namespace cuvs::cluster;
985+
* ...
986+
* raft::resources handle;
987+
* cuvs::cluster::kmeans::balanced_params params;
988+
* int64_t n_features = 15, n_clusters = 8;
989+
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
990+
*
991+
* kmeans::fit(handle,
992+
* params,
993+
* X,
994+
* centroids.view());
995+
* ...
996+
* auto labels = raft::make_device_vector<uint32_t, int64_t>(handle, X.extent(0));
997+
*
998+
* kmeans::predict(handle,
999+
* params,
1000+
* X,
1001+
* centroids.view(),
1002+
* labels.view());
1003+
* @endcode
1004+
*
1005+
* @param[in] handle The raft handle.
1006+
* @param[in] params Parameters for KMeans model.
1007+
* @param[in] X New data to predict.
1008+
* [dim = n_samples x n_features]
1009+
* @param[in] centroids Cluster centroids. The data must be in
1010+
* row-major format.
1011+
* [dim = n_clusters x n_features]
1012+
* @param[out] labels Index of the cluster each sample in X
1013+
* belongs to.
1014+
* [len = n_samples]
1015+
*/
1016+
void predict(const raft::resources& handle,
1017+
cuvs::cluster::kmeans::balanced_params const& params,
1018+
raft::device_matrix_view<const uint8_t, int64_t> X,
1019+
raft::device_matrix_view<const float, int64_t> centroids,
1020+
raft::device_vector_view<uint32_t, int64_t> labels);
1021+
8221022
/**
8231023
* @brief Compute k-means clustering and predicts cluster index for each sample
8241024
* in the input.

0 commit comments

Comments
 (0)