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

Device Clusterization Reorganization, main branch (2024.04.17.) #545

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ TRACCC_HOST_DEVICE inline void fill_spacepoint(spacepoint& sp,
const cell_module& module) {

// Transform measurement position to 3D
point3 local_3d = {meas.local[0], meas.local[1], 0.f};
point3 global = module.placement.point_to_global(local_3d);

// Fill spacepoint with this spacepoint
sp = {global, meas};
const point3 local_3d = {meas.local[0], meas.local[1], 0.f};
sp.global = module.placement.point_to_global(local_3d);
sp.meas = meas;
}

} // namespace traccc::details
8 changes: 5 additions & 3 deletions core/include/traccc/clusterization/impl/sparse_ccl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ TRACCC_HOST_DEVICE inline unsigned int make_union(
TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a,
const traccc::cell& b) {

return (a.channel0 - b.channel0) * (a.channel0 - b.channel0) <= 1 and
(a.channel1 - b.channel1) * (a.channel1 - b.channel1) <= 1 and
return (a.channel0 - b.channel0) * (a.channel0 - b.channel0) <= 1 &&
(a.channel1 - b.channel1) * (a.channel1 - b.channel1) <= 1 &&
a.module_link == b.module_link;
}

TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a,
const traccc::cell& b) {
return (a.channel1 - b.channel1) > 1 || a.module_link != b.module_link;

assert((a.channel1 >= b.channel1) || (a.module_link != b.module_link));
return (a.channel1 > (b.channel1 + 1)) || (a.module_link != b.module_link);
}

TRACCC_HOST_DEVICE inline unsigned int sparse_ccl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

// Library include(s).
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/spacepoint.hpp"
#include "traccc/utils/algorithm.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2022 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -12,8 +12,8 @@
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"

// System include(s).
#include <cstddef>
// VecMem include(s).
#include <vecmem/containers/data/vector_view.hpp>

namespace traccc::device {

Expand All @@ -32,12 +32,11 @@ TRACCC_HOST_DEVICE
inline void aggregate_cluster(
const cell_collection_types::const_device& cells,
const cell_module_collection_types::const_device& modules,
const vecmem::data::vector_view<unsigned short> f_view,
const unsigned int start, const unsigned int end, const unsigned short cid,
measurement& out, vecmem::data::vector_view<unsigned int> cell_links,
const unsigned int link);
const vecmem::data::vector_view<const unsigned short>& f_view,
unsigned int start, unsigned int end, unsigned short cid, measurement& out,
vecmem::data::vector_view<unsigned int> cell_links, unsigned int link);

} // namespace traccc::device

// Include the implementation.
#include "traccc/clusterization/device/impl/aggregate_cluster.ipp"
#include "traccc/clusterization/device/impl/aggregate_cluster.ipp"
63 changes: 49 additions & 14 deletions device/common/include/traccc/clusterization/device/ccl_kernel.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2022-2023 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -22,14 +22,48 @@

namespace traccc::device {

namespace {
namespace details {

/// These indices in clusterization will only range from 0 to
/// max_cells_per_partition, so we only need a short
using index_t = unsigned short;

static constexpr int TARGET_CELLS_PER_THREAD = 8;
static constexpr int MAX_CELLS_PER_THREAD = 12;
} // namespace

/// Helper struct for calculating some of the input parameters of @c ccl_kernel
struct ccl_kernel_helper {

/// Constructor setting the helper parameters
///
/// @param[in] target_cells_per_partition Target average number of cells per
/// thread block
/// @param[in] n_cells Total number of cells
///
ccl_kernel_helper(index_t target_cells_per_partition,
unsigned int n_cells) {

max_cells_per_partition =
(target_cells_per_partition * MAX_CELLS_PER_THREAD +
TARGET_CELLS_PER_THREAD - 1) /
TARGET_CELLS_PER_THREAD;
threads_per_partition =
(target_cells_per_partition + TARGET_CELLS_PER_THREAD - 1) /
TARGET_CELLS_PER_THREAD;
num_partitions = (n_cells + target_cells_per_partition - 1) /
target_cells_per_partition;
}

/// Maximum number of cells per partition
index_t max_cells_per_partition;
/// Number of threads per partition
unsigned int threads_per_partition;
/// Number of partitions
unsigned int num_partitions;

}; // struct ccl_kernel_helper

} // namespace details

/// Function which reads raw detector cells and turns them into measurements.
///
Expand All @@ -40,30 +74,31 @@ static constexpr int MAX_CELLS_PER_THREAD = 12;
/// @param[in] modules_view collection of modules to which the cells are linked
/// @param[in] max_cells_per_partition maximum number of cells per thread block
/// @param[in] target_cells_per_partition average number of cells per thread
/// block
/// block
/// @param partition_start partition start point for this thread block
/// @param partition_end partition end point for this thread block
/// @param outi number of measurements for this partition
/// @param f array of "parent" indices for all cells in this partition
/// @param gf array of "grandparent" indices for all cells in this partition
/// @param f_view array of "parent" indices for all cells in this partition
/// @param gf_view array of "grandparent" indices for all cells in this
/// partition
/// @param barrier A generic object for block-wide synchronisation
/// @param[out] measurements_view collection of measurements
/// @param[out] measurement_count number of measurements
/// @param[out] cell_links collection of links to measurements each cell is
/// put into
template <typename barrier_t>
TRACCC_DEVICE inline void ccl_kernel(
const index_t threadId, const index_t blckDim, const unsigned int blockId,
details::index_t threadId, details::index_t blckDim, unsigned int blockId,
const cell_collection_types::const_view cells_view,
const cell_module_collection_types::const_view modules_view,
const index_t max_cells_per_partition,
const index_t target_cells_per_partition, unsigned int& partition_start,
unsigned int& partition_end, unsigned int& outi, index_t* f, index_t* gf,
barrier_t& barrier, measurement_collection_types::view measurements_view,
unsigned int& measurement_count,
const details::index_t max_cells_per_partition,
const details::index_t target_cells_per_partition,
unsigned int& partition_start, unsigned int& partition_end,
unsigned int& outi, vecmem::data::vector_view<details::index_t> f_view,
vecmem::data::vector_view<details::index_t> gf_view, barrier_t& barrier,
measurement_collection_types::view measurements_view,
vecmem::data::vector_view<unsigned int> cell_links);

} // namespace traccc::device

