Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: General binned group for seeding #2854

Merged
merged 158 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
9aff3d6
Config for ITk
Feb 18, 2022
35f0e13
Sync
Dec 5, 2022
9cd99b3
Sync
Dec 13, 2022
967d352
Sync
Dec 17, 2022
ae6c802
Sync
Jan 3, 2023
22951c2
Merge remote-tracking branch 'upstream/main'
Jan 12, 2023
9341df3
Sync
Feb 22, 2023
2b075ba
sync
Mar 7, 2023
448a8c4
sync
Mar 14, 2023
762a38a
Merge remote-tracking branch 'upstream/main'
Mar 22, 2023
e3a5ef6
Merge remote-tracking branch 'upstream/main'
Mar 25, 2023
3e0a86e
Merge remote-tracking branch 'upstream/main'
Mar 31, 2023
3311801
Merge remote-tracking branch 'upstream/main'
May 22, 2023
fa6ce27
Merge remote-tracking branch 'upstream/main'
Jun 14, 2023
791691d
Merge remote-tracking branch 'upstream/main'
Jun 27, 2023
3754f37
Merge remote-tracking branch 'upstream/main'
Jul 6, 2023
21c3837
Merge remote-tracking branch 'upstream/main' into main
Jul 9, 2023
b08dfc2
sync
Sep 1, 2023
867ec9c
sync
Oct 26, 2023
36d0c92
sync
Oct 31, 2023
9552ebc
First implementation
Nov 21, 2023
ae0724c
changes
Nov 22, 2023
f9d16c0
no future
Nov 23, 2023
501f16c
minor
Nov 23, 2023
6aa0a62
format
Nov 23, 2023
4326ed6
first round of tests
Nov 24, 2023
558efd5
sub iteration
Dec 12, 2023
cb8de3f
format
Dec 12, 2023
b9cf4cc
changes
Dec 12, 2023
70c7feb
format
Dec 12, 2023
a77b90b
format
Dec 12, 2023
02bf47b
format
Dec 12, 2023
b53dedd
test 1 for cuda
Dec 12, 2023
b8793b1
local, not global
Dec 12, 2023
bc77b3e
agains cuda
Dec 12, 2023
0f0b59d
and again format
Dec 12, 2023
bf60dfd
more tests for global iterator
Dec 12, 2023
e074e16
more tests and some bug fixing
Dec 12, 2023
1c55a27
oopsie
Dec 12, 2023
9179279
even more tests
Dec 13, 2023
a35da6d
remove line
Dec 13, 2023
773d11c
format
Dec 13, 2023
f7fdcb5
first round of comments
Dec 13, 2023
d5016b8
format
Dec 13, 2023
ec66bfa
test for checking iterations
Dec 13, 2023
9ea63ab
clang tidy
Dec 13, 2023
4772218
remove property
Dec 15, 2023
bc0aa70
First implementation
Nov 21, 2023
167756d
changes
Nov 22, 2023
b12d268
no future
Nov 23, 2023
cc20c8d
minor
Nov 23, 2023
5285668
format
Nov 23, 2023
7c9d4e4
first round of tests
Nov 24, 2023
5d7e2ab
sub iteration
Dec 12, 2023
e0d0fe7
format
Dec 12, 2023
309a0ef
changes
Dec 12, 2023
ab158e1
format
Dec 12, 2023
52b90cd
format
Dec 12, 2023
118db39
format
Dec 12, 2023
592183b
test 1 for cuda
Dec 12, 2023
c2ad48b
local, not global
Dec 12, 2023
57f8876
agains cuda
Dec 12, 2023
b1abea1
and again format
Dec 12, 2023
3e9599c
more tests for global iterator
Dec 12, 2023
0c70d03
more tests and some bug fixing
Dec 12, 2023
f759e1e
oopsie
Dec 12, 2023
63917d9
even more tests
Dec 13, 2023
3d31631
remove line
Dec 13, 2023
1bba1e9
format
Dec 13, 2023
bfe8e61
first round of comments
Dec 13, 2023
86af08d
format
Dec 13, 2023
d627255
test for checking iterations
Dec 13, 2023
bd7bd05
clang tidy
Dec 13, 2023
ec2fe30
move and rename
Dec 15, 2023
bcf7ec1
first working version
Dec 15, 2023
edc349b
changes
Dec 15, 2023
1da0f92
sync
Dec 15, 2023
e39777f
tests
Dec 16, 2023
73a5600
changes
Dec 16, 2023
cdce928
changes
Dec 16, 2023
c39a265
sync
Dec 16, 2023
65d249a
formta
Dec 16, 2023
ee1e504
Merge branch 'main' into removeSkipProperty
paulgessinger Dec 17, 2023
1c5cc86
cuda
Dec 18, 2023
4f64437
new methods and tests
Dec 18, 2023
601339e
Add comments
Dec 18, 2023
afa5acf
format
Dec 18, 2023
a325bc2
spelling
Dec 18, 2023
8b7374f
add protections
Dec 18, 2023
59eb33f
Core
Dec 18, 2023
c0f3253
first input check
Dec 18, 2023
ee18f0f
use asserts
Dec 18, 2023
072d184
typo
Dec 18, 2023
5df2442
bug
Dec 18, 2023
30565d7
to be reverted change
Dec 18, 2023
41a10bd
Update builds.yml
CarloVarni Dec 18, 2023
f0728e0
Protection against empty zbin neighbours in example seeding alg
CarloVarni Dec 18, 2023
04c9ba2
Update SeedingAlgorithm.cpp
CarloVarni Dec 18, 2023
1adf1a8
test
Dec 19, 2023
a3a772b
set default num phi neighbours to 1
Dec 19, 2023
dfe672f
update comment
Dec 19, 2023
3800426
format, license and spelling
Dec 19, 2023
63669c1
test with empty inputs
Dec 19, 2023
c5078f3
Merge remote-tracking branch 'upstream/main' into GenericBinFinder
Dec 19, 2023
623b3de
clang tidy
Dec 19, 2023
66f8342
test constructor
Dec 19, 2023
1b16b19
Merge remote-tracking branch 'upstream/main' into GenericBinFinder
Dec 21, 2023
31de7db
Merge remote-tracking branch 'origin/AddCommentsGridIterator' into Ge…
Dec 21, 2023
a079084
add other changes
Dec 21, 2023
62a0420
Move objects instead of copying
Dec 21, 2023
044bab2
reserve
Dec 21, 2023
bbea8dd
Merge remote-tracking branch 'origin/removeSkipProperty' into general…
Dec 21, 2023
a27f540
breaking changes
Dec 21, 2023
ad40814
First implementation
Dec 21, 2023
a1f6bae
Implementation and tests
Dec 21, 2023
006af4e
separate Filling
Dec 22, 2023
eafbb94
another test
Dec 22, 2023
2bd528d
sync
Dec 22, 2023
0b544ab
sync
Jan 8, 2024
b9e94c6
sync
Jan 9, 2024
3d474f7
copyright and typos
Jan 9, 2024
5e39602
test for boundary types
Jan 9, 2024
9e408e0
sync
Jan 10, 2024
baf80fa
sync
Jan 10, 2024
86b25ea
fix test and format
Jan 10, 2024
212e4ce
fix test and format
Jan 10, 2024
78feaee
copyright
Jan 10, 2024
a5c6e84
format
Jan 10, 2024
dfb08bd
from shared to unique and always request reference
Jan 11, 2024
8433591
minor changes
Jan 11, 2024
96ae871
format round
Jan 11, 2024
ee23896
first change for SYCL
Jan 11, 2024
93721f6
other SYCL changes
Jan 11, 2024
c302d3e
no idea
Jan 11, 2024
f273e4a
include tuple
Jan 11, 2024
c85782d
no general namespace
Jan 11, 2024
905d418
minor
Jan 11, 2024
2bc3bf5
DIM from grid
Jan 11, 2024
8dbb825
format
Jan 11, 2024
2659e7e
cuda first round
Jan 11, 2024
bf2e6af
another cuda round
Jan 11, 2024
7a7bf8e
third cuda round
Jan 11, 2024
754dd24
again cuda
Jan 11, 2024
351bb4c
oopsie
Jan 11, 2024
4d3c127
changes
Jan 11, 2024
074051b
and last format
Jan 11, 2024
053a033
Merge remote-tracking branch 'origin/main' into generalBinnedSPgroup
Jan 15, 2024
ec89adb
ops
Jan 15, 2024
c397e07
sync
Jan 15, 2024
45909e4
sync
Jan 16, 2024
0f5dfcf
ops
Jan 16, 2024
936d893
wrong include
Jan 17, 2024
5783034
address comments
Jan 17, 2024
90620c8
format
Jan 17, 2024
38c01ad
cuda test
Jan 17, 2024
96215ad
ops
Jan 17, 2024
01e57d8
changes
Jan 18, 2024
59ac19b
Merge branch 'main' into generalBinnedSPgroup
kodiakhq[bot] Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Core/include/Acts/Seeding/BinnedGroup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// 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/.

