CLUEstering
High-performance density-based weighted clustering library developed at CERN
Loading...
Searching...
No Matches
Clusterer.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "CLUEstering/core/detail/CLUEAlpakaKernels.hpp"
8#include "CLUEstering/core/detail/defines.hpp"
11#include "CLUEstering/data_structures/Tiles.hpp"
12#include "CLUEstering/data_structures/internal/Followers.hpp"
13
14#include <cstdint>
15#include <vector>
16
17namespace clue {
18
24 template <uint8_t Ndim>
25 class Clusterer {
26 private:
27 using CoordinateExtremes = clue::CoordinateExtremes<Ndim>;
28 using PointsHost = clue::PointsHost<Ndim>;
29 using PointsDevice = clue::PointsDevice<Ndim, clue::Device>;
30 using TilesDevice = clue::TilesAlpaka<Ndim, clue::Device>;
31 using FollowersDevice = clue::Followers<clue::Device>;
32 using Acc = internal::Acc;
33 inline static constexpr auto reserve = detail::reserve;
34
35 float m_dc;
36 float m_seed_dc;
37 float m_rhoc;
38 float m_dm;
39 int m_pointsPerTile; // average number of points found in a tile
40 std::array<uint8_t, Ndim> m_wrappedCoordinates;
41
42 std::optional<TilesDevice> m_tiles;
43 std::optional<clue::device_buffer<Device, VecArray<int32_t, reserve>>> m_seeds;
44 std::optional<FollowersDevice> m_followers;
45 std::optional<PointsDevice> d_points;
46
47 void init_device(Queue& queue);
48 void init_device(Queue& queue, TilesDevice* tile_buffer);
49
50 void setupTiles(Queue& queue, const PointsHost& h_points);
51 void setupTiles(Queue& queue, const PointsDevice& d_points);
52
53 void setupFollowers(Queue& queue, int32_t n_points);
54
55 void setupPoints(const PointsHost& h_points, PointsDevice& dev_points, Queue& queue);
56
57 void setup(Queue& queue, const PointsHost& h_points, PointsDevice& dev_points) {
58 setupTiles(queue, h_points);
59 setupFollowers(queue, h_points.size());
60 setupPoints(h_points, dev_points, queue);
61 }
62
63 template <concepts::convolutional_kernel Kernel>
64 void make_clusters_impl(PointsHost& h_points,
65 PointsDevice& dev_points,
66 const Kernel& kernel,
67 Queue& queue,
68 std::size_t block_size);
69 template <concepts::convolutional_kernel Kernel>
70 void make_clusters_impl(PointsDevice& dev_points,
71 const Kernel& kernel,
72 Queue& queue,
73 std::size_t block_size);
74
75 public:
83 Clusterer(float dc, float rhoc, float dm, float seed_dc = -1.f, int pPBin = 128);
92 Clusterer(Queue& queue, float dc, float rhoc, float dm, float seed_dc = -1.f, int pPBin = 128);
102 Clusterer(Queue& queue,
103 TilesDevice* tile_buffer,
104 float dc,
105 float rhoc,
106 float dm,
107 float seed_dc = -1.f,
108 int pPBin = 128);
109
117 void setParameters(float dc, float rhoc, float dm, float seed_dc = -1.f, int pPBin = 128);
118
125 template <concepts::convolutional_kernel Kernel = FlatKernel>
126 void make_clusters(Queue& queue,
127 PointsHost& h_points,
128 const Kernel& kernel = FlatKernel{.5f},
129 std::size_t block_size = 256);
136 template <concepts::convolutional_kernel Kernel = FlatKernel>
137 void make_clusters(PointsHost& h_points,
138 const Kernel& kernel = FlatKernel{.5f},
139 std::size_t block_size = 256);
147 template <concepts::convolutional_kernel Kernel = FlatKernel>
148 void make_clusters(Queue& queue,
149 PointsHost& h_points,
150 PointsDevice& dev_points,
151 const Kernel& kernel = FlatKernel{.5f},
152 std::size_t block_size = 256);
160 template <concepts::convolutional_kernel Kernel = FlatKernel>
161 void make_clusters(PointsHost& h_points,
162 PointsDevice& dev_points,
163 const Kernel& kernel = FlatKernel{.5f},
164 std::size_t block_size = 256);
171 template <concepts::convolutional_kernel Kernel = FlatKernel>
172 void make_clusters(Queue& queue,
173 PointsDevice& dev_points,
174 const Kernel& kernel = FlatKernel{.5f},
175 std::size_t block_size = 256);
176
180 void setWrappedCoordinates(const std::array<uint8_t, Ndim>& wrappedCoordinates);
184 void setWrappedCoordinates(std::array<uint8_t, Ndim>&& wrappedCoordinates);
189 template <typename... TArgs>
190 void setWrappedCoordinates(TArgs... wrappedCoordinates);
191
196 std::vector<std::vector<int>> getClusters(const PointsHost& h_points);
197 };
198
199} // namespace clue
200
201#include "CLUEstering/core/detail/Clusterer.hpp"
Provides the PointsDevice class for managing points on a device.
Provides the PointsHost class for managing points in host memory.
Clusterer(float dc, float rhoc, float dm, float seed_dc=-1.f, int pPBin=128)
Constuct a Clusterer object.
void setWrappedCoordinates(TArgs... wrappedCoordinates)
Specify which coordinates are periodic.
void make_clusters(PointsHost &h_points, PointsDevice &dev_points, const Kernel &kernel=FlatKernel{.5f}, std::size_t block_size=256)
Construct the clusters from host and device points.
void make_clusters(Queue &queue, PointsDevice &dev_points, const Kernel &kernel=FlatKernel{.5f}, std::size_t block_size=256)
Construct the clusters from device points.
void setParameters(float dc, float rhoc, float dm, float seed_dc=-1.f, int pPBin=128)
Set the parameters for the clustering algorithm.
void setWrappedCoordinates(std::array< uint8_t, Ndim > &&wrappedCoordinates)
Specify which coordinates are periodic.
std::vector< std::vector< int > > getClusters(const PointsHost &h_points)
Get the clusters from the host points.
Clusterer(Queue &queue, TilesDevice *tile_buffer, float dc, float rhoc, float dm, float seed_dc=-1.f, int pPBin=128)
Constuct a Clusterer object.
void make_clusters(Queue &queue, PointsHost &h_points, PointsDevice &dev_points, const Kernel &kernel=FlatKernel{.5f}, std::size_t block_size=256)
Construct the clusters from host and device points.
Clusterer(Queue &queue, float dc, float rhoc, float dm, float seed_dc=-1.f, int pPBin=128)
Constuct a Clusterer object.
void setWrappedCoordinates(const std::array< uint8_t, Ndim > &wrappedCoordinates)
Specify which coordinates are periodic.
void make_clusters(Queue &queue, PointsHost &h_points, const Kernel &kernel=FlatKernel{.5f}, std::size_t block_size=256)
Construct the clusters from host points.
void make_clusters(PointsHost &h_points, const Kernel &kernel=FlatKernel{.5f}, std::size_t block_size=256)
Construct the clusters from host points.
Definition Tiles.hpp:22
The FlatKernel class implements a flat kernel for convolution. It returns a constant value for the ke...
Definition ConvolutionalKernel.hpp:13
The PointsDevice class is a data structure that manages points on a device. It provides methods to al...
Definition PointsDevice.hpp:25
The PointsHost class is a data structure that manages points in host memory. It provides methods to a...
Definition PointsHost.hpp:22
ALPAKA_FN_HOST int32_t size() const
Returns the number of points.
Definition Tiles.hpp:138