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> d_tiles;
43 std::optional<clue::device_buffer<Device, VecArray<int32_t, reserve>>> d_seeds;
44 std::optional<FollowersDevice> d_followers;
45 std::optional<PointsDevice> d_points;
46
47 TilesAlpakaView<Ndim>* m_tiles;
48 VecArray<int32_t, reserve>* m_seeds;
49 FollowersView* m_followers;
50
51 void init_device(Queue& queue);
52 void init_device(Queue& queue, TilesDevice* tile_buffer);
53
54 void setupTiles(Queue& queue, const PointsHost& h_points);
55 void setupTiles(Queue& queue, const PointsDevice& d_points);
56
57 void setupFollowers(Queue& queue, int32_t n_points);
58
59 void setupPoints(const PointsHost& h_points, PointsDevice& dev_points, Queue& queue);
60
61 void setup(Queue& queue, const PointsHost& h_points, PointsDevice& dev_points) {
62 setupTiles(queue, h_points);
63 setupFollowers(queue, h_points.size());
64 setupPoints(h_points, dev_points, queue);
65 }
66
67 void calculate_tile_size(CoordinateExtremes* min_max,
68 float* tile_sizes,
69 const PointsHost& h_points,
70 int32_t nPerDim);
71 void calculate_tile_size(Queue& queue,
72 CoordinateExtremes* min_max,
73 float* tile_sizes,
74 const PointsDevice& dev_points,
75 uint32_t nPerDim);
76
77 template <typename KernelType>
78 void make_clusters_impl(PointsHost& h_points,
79 PointsDevice& dev_points,
80 const KernelType& kernel,
81 Queue& queue,
82 std::size_t block_size);
83 template <typename KernelType>
84 void make_clusters_impl(PointsDevice& dev_points,
85 const KernelType& kernel,
86 Queue& queue,
87 std::size_t block_size);
88
89 public:
97 Clusterer(float dc, float rhoc, float dm, float seed_dc = -1.f, int pPBin = 128);
106 Clusterer(Queue& queue, float dc, float rhoc, float dm, float seed_dc = -1.f, int pPBin = 128);
116 Clusterer(Queue& queue,
117 TilesDevice* tile_buffer,
118 float dc,
119 float rhoc,
120 float dm,
121 float seed_dc = -1.f,
122 int pPBin = 128);
123
130 template <typename KernelType>
131 void make_clusters(PointsHost& h_points,
132 const KernelType& kernel,
133 Queue& queue,
134 std::size_t block_size);
140 template <typename KernelType>
141 void make_clusters(PointsHost& h_points, const KernelType& kernel, std::size_t block_size);
149 template <typename KernelType>
150 void make_clusters(PointsHost& h_points,
151 PointsDevice& dev_points,
152 const KernelType& kernel,
153 Queue& queue,
154 std::size_t block_size);
161 template <typename KernelType>
162 void make_clusters(PointsHost& h_points,
163 PointsDevice& dev_points,
164 const KernelType& kernel,
165 std::size_t block_size);
172 template <typename KernelType>
173 void make_clusters(PointsDevice& dev_points,
174 const KernelType& kernel,
175 Queue& queue,
176 std::size_t block_size);
177
181 void setWrappedCoordinates(const std::array<uint8_t, Ndim>& wrappedCoordinates);
185 void setWrappedCoordinates(std::array<uint8_t, Ndim>&& wrappedCoordinates);
190 template <typename... TArgs>
191 void setWrappedCoordinates(TArgs... wrappedCoordinates);
192
197 std::vector<std::vector<int>> getClusters(const PointsHost& h_points);
198 };
199
200} // namespace clue
201
202#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 make_clusters(PointsDevice &dev_points, const KernelType &kernel, Queue &queue, std::size_t block_size)
Construct the clusters from device points.
void make_clusters(PointsHost &h_points, const KernelType &kernel, Queue &queue, std::size_t block_size)
Construct the clusters from host points.
void setWrappedCoordinates(TArgs... wrappedCoordinates)
Specify which coordinates are periodic.
void make_clusters(PointsHost &h_points, PointsDevice &dev_points, const KernelType &kernel, std::size_t block_size)
Construct the clusters from host and device points.
void make_clusters(PointsHost &h_points, const KernelType &kernel, std::size_t block_size)
Construct the clusters from host points.
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.
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(PointsHost &h_points, PointsDevice &dev_points, const KernelType &kernel, Queue &queue, std::size_t block_size)
Construct the clusters from host and device points.
Definition Tiles.hpp:24
The PointsDevice class is a data structure that manages points on a device. It provides methods to al...
Definition PointsDevice.hpp:27
The PointsHost class is a data structure that manages points in host memory. It provides methods to a...
Definition PointsHost.hpp:24
Definition Tiles.hpp:140
Definition Tiles.hpp:42