#pragma once

#include "Acts/Seeding/BinnedGroupIterator.hpp"
#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/GridBinFinder.hpp"
#include "Acts/Utilities/GridIterator.hpp"
#include "Acts/Utilities/Holders.hpp"

#include <memory>
#include <vector>

namespace Acts {

/// @class BinnedGroup
/// @tparam grid_t Type of the grid the group owns
///
/// The assumption is that the grid has ownership of the space points and
/// that the grid value_type (i.e. T in Grid<T, Axes ...>) is an iterable
/// object of space points, such as a vector< ... >
template <typename grid_t>
class BinnedGroup {
public:
friend BinnedGroupIterator<grid_t>;

static constexpr std::size_t DIM = grid_t::DIM;

/// @brief Default constructor
BinnedGroup() = delete;

/// brief Constructor
BinnedGroup(grid_t&& grid, const Acts::GridBinFinder<DIM>& bottomFinder,
const Acts::GridBinFinder<DIM>& topFinder,
std::array<std::vector<std::size_t>, DIM> navigation =
std::array<std::vector<std::size_t>, DIM>());

BinnedGroup(grid_t& grid, const Acts::GridBinFinder<DIM>& bottomFinder,
const Acts::GridBinFinder<DIM>& topFinder,
std::array<std::vector<std::size_t>, DIM> navigation =
std::array<std::vector<std::size_t>, DIM>()) = delete;

/// @brief Copy constructor
/// @param [in] other The BinnedGroup to copy
BinnedGroup(const BinnedGroup<grid_t>& other) = delete;
/// @brief Copy assignment
/// @param [in] other The BinnedGroup to copy
/// @return The copied BinnedGroup
BinnedGroup<grid_t>& operator=(const BinnedGroup<grid_t>& other) = delete;

/// @brief Move Constructor
/// @param [in] other The BinnedGroup to move
BinnedGroup(BinnedGroup<grid_t>&& other) noexcept = default;
/// @brief Move Assignment
/// @param [in] other The BinnedGroup to move
/// @return The moved BinnedGroup
BinnedGroup<grid_t>& operator=(BinnedGroup<grid_t>&& other) noexcept =
default;

/// @brief Default destructor
~BinnedGroup() = default;

/// @brief Retrieve const reference to the Grid
/// @return Const reference to the stored grid
const grid_t& grid() const;
/// @brief Retrieve mutable reference to the Grid
/// @return Mutable reference to the stored grid
grid_t& grid();

/// @brief Get the begin iterator
/// @return The iterator
Acts::BinnedGroupIterator<grid_t> begin() const;
/// @brief Get the end iterator
/// @return The iterator
Acts::BinnedGroupIterator<grid_t> end() const;

private:
/// @brief The N-dimentional grid
grid_t m_grid;
/// @brief The Grid Bin Finder for bottom candidates
const Acts::GridBinFinder<DIM>* m_bottomBinFinder{nullptr};
/// @brief The Grid Bin Finder for top candidates
const Acts::GridBinFinder<DIM>* m_topBinFinder{nullptr};
/// @brief Order of bins to loop over when searching for SPs
std::array<std::vector<std::size_t>, DIM> m_bins{};
};

} // namespace Acts

