forked from rapidsai/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distributed index + answered part of the reviews
- Loading branch information
1 parent
646452c
commit db803cb
Showing
13 changed files
with
245 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
enum LegateRaftOpCode { | ||
_OP_CODE_BASE = 0, | ||
RAFT_KNN_OP = 1, | ||
RAFT_KNN = 1, | ||
RAFT_KNN_MERGE = 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ namespace // unnamed | |
legate_raft::Compute1NNTask::register_variants(); | ||
} | ||
|
||
} // namespace | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ namespace // unnamed | |
legate_raft::HistogramTask::register_variants(); | ||
} | ||
|
||
} // namespace | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdexcept> | ||
|
||
#include "../raft/raft_api.hpp" | ||
#include "../legate_raft.h" | ||
#include "../legate_library.h" | ||
|
||
namespace legate_raft { | ||
|
||
class RAFT_KNN_MERGE_TASK : public Task<RAFT_KNN_MERGE_TASK, RAFT_KNN_MERGE> { | ||
public: | ||
static void gpu_variant(legate::TaskContext& context) | ||
{ | ||
size_t n_samples = context.scalars()[0].value<int64_t>(); | ||
int n_parts = context.scalars()[1].value<int64_t>(); | ||
int k = context.scalars()[2].value<int64_t>(); | ||
|
||
auto& in_ind = context.inputs()[0]; | ||
auto& in_dist = context.inputs()[1]; | ||
auto& out_ind = context.outputs()[0]; | ||
auto& out_dist = context.outputs()[1]; | ||
|
||
auto in_ind_read = in_ind.read_accessor<int64_t, 2>().ptr(Legion::DomainPoint(0)); | ||
auto in_dist_read = in_dist.read_accessor<float, 2>().ptr(Legion::DomainPoint(0)); | ||
auto out_ind_write = out_ind.write_accessor<int64_t, 2>().ptr(Legion::DomainPoint(0)); | ||
auto out_dist_write = out_dist.write_accessor<float, 2>().ptr(Legion::DomainPoint(0)); | ||
|
||
raft_knn_merge(n_samples, | ||
n_parts, | ||
k, | ||
in_ind_read, | ||
in_dist_read, | ||
out_ind_write, | ||
out_dist_write); | ||
} | ||
}; | ||
|
||
} // namespace legate_raft | ||
|
||
namespace // unnamed | ||
{ | ||
|
||
static void __attribute__((constructor)) register_tasks(void) | ||
{ | ||
legate_raft::RAFT_KNN_MERGE_TASK::register_variants(); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 "raft_api.hpp" | ||
|
||
#include <cstdint> | ||
#include <raft/core/device_resources.hpp> | ||
#include <raft/core/mdspan_types.hpp> | ||
#include <raft/core/device_mdspan.hpp> | ||
#include <raft/distance/distance_types.hpp> | ||
#include <raft/neighbors/brute_force.cuh> | ||
|
||
#ifdef RAFT_COMPILED | ||
#include <raft/distance/specializations.cuh> | ||
#endif | ||
|
||
|
||
template<typename idx_t> | ||
void raft_knn_merge(size_t n_samples, | ||
int n_parts, | ||
int k, | ||
const idx_t* in_ind, | ||
const float* in_dist, | ||
idx_t* out_ind, | ||
float* out_dist) | ||
{ | ||
static raft::device_resources handle; | ||
|
||
auto in_keys = raft::device_matrix_view<const float, idx_t, raft::row_major>(in_dist, n_samples * n_parts, k); | ||
auto in_values = raft::device_matrix_view<const idx_t, idx_t, raft::row_major>(in_ind, n_samples * n_parts, k); | ||
auto out_keys = raft::device_matrix_view<float, idx_t, raft::row_major>(out_dist, n_samples, k); | ||
auto out_values = raft::device_matrix_view<idx_t, idx_t, raft::row_major>(out_ind, n_samples, k); | ||
|
||
raft::neighbors::brute_force::knn_merge_parts(handle, | ||
in_keys, | ||
in_values, | ||
out_keys, | ||
out_values, | ||
n_samples); | ||
|
||
} | ||
|
||
|
||
template void raft_knn_merge( | ||
size_t, | ||
int, | ||
int, | ||
const int64_t*, | ||
const float*, | ||
int64_t*, | ||
float*); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
from .knn import run_knn | ||
# Copyright 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. | ||
# | ||
|
||
from .knn import run_knn | ||
|
||
__all__ = ["run_knn"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters