-
Notifications
You must be signed in to change notification settings - Fork 1
/
centroid_update_factory.hpp
130 lines (113 loc) · 3.92 KB
/
centroid_update_factory.hpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
*
* Copyright (c) 2016, Lutz, Clemens <[email protected]>
*/
#ifndef CENTROID_UPDATE_FACTORY_HPP
#define CENTROID_UPDATE_FACTORY_HPP
#include "centroid_update_configuration.hpp"
#include "measurement/measurement.hpp"
#include "cl_kernels/centroid_update_feature_sum.hpp"
#include "cl_kernels/centroid_update_feature_sum_pardim.hpp"
#include "cl_kernels/centroid_update_cluster_merge.hpp"
#include <functional>
#include <string>
#include <stdexcept>
#include <boost/compute/core.hpp>
#include <boost/compute/iterator/buffer_iterator.hpp>
namespace Clustering {
template <typename PointT, typename LabelT, typename MassT, bool ColMajor>
class CentroidUpdateFactory {
public:
template <typename T>
using BufferIterator = boost::compute::buffer_iterator<T>;
using CentroidUpdateFunction = std::function<
boost::compute::event(
boost::compute::command_queue queue,
size_t num_features,
size_t num_points,
size_t num_clusters,
BufferIterator<PointT> points_begin,
BufferIterator<PointT> points_end,
BufferIterator<PointT> centroids_begin,
BufferIterator<PointT> centroids_end,
BufferIterator<LabelT> labels_begin,
BufferIterator<LabelT> labels_end,
BufferIterator<MassT> masses_begin,
BufferIterator<MassT> masses_end,
Measurement::DataPoint& datapoint,
boost::compute::wait_list const& events
)
>;
CentroidUpdateFunction create(
boost::compute::context context,
CentroidUpdateConfiguration config,
Measurement::Measurement& measurement
)
{
measurement.set_parameter(
"CentroidUpdateGlobalSize",
std::to_string(config.global_size[0])
);
measurement.set_parameter(
"CentroidUpdateLocalSize",
std::to_string(config.local_size[0])
);
if (
config.strategy == "cluster_merge" ||
config.strategy == "feature_sum_pardim"
)
{
measurement.set_parameter(
"CentroidUpdateVectorLength",
std::to_string(config.vector_length)
);
}
if (config.strategy == "feature_sum") {
CentroidUpdateFeatureSum<
PointT,
LabelT,
MassT,
ColMajor>
strategy;
strategy.prepare(context, config);
return strategy;
}
else if (config.strategy == "feature_sum_pardim") {
measurement.set_parameter(
"CentroidUpdateLocalFeatures",
std::to_string(config.local_features)
);
measurement.set_parameter(
"CentroidUpdateThreadFeatures",
std::to_string(config.thread_features)
);
CentroidUpdateFeatureSumPardim<
PointT,
LabelT,
MassT,
ColMajor>
strategy;
strategy.prepare(context, config);
return strategy;
}
else if (config.strategy == "cluster_merge") {
CentroidUpdateClusterMerge<
PointT,
LabelT,
MassT,
ColMajor>
strategy;
strategy.prepare(context, config);
return strategy;
}
else {
throw std::invalid_argument(config.strategy);
}
}
};
}
#endif /* CENTROID_UPDATE_FACTORY_HPP */