#include "Acts/Seeding/BinnedGroup.ipp"

namespace Acts {
template <typename external_spacepoint_t>
using BinnedSPGroup =
Acts::BinnedGroup<Acts::SpacePointGrid<external_spacepoint_t>>;
}
59 changes: 59 additions & 0 deletions Core/include/Acts/Seeding/BinnedGroup.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// 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/.

namespace Acts {

template <typename grid_t>
BinnedGroup<grid_t>::BinnedGroup(
grid_t&& grid,
const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& bottomFinder,
const Acts::GridBinFinder<Acts::BinnedGroup<grid_t>::DIM>& topFinder,
std::array<std::vector<std::size_t>, Acts::BinnedGroup<grid_t>::DIM>
navigation)
: m_grid(std::move(grid)),
m_bottomBinFinder(&bottomFinder),
m_topBinFinder(&topFinder),
m_bins(std::move(navigation)) {
/// If navigation is not defined for all axes, then we default that to a
/// std::iota from 1ul
std::array<std::size_t, DIM> numLocBins = m_grid.numLocalBins();
for (std::size_t i(0ul); i < DIM; ++i) {
if (!m_bins[i].empty()) {
continue;
}
m_bins[i].resize(numLocBins[i]);
std::iota(m_bins[i].begin(), m_bins[i].end(), 1ul);
}
}

template <typename grid_t>
const grid_t& BinnedGroup<grid_t>::grid() const {
return m_grid;
}

template <typename grid_t>
grid_t& BinnedGroup<grid_t>::grid() {
return m_grid;
}

template <typename grid_t>
Acts::BinnedGroupIterator<grid_t> BinnedGroup<grid_t>::begin() const {
return Acts::BinnedGroupIterator<grid_t>(
*this, std::array<std::size_t, Acts::BinnedGroup<grid_t>::DIM>(), m_bins);
}

template <typename grid_t>
Acts::BinnedGroupIterator<grid_t> BinnedGroup<grid_t>::end() const {
std::array<std::size_t, Acts::BinnedGroup<grid_t>::DIM> endline{};
for (std::size_t i(0ul); i < Acts::BinnedGroup<grid_t>::DIM; ++i) {
endline[i] = m_bins[i].size();
}
return Acts::BinnedGroupIterator<grid_t>(*this, endline, m_bins);
}

} // namespace Acts
128 changes: 128 additions & 0 deletions Core/include/Acts/Seeding/BinnedGroupIterator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// 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/.