// Include the implementation.
#include "traccc/clusterization/device/impl/ccl_kernel.ipp"
#include "traccc/clusterization/device/impl/ccl_kernel.ipp"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2022 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -9,15 +9,10 @@

// Project include(s).
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/device/fill_prefix_sum.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/spacepoint.hpp"

// Vecmem include(s).
#include <vecmem/containers/data/vector_view.hpp>
#include <vecmem/memory/memory_resource.hpp>

// System include(s).
#include <cstddef>

Expand All @@ -34,13 +29,13 @@ namespace traccc::device {
///
TRACCC_HOST_DEVICE
inline void form_spacepoints(
const std::size_t globalIndex,
std::size_t globalIndex,
measurement_collection_types::const_view measurements_view,
cell_module_collection_types::const_view modules_view,
const unsigned int measurement_count,
unsigned int measurement_count,
spacepoint_collection_types::view spacepoints_view);

} // namespace traccc::device

// Include the implementation.
#include "traccc/clusterization/device/impl/form_spacepoints.ipp"
#include "traccc/clusterization/device/impl/form_spacepoints.ipp"
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ TRACCC_HOST_DEVICE
inline void aggregate_cluster(
const cell_collection_types::const_device& cells,
const cell_module_collection_types::const_device& modules,
const vecmem::data::vector_view<unsigned short> f_view,
const vecmem::data::vector_view<const unsigned short>& f_view,
const unsigned int start, const unsigned int end, const unsigned short cid,
measurement& out, vecmem::data::vector_view<unsigned int> cell_links,
const unsigned int link) {

const vecmem::device_vector<unsigned short> f(f_view);
const vecmem::device_vector<const unsigned short> f(f_view);
vecmem::device_vector<unsigned int> cell_links_device(cell_links);

/*
Expand All @@ -40,8 +40,6 @@ inline void aggregate_cluster(

for (unsigned short j = cid; j < partition_size; j++) {

assert(j < f.size());

const unsigned int pos = j + start;
/*
* Terminate the process earlier if we have reached a cell sufficiently
Expand All @@ -58,26 +56,25 @@ inline void aggregate_cluster(
* is part of our cluster. In that case, we take its values
* for position and add them to our accumulators.
*/
if (f[j] == cid) {
if (f.at(j) == cid) {

if (this_cell.channel1 > maxChannel1) {
maxChannel1 = this_cell.channel1;
}

const float weight = details::signal_cell_modelling(
const scalar weight = traccc::details::signal_cell_modelling(
this_cell.activation, this_module);

if (weight > this_module.threshold) {
totalWeight += this_cell.activation;
totalWeight += weight;
const point2 cell_position =
details::position_from_cell(this_cell, this_module);
traccc::details::position_from_cell(this_cell, this_module);
const point2 prev = mean;
const point2 diff = cell_position - prev;

mean = prev + (weight / totalWeight) * diff;
for (char i = 0; i < 2; ++i) {
var[i] = var[i] +
weight * (diff[i]) * (cell_position[i] - mean[i]);
var[i] += weight * (diff[i]) * (cell_position[i] - mean[i]);
}
}

Expand All @@ -93,6 +90,7 @@ inline void aggregate_cluster(
}
}
if (totalWeight > static_cast<scalar>(0.)) {
#pragma unroll
for (char i = 0; i < 2; ++i) {
var[i] /= totalWeight;
}
Expand All @@ -110,6 +108,8 @@ inline void aggregate_cluster(
out.module_link = module_link;
// The following will need to be filled properly "soon".
out.meas_dim = 2u;
// Set a unique identifier for the measurement.
out.measurement_id = link;
}

} // namespace traccc::device
Loading
Loading