-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathunique.cc
More file actions
81 lines (70 loc) · 2.55 KB
/
unique.cc
File metadata and controls
81 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright 2022 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 "cunumeric/set/unique.h"
#include "cunumeric/set/unique_template.inl"
namespace cunumeric {
using namespace legate;
template <Type::Code CODE, int32_t DIM>
struct UniqueImplBody<VariantKind::CPU, CODE, DIM> {
using VAL = legate_type_of<CODE>;
void operator()(std::vector<Array>& outputs,
const AccessorRO<VAL, DIM>& in,
const Pitches<DIM - 1>& pitches,
const Rect<DIM>& rect,
const size_t volume,
const std::vector<comm::Communicator>& comms,
const DomainPoint& point,
const Domain& launch_domain,
const bool return_index,
const DomainPoint& parent_point)
{
auto& output = outputs[0];
if (return_index) {
std::set<ZippedIndex<VAL>, IndexEquality<VAL>> dedup_set;
for (size_t idx = 0; idx < volume; ++idx) {
auto p = pitches.unflatten(idx, rect.lo);
auto value = in[p];
int64_t index = rowwise_linearize(DIM, p, parent_point);
dedup_set.insert(ZippedIndex<VAL>({value, index}));
}
auto result = output.create_output_buffer<ZippedIndex<VAL>, 1>(dedup_set.size(), true);
size_t pos = 0;
for (auto e : dedup_set) { result[pos++] = e; }
} else {
std::set<VAL> dedup_set;
for (size_t idx = 0; idx < volume; ++idx) {
auto p = pitches.unflatten(idx, rect.lo);
dedup_set.insert(in[p]);
}
auto result = output.create_output_buffer<VAL, 1>(dedup_set.size(), true);
size_t pos = 0;
for (auto e : dedup_set) result[pos++] = e;
}
}
};
/*static*/ void UniqueTask::cpu_variant(TaskContext& context)
{
unique_template<VariantKind::CPU>(context);
}
namespace // unnamed
{
static void __attribute__((constructor)) register_tasks(void)
{
UniqueTask::register_variants(
{{LEGATE_GPU_VARIANT, legate::VariantOptions{}.with_concurrent(true)}});
}
} // namespace
} // namespace cunumeric