#pragma once

#include "Acts/Seeding/SpacePointGrid.hpp"
#include "Acts/Utilities/GridIterator.hpp"
#include "Acts/Utilities/Holders.hpp"
#include "Acts/Utilities/detail/grid_helper.hpp"

#include <array>
#include <memory>
#include <tuple>

#include <boost/container/small_vector.hpp>

namespace Acts {
template <typename grid_t>
class BinnedGroup;

template <typename grid_t>
class BinnedGroupIterator {
public:
static constexpr std::size_t DIM = grid_t::DIM;

/// @brief Constructor
/// Never take the ownership of the group
///
/// @param [in] group The group we are iterating on
/// @param [in] index Current local position in the grid
/// @param [in] navigation The navigation pattern in the grid
BinnedGroupIterator(
Acts::BinnedGroup<grid_t>&& group, std::array<std::size_t, DIM> index,
std::array<std::vector<std::size_t>, DIM> navigation) = delete;

/// @brief Constructor
/// Never take the ownership of the group
///
/// @param [in] group The group we are iterating on
/// @param [in] index Current local position in the grid
/// @param [in] navigation The navigation pattern in the grid
BinnedGroupIterator(const Acts::BinnedGroup<grid_t>&& group,
std::array<std::size_t, DIM> index,
std::array<std::vector<std::size_t>, DIM> navigation) =
delete;

/// @brief Constructor
/// @param [in] group The group we are iterating on
/// @param [in] index Current local position in the grid
/// @param [in] navigation The navigation pattern in the grid
BinnedGroupIterator(const Acts::BinnedGroup<grid_t>& group,
std::array<std::size_t, DIM> index,
std::array<std::vector<std::size_t>, DIM> navigation);

/// Do not allow Copy operations

/// @brief Copy Constructor
/// @param [in] other The BinnedGroupIterator to copy
BinnedGroupIterator(const BinnedGroupIterator<grid_t>& other) = delete;
/// @brief Copy assignment
/// @param [in] other The BinnedGroupIterator to copy
/// @return The copied BinnedGroupIterator
BinnedGroupIterator<grid_t>& operator=(
const BinnedGroupIterator<grid_t>& other) = delete;

/// @brief Move Constructor
/// @param [in] other The BinnedGroupIterator to move
BinnedGroupIterator(BinnedGroupIterator<grid_t>&& other) noexcept = default;
/// @brief Move assignment
/// @param [in] other The BinnedGroupIterator to move
/// @return The moved BinnedGroupIterator
BinnedGroupIterator<grid_t>& operator=(BinnedGroupIterator&& other) noexcept =
default;

/// @brief Default Destructor
~BinnedGroupIterator() = default;

/// @brief Equality operator
/// @param [in] other The BinnedGroupIterator we are comparing against this one
/// @return The result of the comparison
bool operator==(const BinnedGroupIterator<grid_t>& other) const;
/// @brief (In-)Equality operator
/// @param [in] other The BinnedGroupIterator we are comparing against this one
/// @return The result of the comparison
bool operator!=(const BinnedGroupIterator<grid_t>& other) const;

/// @brief Increment the iterator by one (pre)
/// @return The incremented iterator
BinnedGroupIterator<grid_t>& operator++();

/// @brief Return the current bin with the middle candidate, as well as all the
/// bins with the possible bottom and top candidates
///
/// @return The collection of all the bins in the grid
std::tuple<boost::container::small_vector<std::size_t,
Acts::detail::ipow(3, grid_t::DIM)>,
std::size_t,
boost::container::small_vector<std::size_t,
Acts::detail::ipow(3, grid_t::DIM)>>
operator*() const;

private:
/// @brief Move to the next not-empty bin in the grid
void findNotEmptyBin();

private:
/// @brief The group that contains the grid and the bin finders
Acts::detail::RefHolder<const Acts::BinnedGroup<grid_t>> m_group{nullptr};
/// @brief Current N-dimentional grid iterator
typename grid_t::local_iterator_t m_gridItr;
/// @brief End iterator;
typename grid_t::local_iterator_t m_gridItrEnd;
};

} // namespace Acts

