Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public API and tests for hierarchical balanced k-means #1113

Merged
merged 53 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8930877
Add kmeans balanced public API and modify benchmark
Nyrio Dec 14, 2022
1b66ae0
kmeans_balanced unit test
Nyrio Dec 14, 2022
9efbd30
Add support for double
Nyrio Dec 15, 2022
876ed4e
Don't pass redundant stream argument when passing handle
Nyrio Dec 15, 2022
0f3ab9b
Replace uint32_t with IdxT where relevant
Nyrio Dec 15, 2022
289270d
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Dec 15, 2022
6a57b5e
Use core operators
Nyrio Dec 15, 2022
ef7ffbf
Add parameter structure for kmeans balanced, fix integer type issues,…
Nyrio Dec 16, 2022
c1c1faa
Testing and cleanup
Nyrio Dec 19, 2022
0bc3143
Add test cases for conversion + fix bug
Nyrio Dec 19, 2022
4622f1f
Document k-means balanced API
Nyrio Dec 19, 2022
f32b7f6
Use new API in IVF-Flat and IVF-PQ, remove old API
Nyrio Dec 20, 2022
77ab474
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 4, 2023
b61d8a8
Casting to avoid template type inference failures
Nyrio Jan 4, 2023
c18b292
Snake-case kmeans_balanced_params
Nyrio Jan 9, 2023
78773a9
View fixes
Nyrio Jan 9, 2023
d493ded
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 9, 2023
2f1fa20
Post-merge fix
Nyrio Jan 9, 2023
80d715b
Avoid applying mapping twice and assume identity when data and math t…
Nyrio Jan 12, 2023
f17fbd1
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 12, 2023
7edb3b1
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 17, 2023
0d04d4d
Add use-case examples to build_clusters and calc_centers_and_sizes
Nyrio Jan 17, 2023
a0c9421
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 20, 2023
6d791d7
Documentation improvements + remove verbosity params (should use set_…
Nyrio Jan 23, 2023
89836d9
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 23, 2023
82d1f14
Replace copy_selected with matrix::gather where possible
Nyrio Jan 23, 2023
c5aff02
Fix unsigned / signed integer comparisons
Nyrio Jan 23, 2023
8705e3a
Put build_clusters and calc_centers_and_sizes in a helpers namespace
Nyrio Jan 23, 2023
1a77a09
Change order of args in public API for consistency
Nyrio Jan 23, 2023
a6232a2
Enabling shallow copy of handle/device_resources
cjnolet Jan 24, 2023
32af7f0
Adding copy constructor to handle/device_resources that enables a dif…
cjnolet Jan 24, 2023
234f004
Merge remote-tracking branch 'cjnolet/imp-2302-resources_copy' into f…
Nyrio Jan 24, 2023
1c03a46
Don't expose memory resource in public API, use handle instead
Nyrio Jan 24, 2023
3073672
Add base class for shared k-means parameters + add explanation of the…
Nyrio Jan 24, 2023
d07bb66
De-duplicate mod_op and modulo_op
Nyrio Jan 24, 2023
d76877a
Replace modulo_op with mod_op (bis)
Nyrio Jan 24, 2023
30fd8f2
Fix changes lost in bad merge
Nyrio Jan 24, 2023
7a163fa
Doxygen fixes
Nyrio Jan 24, 2023
a25df21
Fix use of is_floating_point_v
Nyrio Jan 24, 2023
5166503
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 25, 2023
7372f80
mesocluster_size_max_balanced should be IdxT, not uint32_t
Nyrio Jan 25, 2023
88eef79
For some reason my local clang-format seems to disagree with the pre-…
Nyrio Jan 25, 2023
4b41d41
Change edge case that breaks checks
Nyrio Jan 25, 2023
a829fef
Include minClusterAndDistance in batch size calculation
Nyrio Jan 25, 2023
7d399db
Merge remote-tracking branch 'origin/branch-23.02' into fea-kmeans-ba…
Nyrio Jan 26, 2023
2d78a50
Remove write_only_op helper s we can now use map_offset
Nyrio Jan 26, 2023
f262406
Replace handle_t with device_resources
Nyrio Jan 26, 2023
39e55eb
Fix missing includes
Nyrio Jan 26, 2023
4e6704c
Merge branch 'branch-23.02' into fea-kmeans-balanced-api
Nyrio Jan 27, 2023
02feb04
Merge branch 'branch-23.02' into fea-kmeans-balanced-api
cjnolet Jan 27, 2023
462fa66
Merge branch 'branch-23.02' into fea-kmeans-balanced-api
cjnolet Jan 27, 2023
6c73586
Add test with more rows to test memory footprint to some extent
Nyrio Jan 30, 2023
55fcb1f
Merge branch 'branch-23.02' into fea-kmeans-balanced-api
cjnolet Jan 31, 2023
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 .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ concurrency:
jobs:
cpp-build:
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-matrix-build.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-build.yaml@cuda-118
with:
build_type: ${{ inputs.build_type || 'branch' }}
branch: ${{ inputs.branch }}
Expand All @@ -37,7 +37,7 @@ jobs:
python-build:
needs: [cpp-build]
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-matrix-build.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-build.yaml@cuda-118
with:
build_type: ${{ inputs.build_type || 'branch' }}
branch: ${{ inputs.branch }}
Expand All @@ -46,7 +46,7 @@ jobs:
upload-conda:
needs: [cpp-build, python-build]
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-upload-packages.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-upload-packages.yaml@cuda-118
with:
build_type: ${{ inputs.build_type || 'branch' }}
branch: ${{ inputs.branch }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ jobs:
- wheel-build-raft-dask
- wheel-tests-raft-dask
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/pr-builder.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/pr-builder.yaml@cuda-118
checks:
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/checks.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/checks.yaml@cuda-118
conda-cpp-build:
needs: checks
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-matrix-build.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-build.yaml@cuda-118
with:
build_type: pull-request
node_type: cpu16
conda-cpp-tests:
needs: conda-cpp-build
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-tests.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-tests.yaml@cuda-118
with:
build_type: pull-request
conda-python-build:
needs: conda-cpp-build
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-matrix-build.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-build.yaml@cuda-118
with:
build_type: pull-request
conda-python-tests:
needs: conda-python-build
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-tests.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-tests.yaml@cuda-118
with:
build_type: pull-request
wheel-build-pylibraft:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ on:
jobs:
conda-cpp-tests:
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-tests.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-cpp-tests.yaml@cuda-118
with:
build_type: nightly
branch: ${{ inputs.branch }}
date: ${{ inputs.date }}
sha: ${{ inputs.sha }}
conda-python-tests:
secrets: inherit
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-tests.yaml@main
uses: rapidsai/shared-action-workflows/.github/workflows/conda-python-tests.yaml@cuda-118
with:
build_type: nightly
branch: ${{ inputs.branch }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Several CMake targets can be made available by adding components in the table be
The easiest way to build RAFT from source is to use the `build.sh` script at the root of the repository:
1. Create an environment with the needed dependencies:
```
mamba env create --name raft_dev_env -f conda/environments/all_cuda-115_arch-x86_64.yaml
mamba env create --name raft_dev_env -f conda/environments/all_cuda-118_arch-x86_64.yaml
mamba activate raft_dev_env
```
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ dependencies:
- clang-tools=11.1.0
- clang=11.1.0
- cmake>=3.23.1,!=3.25.0
- cuda-profiler-api>=11.4.240,<=11.8.86
- cuda-profiler-api=11.8.86
- cuda-python >=11.7.1,<12.0
- cudatoolkit=11.5
- cudatoolkit=11.8
- cupy
- cxx-compiler
- cython>=0.29,<0.30
- dask-cuda=23.02.*
- dask-cuda=23.02
- dask>=2022.12.0
- distributed>=2022.12.0
- doxygen>=1.8.20
- faiss-proc=*=cuda
- gcc_linux-64=9.*
- libcublas-dev>=11.7.3.1,<=11.7.4.6
- libcublas>=11.7.3.1,<=11.7.4.6
- libcurand-dev>=10.2.6.48,<=10.2.7.107
- libcurand>=10.2.6.48,<=10.2.7.107
- libcusolver-dev>=11.2.1.48,<=11.3.2.107
- libcusolver>=11.2.1.48,<=11.3.2.107
- libcusparse-dev>=11.7.0.31,<=11.7.0.107
- libcusparse>=11.7.0.31,<=11.7.0.107
- libfaiss>=1.7.0=cuda*
- gcc_linux-64=9
- libcublas-dev=11.11.3.6
- libcublas=11.11.3.6
- libcurand-dev=10.3.0.86
- libcurand=10.3.0.86
- libcusolver-dev=11.4.1.48
- libcusolver=11.4.1.48
- libcusparse-dev=11.7.5.86
- libcusparse=11.7.5.86
- libfaiss>=1.7.1=cuda*
- ninja
- pytest
- pytest-cov
- rmm=23.02.*
- rmm=23.02
- scikit-build>=0.13.1
- scikit-learn
- scipy
- sphinx-markdown-tables
- sysroot_linux-64==2.17
- ucx-proc=*=gpu
- ucx-py=0.30.*
- ucx-py=0.30
- ucx>=1.13.0
name: all_cuda-115_arch-x86_64
name: all_cuda-118_arch-x86_64
22 changes: 11 additions & 11 deletions conda/recipes/libraft/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,42 @@ gtest_version:
- "=1.10.0"

libfaiss_version:
- "1.7.0 *_cuda"
- "1.7.2 *_cuda"

# The CTK libraries below are missing from the conda-forge::cudatoolkit
# package. The "*_host_*" version specifiers correspond to `11.5` packages and the
# package. The "*_host_*" version specifiers correspond to `11.8` packages and the
# "*_run_*" version specifiers correspond to `11.x` packages.

libcublas_host_version:
- ">=11.7.3.1,<=11.7.4.6"
- "=11.11.3.6"

libcublas_run_version:
- ">=11.5.2.43,<=11.11.3.6"
- ">=11.5.2.43,<12.0.0"

libcurand_host_version:
- ">=10.2.6.48,<=10.2.7.107"
- "=10.3.0.86"

libcurand_run_version:
- ">=10.2.5.43,<=10.3.0.86"
- ">=10.2.5.43,<10.3.1"

libcusolver_host_version:
- ">=11.2.1.48,<=11.3.2.107"
- "=11.4.1.48"

libcusolver_run_version:
- ">=11.2.0.43,<=11.4.1.48"
- ">=11.2.0.43,<11.4.2"

libcusparse_host_version:
- ">=11.7.0.31,<=11.7.0.107"
- "=11.7.5.86"

libcusparse_run_version:
- ">=11.6.0.43,<=11.7.5.86"
- ">=11.6.0.43,<12.0.0"

# `cuda-profiler-api` only has `11.8.0` and `12.0.0` packages for all
# architectures. The "*_host_*" version specifiers correspond to `11.8` packages and the
# "*_run_*" version specifiers correspond to `11.x` packages.

cuda_profiler_api_host_version:
- ">=11.8.86,<12"
- "=11.8.86"

cuda_profiler_api_run_version:
- ">=11.4.240,<12"
9 changes: 6 additions & 3 deletions cpp/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -32,6 +32,7 @@ function(ConfigureBench)
PRIVATE raft::raft
$<$<BOOL:${ConfigureBench_DIST}>:raft::distance>
$<$<BOOL:${ConfigureBench_NN}>:raft::nn>
GTest::gtest
benchmark::benchmark
Threads::Threads
$<TARGET_NAME_IF_EXISTS:OpenMP::OpenMP_CXX>
Expand Down Expand Up @@ -102,7 +103,10 @@ if(BUILD_BENCH)
bench/main.cpp
)

ConfigureBench(NAME MATRIX_BENCH PATH bench/matrix/argmin.cu bench/main.cpp)
ConfigureBench(
NAME MATRIX_BENCH PATH bench/matrix/argmin.cu bench/matrix/gather.cu bench/matrix/select_k.cu
bench/main.cpp
)

ConfigureBench(
NAME RANDOM_BENCH PATH bench/random/make_blobs.cu bench/random/permute.cu bench/random/rng.cu
Expand All @@ -126,7 +130,6 @@ if(BUILD_BENCH)
bench/neighbors/knn/ivf_pq_int8_t_int64_t.cu
bench/neighbors/knn/ivf_pq_uint8_t_uint32_t.cu
bench/neighbors/refine.cu
bench/neighbors/selection.cu
bench/main.cpp
OPTIONAL
DIST
Expand Down
17 changes: 7 additions & 10 deletions cpp/bench/matrix/argmin.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,11 @@
#include <common/benchmark.hpp>
#include <raft/matrix/argmin.cuh>
#include <raft/random/rng.cuh>
#include <raft/util/itertools.hpp>

#include <rmm/device_uvector.hpp>

namespace raft::bench::linalg {
namespace raft::bench::matrix {

template <typename IdxT>
struct ArgminParams {
Expand Down Expand Up @@ -57,15 +58,11 @@ struct Argmin : public fixture {
raft::device_vector<OutT, IdxT> indices;
}; // struct Argmin

const std::vector<ArgminParams<int64_t>> argmin_inputs_i64{
{1000, 64}, {1000, 128}, {1000, 256}, {1000, 512}, {1000, 1024},
{10000, 64}, {10000, 128}, {10000, 256}, {10000, 512}, {10000, 1024},
{100000, 64}, {100000, 128}, {100000, 256}, {100000, 512}, {100000, 1024},
{1000000, 64}, {1000000, 128}, {1000000, 256}, {1000000, 512}, {1000000, 1024},
{10000000, 64}, {10000000, 128}, {10000000, 256}, {10000000, 512}, {10000000, 1024},
};
const std::vector<ArgminParams<int64_t>> argmin_inputs_i64 =
raft::util::itertools::product<ArgminParams<int64_t>>({1000, 10000, 100000, 1000000, 10000000},
{64, 128, 256, 512, 1024});

RAFT_BENCH_REGISTER((Argmin<float, uint32_t, int64_t>), "", argmin_inputs_i64);
RAFT_BENCH_REGISTER((Argmin<double, uint32_t, int64_t>), "", argmin_inputs_i64);

} // namespace raft::bench::linalg
} // namespace raft::bench::matrix
101 changes: 101 additions & 0 deletions cpp/bench/matrix/gather.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <common/benchmark.hpp>
#include <raft/matrix/gather.cuh>
#include <raft/random/rng.cuh>
#include <raft/util/itertools.hpp>

#include <rmm/device_uvector.hpp>

namespace raft::bench::matrix {

template <typename IdxT>
struct GatherParams {
IdxT rows, cols, map_length;
};

template <typename IdxT>
inline auto operator<<(std::ostream& os, const GatherParams<IdxT>& p) -> std::ostream&
{
os << p.rows << "#" << p.cols << "#" << p.map_length;
return os;
}

template <typename T, typename MapT, typename IdxT, bool Conditional = false>
struct Gather : public fixture {
Gather(const GatherParams<IdxT>& p) : params(p) {}

void allocate_data(const ::benchmark::State& state) override
{
matrix = raft::make_device_matrix<T, IdxT>(handle, params.rows, params.cols);
map = raft::make_device_vector<MapT, IdxT>(handle, params.map_length);
out = raft::make_device_matrix<T, IdxT>(handle, params.map_length, params.cols);
stencil = raft::make_device_vector<T, IdxT>(handle, Conditional ? params.map_length : IdxT(0));

raft::random::RngState rng{1234};
raft::random::uniform(
rng, matrix.data_handle(), params.rows * params.cols, T(-1), T(1), stream);
raft::random::uniformInt(
handle, rng, map.data_handle(), params.map_length, (MapT)0, (MapT)params.rows);
if constexpr (Conditional) {
raft::random::uniform(rng, stencil.data_handle(), params.map_length, T(-1), T(1), stream);
}
handle.sync_stream(stream);
}

void run_benchmark(::benchmark::State& state) override
{
std::ostringstream label_stream;
label_stream << params;
state.SetLabel(label_stream.str());

loop_on_state(state, [this]() {
auto matrix_const_view = raft::make_device_matrix_view<const T, IdxT, row_major>(
matrix.data_handle(), matrix.extent(0), matrix.extent(1));
auto map_const_view =
raft::make_device_vector_view<const MapT, IdxT>(map.data_handle(), map.extent(0));
if constexpr (Conditional) {
auto stencil_const_view =
raft::make_device_vector_view<const T, IdxT>(stencil.data_handle(), stencil.extent(0));
auto pred_op = raft::plug_const_op(T(0.0), raft::greater_op());
raft::matrix::gather_if(
handle, matrix_const_view, out.view(), map_const_view, stencil_const_view, pred_op);
} else {
raft::matrix::gather(handle, matrix_const_view, map_const_view, out.view());
}
});
}

private:
GatherParams<IdxT> params;
raft::device_matrix<T, IdxT> matrix, out;
raft::device_vector<T, IdxT> stencil;
raft::device_vector<MapT, IdxT> map;
}; // struct Gather

template <typename T, typename MapT, typename IdxT>
using GatherIf = Gather<T, MapT, IdxT, true>;

const std::vector<GatherParams<int64_t>> gather_inputs_i64 =
raft::util::itertools::product<GatherParams<int64_t>>(
{1000000}, {10, 20, 50, 100, 200, 500}, {1000, 10000, 100000, 1000000});

RAFT_BENCH_REGISTER((Gather<float, uint32_t, int64_t>), "", gather_inputs_i64);
RAFT_BENCH_REGISTER((Gather<double, uint32_t, int64_t>), "", gather_inputs_i64);
RAFT_BENCH_REGISTER((GatherIf<float, uint32_t, int64_t>), "", gather_inputs_i64);
RAFT_BENCH_REGISTER((GatherIf<double, uint32_t, int64_t>), "", gather_inputs_i64);
} // namespace raft::bench::matrix
Loading