Skip to content

Commit 4314df2

Browse files
m-brettellMarkbwynneHEP
authored
Integration of the GBTS kernels in traccc (#1150)
* Adding layer binning kernels and gbts algo/config * file organization * changing GBTS config inputs * GBTS config improvments * data struture updtae * Memory access fixes to layer binning kernels * correct layer binning bad eta width * added sp skiping based on cluster width * Adding graph making kernels * Cluster widthless graph building kernels cut fixes * seeds extracted! * reverting traccc version * fixes for seed extraction * cut fixes * refactor covarience matrix access for GBTS * Tyiding, constants and array->vector * cluster width cut re-tuning * remove cw testing * node type fixes * add option to turn off tau cut * handeling no seeds found * Fixes to cluster_diameter calculation for GBTS * cut tunings for GBTS * Fixing rebase artifacts * formating fixes for GBTS * indent fixes * Adding layer binning kernels and gbts algo/config * re-organizing files and type fixing * changing GBTS config inputs * GBTS config improvments * data struture updtae * Memory access fixes to layer binning kernels * correct layer binning bad eta width * added sp skiping based on cluster width * Adding graph making kernels * Cluster widthless graph building kernels cut fixes * seeds extracted! * reverting traccc version * fixes for seed extraction * cut fixes * refactor covarience matrix access for GBTS * Tyiding, constants and array->vector * cluster width cut re-tuning * remove cw testing * node type fixes * add option to turn off tau cut * handeling no seeds found * Fixes to cluster_diameter calculation for GBTS * cut tunings for GBTS * cleaning merge artifacts * Getting good graph/seed stats * Adding graph building and seed extraction * remove artifact of traccc versison update * Small fix to allow the branch to compile (#3) I assume these int casts are harmless, unless our detector geometry is way bigger than I thought... * removing merge artifacts * tyding and configurable tau cut * Wsign-conversion fixes * more conversion fixes * formating * more formating * rebase fixes --------- Co-authored-by: Mark <[email protected]> Co-authored-by: Benjamin Wynne <[email protected]>
1 parent 0f6a931 commit 4314df2

File tree

9 files changed

+2771
-0
lines changed

9 files changed

+2771
-0
lines changed

core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ traccc_add_library( traccc_core core TYPE SHARED
126126
"src/seeding/silicon_pixel_spacepoint_formation.hpp"
127127
"include/traccc/seeding/silicon_pixel_spacepoint_formation_algorithm.hpp"
128128
"src/seeding/silicon_pixel_spacepoint_formation_algorithm.cpp"
129+
#gbts seed finding config
130+
"include/traccc/gbts_seeding/gbts_seeding_config.hpp"
131+
"src/gbts_seeding/gbts_seeding_config.cpp"
129132
# Ambiguity resolution
130133
"include/traccc/ambiguity_resolution/ambiguity_resolution_config.hpp"
131134
"include/traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// System include(s)
11+
#include <memory>
12+
13+
// Project include(s).
14+
#include "traccc/definitions/common.hpp"
15+
#include "traccc/definitions/primitives.hpp"
16+
#include "traccc/definitions/qualifiers.hpp"
17+
#include "traccc/utils/messaging.hpp"
18+
19+
// Detray include(s).
20+
#include <detray/geometry/barcode.hpp>
21+
22+
namespace traccc::device {
23+
24+
struct gbts_layerInfo {
25+
std::vector<char> type;
26+
// etaBin0 and numBins
27+
std::vector<std::pair<int, int>> info;
28+
// minEta and deltaEta
29+
std::vector<std::pair<float, float>> geo;
30+
31+
void reserve(unsigned int n) {
32+
type.reserve(n);
33+
info.reserve(n);
34+
geo.reserve(n);
35+
}
36+
37+
void addLayer(char layerType, int firstBin, int nBins, float minEta,
38+
float etaBinWidth) {
39+
type.push_back(layerType);
40+
info.push_back(std::make_pair(firstBin, nBins));
41+
geo.push_back(std::make_pair(minEta, etaBinWidth));
42+
}
43+
};
44+
45+
struct gbts_consts {
46+
47+
// CCA max iterations -> maxium seed length
48+
static constexpr unsigned short max_cca_iter = 15;
49+
// shared memory allocation sizes
50+
static constexpr unsigned short node_buffer_length = 128;
51+
static constexpr unsigned short shared_state_buffer_size = 608;
52+
53+
// access into output graph
54+
static constexpr char node1 = 0;
55+
static constexpr char node2 = 1;
56+
static constexpr char nNei = 2;
57+
static constexpr char nei_start = 3;
58+
};
59+
60+
} // namespace traccc::device
61+
62+
namespace traccc {
63+
64+
struct gbts_algo_params {
65+
66+
// edge making cuts
67+
float min_delta_phi = 0.015f;
68+
float dphi_coeff = 2.2e-4f;
69+
float min_delta_phi_low_dr = 0.002f;
70+
float dphi_coeff_low_dr = 4.33e-4f;
71+
72+
float minDeltaRadius = 2.0f;
73+
74+
float min_z0 = -160.0f;
75+
float max_z0 = 160.0f;
76+
float maxOuterRadius = 550.0f;
77+
float cut_zMinU = min_z0 - maxOuterRadius * 45;
78+
float cut_zMaxU = max_z0 + maxOuterRadius * 45; // how to get ROI dzdr
79+
80+
float max_Kappa = 3.75e-4f;
81+
float low_Kappa_d0 = 0.0f; // used to be 0.2f
82+
float high_Kappa_d0 = 0.0f; // used to be 1.0f
83+
84+
// tau prediction cut
85+
float tMin_slope = 6.7f;
86+
float offset = 0.2f;
87+
float tMax_min = 1.6f;
88+
float tMax_correction = 0.15f;
89+
float tMax_slope = 6.1f;
90+
91+
float type1_max_width = 0.2f;
92+
93+
// edge matching cuts
94+
float cut_dphi_max = 0.012f;
95+
float cut_dcurv_max = 0.001f;
96+
float cut_tau_ratio_max = 0.01f;
97+
};
98+
99+
struct gbts_seedfinder_config {
100+
bool setLinkingScheme(
101+
const std::vector<std::pair<int, std::vector<int>>>& binTables,
102+
const device::gbts_layerInfo layerInfo,
103+
std::vector<std::pair<uint64_t, short>>& detrayBarcodeBinning,
104+
float minPt, std::unique_ptr<const traccc::Logger> logger);
105+
106+
// layer linking and geometry
107+
std::vector<std::pair<unsigned int, unsigned int>> binTables{};
108+
traccc::device::gbts_layerInfo layerInfo{};
109+
unsigned int nLayers = 0;
110+
111+
std::vector<short> volumeToLayerMap{};
112+
std::vector<std::array<unsigned int, 2>> surfaceToLayerMap{};
113+
114+
// tuned for 900 MeV pT cut and scaled by input minPt
115+
gbts_algo_params algo_params{};
116+
117+
// node making bin counts
118+
unsigned int n_eta_bins = 0; // calculated from input layerInfo
119+
unsigned int n_phi_bins = 128;
120+
// graph making maxiums
121+
unsigned char max_num_neighbours = 10;
122+
// graph extraction cuts
123+
int minLevel = 3; // equivlent to a cut of #seed edges or #spacepoints-1
124+
};
125+
126+
} // namespace traccc
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#include "traccc/gbts_seeding/gbts_seeding_config.hpp"
9+
10+
#include <algorithm>
11+
#include <ranges>
12+
13+
namespace traccc {
14+
15+
// binTables contains pairs of linked layer-eta bins
16+
// the layerInfo should really be calculated from the barcodeBinning
17+
// BarcodeBinning pair is detray barcode and bin index (corrisponding to the
18+
// layers in layerInfo) minPt in MeV
19+
bool gbts_seedfinder_config::setLinkingScheme(
20+
const std::vector<std::pair<int, std::vector<int>>>& input_binTables,
21+
const device::gbts_layerInfo input_layerInfo,
22+
std::vector<std::pair<uint64_t, short>>& detrayBarcodeBinning,
23+
float minPt = 900.0f,
24+
std::unique_ptr<const traccc::Logger> callers_logger =
25+
getDummyLogger().clone()) {
26+
27+
TRACCC_LOCAL_LOGGER(std::move(callers_logger));
28+
// copy layer-eta binning infomation
29+
layerInfo = input_layerInfo;
30+
// unroll binTables
31+
for (std::pair<int, std::vector<int>> binPairs : input_binTables) {
32+
for (int bin2 : binPairs.second) {
33+
binTables.push_back(
34+
std::make_pair(static_cast<unsigned int>(binPairs.first),
35+
static_cast<unsigned int>(bin2)));
36+
}
37+
}
38+
39+
for (std::pair<int, int> lI : layerInfo.info)
40+
n_eta_bins = std::max(n_eta_bins,
41+
static_cast<unsigned int>(lI.first + lI.second));
42+
43+
// bin by volume
44+
std::ranges::sort(
45+
detrayBarcodeBinning,
46+
[](const std::pair<uint64_t, short> a,
47+
const std::pair<uint64_t, short> b) { return a.first > b.first; });
48+
49+
unsigned int largest_volume_index =
50+
detray::geometry::barcode(detrayBarcodeBinning[0].first).volume();
51+
auto current_volume = static_cast<short>(largest_volume_index);
52+
if (largest_volume_index >= SHRT_MAX) {
53+
TRACCC_ERROR(
54+
"volume index to large to fit in type-short GBTS volume to layer "
55+
"map");
56+
return false;
57+
}
58+
59+
bool layerChange = false;
60+
short current_layer = detrayBarcodeBinning[0].second;
61+
62+
int split_volumes = 0;
63+
std::vector<std::pair<short, unsigned int>> volumeToLayerMap_unordered;
64+
detrayBarcodeBinning.push_back(
65+
std::make_pair(UINT_MAX, -1)); // end-of-vector element
66+
std::vector<std::array<unsigned int, 2>> surfacesInVolume;
67+
for (std::pair<uint64_t, short> barcodeLayerPair : detrayBarcodeBinning) {
68+
detray::geometry::barcode barcode(barcodeLayerPair.first);
69+
if (current_volume != static_cast<short>(barcode.volume())) {
70+
// reached the end of this volume so add it to the maps
71+
short bin = current_layer;
72+
if (layerChange) {
73+
split_volumes++;
74+
bin = -1 *
75+
static_cast<short>(
76+
surfaceToLayerMap.size() +
77+
1); // start of this volume's surfaces in the map + 1
78+
for (std::array<unsigned int, 2> pair : surfacesInVolume)
79+
surfaceToLayerMap.push_back(pair);
80+
}
81+
volumeToLayerMap_unordered.push_back(std::make_pair(
82+
bin, current_volume)); // layerIdx if not split, begin-index in
83+
// the surface map otherwise
84+
85+
current_volume = static_cast<short>(barcode.volume());
86+
current_layer = barcodeLayerPair.second;
87+
layerChange = false;
88+
surfacesInVolume.clear();
89+
}
90+
// is volume encompassed by a layer
91+
layerChange |= (current_layer != barcodeLayerPair.second);
92+
93+
// save surfaces incase volume is not encommpassed by a layer
94+
surfacesInVolume.push_back(std::array<unsigned int, 2>{
95+
static_cast<unsigned int>(barcode.index()),
96+
static_cast<unsigned int>(barcodeLayerPair.second)});
97+
}
98+
// make volume by layer map
99+
volumeToLayerMap.resize(largest_volume_index + 1);
100+
for (unsigned int i = 0; i < largest_volume_index + 1; ++i)
101+
volumeToLayerMap.push_back(SHRT_MAX);
102+
for (std::pair<short, unsigned int> vLpair : volumeToLayerMap_unordered)
103+
volumeToLayerMap[vLpair.second] = vLpair.first;
104+
// scale cuts
105+
float ptScale = 900.0f / minPt;
106+
algo_params.min_delta_phi *= ptScale;
107+
algo_params.dphi_coeff *= ptScale;
108+
algo_params.min_delta_phi_low_dr *= ptScale;
109+
algo_params.dphi_coeff_low_dr *= ptScale;
110+
algo_params.max_Kappa *= ptScale;
111+
112+
// contianers sizes
113+
nLayers = static_cast<unsigned int>(layerInfo.type.size());
114+
115+
TRACCC_INFO("volume layer map has " << volumeToLayerMap_unordered.size()
116+
<< " volumes");
117+
TRACCC_INFO("The maxium volume index in the layer map is "
118+
<< volumeToLayerMap.size());
119+
TRACCC_INFO("surface to layer map has "
120+
<< surfaceToLayerMap.size() << " barcodes from "
121+
<< split_volumes << " multi-layer volumes");
122+
TRACCC_INFO("layer info found for " << nLayers << " layers");
123+
TRACCC_INFO(binTables.size() << " linked layer-eta bins for GBTS");
124+
125+
if (nLayers == 0) {
126+
TRACCC_ERROR("no layers input");
127+
return false;
128+
} else if (volumeToLayerMap.size() == 0) {
129+
TRACCC_ERROR("empty volume to layer map");
130+
return false;
131+
} else if (surfaceToLayerMap.size() > SHRT_MAX) {
132+
TRACCC_ERROR("surface to layer map is to large");
133+
return false;
134+
}
135+
return true;
136+
}
137+
138+
} // namespace traccc

device/cuda/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
4747
"src/seeding/seeding_algorithm.cpp"
4848
"include/traccc/cuda/seeding/spacepoint_formation_algorithm.hpp"
4949
"src/seeding/spacepoint_formation_algorithm.cu"
50+
#GBTS seed finding code
51+
"include/traccc/cuda/gbts_seeding/gbts_seeding_algorithm.hpp"
52+
"src/gbts_seeding/gbts_seeding_algorithm.cu"
53+
"src/gbts_seeding/kernels/GbtsNodesMakingKernels.cuh"
54+
"src/gbts_seeding/kernels/GbtsGraphMakingKernels.cuh"
55+
"src/gbts_seeding/kernels/GbtsGraphProcessingKernels.cuh"
5056
# Clusterization
5157
"include/traccc/cuda/clusterization/clusterization_algorithm.hpp"
5258
"src/clusterization/clusterization_algorithm.cu"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2021-2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Library include(s).
11+
#include "traccc/cuda/utils/stream.hpp"
12+
13+
// Project include(s).
14+
#include "traccc/edm/measurement.hpp"
15+
#include "traccc/edm/seed_collection.hpp"
16+
#include "traccc/edm/spacepoint_collection.hpp"
17+
#include "traccc/utils/algorithm.hpp"
18+
#include "traccc/utils/memory_resource.hpp"
19+
#include "traccc/utils/messaging.hpp"
20+
21+
// GBTS include(s)
22+
#include "traccc/gbts_seeding/gbts_seeding_config.hpp"
23+
24+
// VecMem include(s).
25+
#include <vecmem/utils/copy.hpp>
26+
27+
// System include(s).
28+
#include <memory>
29+
30+
namespace traccc::cuda {
31+
32+
/// Main algorithm for performing GBTS on an NVIDIA GPU
33+
///
34+
/// This algorithm returns a buffer which is not necessarily filled yet. A
35+
/// synchronisation statement is required before destroying this buffer.
36+
///
37+
class gbts_seeding_algorithm
38+
: public algorithm<edm::seed_collection::buffer(
39+
const traccc::edm::spacepoint_collection::const_view&,
40+
const traccc::measurement_collection_types::const_view&
41+
measurements)>,
42+
public messaging {
43+
44+
public:
45+
/// Constructor for the seed finding algorithm
46+
///
47+
/// @param str The CUDA stream to perform the operations in
48+
///
49+
gbts_seeding_algorithm(
50+
const gbts_seedfinder_config& cfg, traccc::memory_resource& mr,
51+
vecmem::copy& copy, stream& str,
52+
std::unique_ptr<const Logger> logger = getDummyLogger().clone());
53+
54+
/// Operator executing the algorithm.
55+
///
56+
/// @param spacepoints is a view of all spacepoints in the event
57+
/// @return the buffer of track seeds reconstructed from the spacepoints
58+
///
59+
output_type operator()(
60+
const traccc::edm::spacepoint_collection::const_view& spacepoints,
61+
const traccc::measurement_collection_types::const_view& measurements)
62+
const;
63+
64+
private:
65+
gbts_seedfinder_config m_config;
66+
/// The memory resource(s) to use
67+
traccc::memory_resource m_mr;
68+
/// The copy object to use
69+
std::reference_wrapper<vecmem::copy> m_copy;
70+
/// The CUDA stream to use
71+
std::reference_wrapper<stream> m_stream;
72+
};
73+
74+
} // namespace traccc::cuda

0 commit comments

Comments
 (0)