#include "Acts/Seeding/BinnedGroupIterator.ipp"

namespace Acts {
template <typename external_spacepoint_t>
using BinnedSPGroupIterator =
BinnedGroupIterator<Acts::SpacePointGrid<external_spacepoint_t>>;
}
90 changes: 90 additions & 0 deletions Core/include/Acts/Seeding/BinnedGroupIterator.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// 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/.

// Binned SP Group Iterator

template <typename grid_t>
Acts::BinnedGroupIterator<grid_t>::BinnedGroupIterator(
const Acts::BinnedGroup<grid_t>& group,
std::array<std::size_t, Acts::BinnedGroupIterator<grid_t>::DIM> index,
std::array<std::vector<std::size_t>, Acts::BinnedGroupIterator<grid_t>::DIM>
navigation)
: m_group(group), m_gridItr(group.grid(), index, navigation) {
std::array<std::size_t, DIM> endline{};
for (std::size_t i(0ul); i < DIM; ++i) {
endline[i] = navigation[i].size();
}
m_gridItrEnd = typename grid_t::local_iterator_t(m_group->grid(), endline,
std::move(navigation));
findNotEmptyBin();
}

template <typename grid_t>
bool Acts::BinnedGroupIterator<grid_t>::operator==(
const Acts::BinnedGroupIterator<grid_t>& other) const {
return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr;
}

template <typename grid_t>
bool Acts::BinnedGroupIterator<grid_t>::operator!=(
const Acts::BinnedGroupIterator<grid_t>& other) const {
return !(*this == other);
}

template <typename grid_t>
Acts::BinnedGroupIterator<grid_t>&
Acts::BinnedGroupIterator<grid_t>::operator++() {
++m_gridItr;
findNotEmptyBin();
return *this;
}

template <typename grid_t>
std::tuple<boost::container::small_vector<std::size_t,
Acts::detail::ipow(3, grid_t::DIM)>,
std::size_t,
boost::container::small_vector<std::size_t,
Acts::detail::ipow(3, grid_t::DIM)>>
Acts::BinnedGroupIterator<grid_t>::operator*() const {
/// Get the global and local position from current iterator. This is the bin
/// with the middle candidate And we know this is not an empty bin
std::array<std::size_t, DIM> localPosition = m_gridItr.localBinsIndices();
std::size_t global_index =
m_group->grid().globalBinFromLocalBins(localPosition);

/// Get the neighbouring bins
boost::container::small_vector<std::size_t, Acts::detail::ipow(3, DIM)>
bottoms =
m_group->m_bottomBinFinder->findBins(localPosition, m_group->grid());
boost::container::small_vector<std::size_t, Acts::detail::ipow(3, DIM)> tops =
m_group->m_topBinFinder->findBins(localPosition, m_group->grid());

// GCC12+ in Release throws an overread warning here due to the move.
// This is from inside boost code, so best we can do is to suppress it.
#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overread"
#endif
return std::make_tuple(std::move(bottoms), global_index, std::move(tops));
#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
}

template <typename grid_t>
void Acts::BinnedGroupIterator<grid_t>::findNotEmptyBin() {
if (m_gridItr == m_gridItrEnd) {
return;
}
/// Iterate on the grid till we find a not-empty bin
/// We start from the current bin configuration and move forward
std::size_t dimCollection = (*m_gridItr).size();
while (dimCollection == 0ul && ++m_gridItr != m_gridItrEnd) {
dimCollection = (*m_gridItr).size();
}
}
Loading
Loading