8000 Add cuda inhomogeneous bfield type by beomki-yeo · Pull Request #1017 · acts-project/traccc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add cuda inhomogeneous bfield type #1017

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ traccc_add_library( traccc_core core TYPE SHARED
"src/finding/combinatorial_kalman_filter_algorithm.cpp"
"src/finding/combinatorial_kalman_filter_algorithm_constant_field_default_detector.cpp"
"src/finding/combinatorial_kalman_filter_algorithm_constant_field_telescope_detector.cpp"
"src/finding/combinatorial_kalman_filter_algorithm_inhomogeneous_field_default_detector.cpp"
# Fitting algorithmic code
"include/traccc/fitting/kalman_filter/gain_matrix_updater.hpp"
"include/traccc/fitting/kalman_filter/kalman_actor.hpp"
Expand All @@ -85,6 +86,7 @@ traccc_add_library( traccc_core core TYPE SHARED
"src/fitting/kalman_fitting_algorithm.cpp"
"src/fitting/kalman_fitting_algorithm_constant_field_default_detector.cpp"
"src/fitting/kalman_fitting_algorithm_constant_field_telescope_detector.cpp"
"src/fitting/kalman_fitting_algorithm_inhomogeneous_field_default_detector.cpp"
# Seed finding algorithmic code.
"include/traccc/seeding/detail/lin_circle.hpp"
"include/traccc/seeding/detail/doublet.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class combinatorial_kalman_filter_algorithm
telescope_detector::host::scalar_type>>::view_t&,
const measurement_collection_types::const_view&,
const bound_track_parameters_collection_types::const_view&)>,
public algorithm<edm::track_candidate_collection<default_algebra>::host(
const default_detector::host&,
const covfie::field<inhom_bfield_backend_t<
default_detector::host::scalar_type>>::view_t&,
const measurement_collection_types::const_view&,
const bound_track_parameters_collection_types::const_view&)>,
public messaging {

public:
Expand Down Expand Up @@ -92,6 +98,24 @@ class combinatorial_kalman_filter_algorithm
const bound_track_parameters_collection_types::const_view& seeds)
const override;

/// Execute the algorithm
///
/// @param det The (default) detector object
/// @param field The inhomogeneous magnetic field object
/// @param measurements All measurements in an event
/// @param seeds All seeds in an event to start the track finding
/// with
///
/// @return A container of the found track candidates
///
output_type operator()(
const default_detector::host& det,
const covfie::field<traccc::inhom_bfield_backend_t<
default_detector::host::scalar_type>>::view_t& field,
const measurement_collection_types::const_view& measurements,
const bound_track_parameters_collection_types::const_view& seeds)
const override;

private:
/// Algorithm configuration
config_type m_config;
Expand Down
20 changes: 20 additions & 0 deletions core/include/traccc/fitting/kalman_fitting_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class kalman_fitting_algorithm
const covfie::field<const_bfield_backend_t<
telescope_detector::host::scalar_type>>::view_t&,
const edm::track_candidate_container<default_algebra>::const_view&)>,
public algorithm<track_state_container_types::host(
const default_detector::host&,
const covfie::field<inhom_bfield_backend_t<
default_detector::host::scalar_type>>::view_t&,
const edm::track_candidate_container<default_algebra>::const_view&)>,
public messaging {

public:
Expand Down Expand Up @@ -86,6 +91,21 @@ class kalman_fitting_algorithm
const edm::track_candidate_container<default_algebra>::const_view&
track_candidates) const override;

/// Execute the algorithm
///
/// @param det The (default) detector object
/// @param field The inhomogeneous magnetic field object
/// @param track_candidates All track candidates to fit
///
/// @return A container of the fitted track states
///
output_type operator()(
const default_detector::host& det,
const covfie::field<traccc::inhom_bfield_backend_t<
default_detector::host::scalar_type>>::view_t& field,
const edm::track_candidate_container<default_algebra>::const_view&
track_candidates) const override;

private:
/// Algorithm configuration
config_type m_config;
Expand Down
10 changes: 10 additions & 0 deletions core/include/traccc/utils/bfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#pragma once

#include <covfie/core/backend/primitive/constant.hpp>
#include <covfie/core/backend/transformer/affine.hpp>
#include <covfie/core/backend/transformer/linear.hpp>
#include <covfie/core/backend/transformer/strided.hpp>
#include <covfie/core/field.hpp>
#include <covfie/core/vector.hpp>

Expand All @@ -31,4 +34,11 @@ ::covfie::field<const_bfield_backend_t<scalar_t>> construct_const_bfield(
const vector3& v) {
return construct_const_bfield(v[0], v[1], v[2]);
}

template <typename scalar_t>
using inhom_bfield_backend_t =
covfie::backend::affine<covfie::backend::linear<covfie::backend::strided<
covfie::vector::vector_d<std::size_t, 3>,
covfie::backend::array<covfie::vector::vector_d<scalar_t, 3>>>>>;

} // namespace traccc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Local include(s).
#include "traccc/finding/combinatorial_kalman_filter_algorithm.hpp"
#include "traccc/finding/details/find_tracks.hpp"
#include "traccc/utils/bfield.hpp"
#include "traccc/utils/propagation.hpp"

namespace {
using detector_type = traccc::default_detector;
using scalar_type = detector_type::host::scalar_type;
using bfield_type = covfie::field<traccc::inhom_bfield_backend_t<scalar_type>>;
} // namespace

namespace traccc::host {
combinatorial_kalman_filter_algorithm::output_type
combinatorial_kalman_filter_algorithm::operator()(
const detector_type::host& det, const bfield_type::view_t& field,
const measurement_collection_types::const_view& measurements,
const bound_track_parameters_collection_types::const_view& seeds) const {

// Perform the track finding using the templated implementation.
return details::find_tracks<
detray::rk_stepper<bfield_type::view_t,
detector_type::host::algebra_type,
detray::constrained_step<scalar_type>>,
detray::navigator<const detector_type::host>>(
det, field, measurements, seeds, m_config, m_mr.get(), logger());
}

} // namespace traccc::host
F438
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Project include(s).
#include "traccc/fitting/details/fit_tracks.hpp"
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
#include "traccc/fitting/kalman_fitting_algorithm.hpp"
#include "traccc/utils/bfield.hpp"
#include "traccc/utils/propagation.hpp"

namespace {
using detector_type = traccc::default_detector;
using scalar_type = detector_type::host::scalar_type;
using bfield_type = covfie::field<traccc::inhom_bfield_backend_t<scalar_type>>;
} // namespace

namespace traccc::host {

kalman_fitting_algorithm::output_type kalman_fitting_algorithm::operator()(
const detector_type::host& det, const bfield_type::view_t& field,
const edm::track_candidate_container<default_algebra>::const_view&
track_candidates) const {

// Create the fitter object.
kalman_fitter<detray::rk_stepper<bfield_type::view_t,
detector_type::host::algebra_type,
detray::constrained_step<scalar_type>>,
detray::navigator<const detector_type::host>>
fitter{det, field, m_config};

// Perform the track fitting using a common, templated function.
return details::fit_tracks<default_algebra>(fitter, track_candidates,
m_mr.get(), m_copy.get());
}

} // namespace traccc::host
8 changes: 7 additions & 1 deletion device/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
"src/utils/make_prefix_sum_buff.cu"
"include/traccc/cuda/utils/stream.hpp"
"src/utils/barrier.hpp"
"include/traccc/cuda/utils/bfield.hpp"
"src/utils/cuda_error_handling.hpp"
"src/utils/cuda_error_handling.cpp"
"src/utils/stream.cpp"
Expand Down Expand Up @@ -52,8 +53,12 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
"src/clusterization/kernels/ccl_kernel.cu"
"src/clusterization/kernels/ccl_kernel.cuh"
# Finding
"include/traccc/cuda/finding/combinatorial_kalman_filter_algorithm.hpp"
"include/traccc/cuda/finding/finding_algorithm.hpp"
"src/finding/finding_algorithm.cu"
"src/finding/combinatorial_kalman_filter_algorithm.cu"
"src/finding/combinatorial_kalman_filter_algorithm_constant_field_default_detector.cu"
"src/finding/combinatorial_kalman_filter_algorithm_inhomogeneous_field_default_detector.cu"
"src/finding/kernels/make_barcode_sequence.cu"
"src/finding/kernels/make_barcode_sequence.cuh"
"src/finding/kernels/apply_interaction.hpp"
Expand All @@ -66,6 +71,7 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
"src/finding/kernels/specializations/find_tracks_default_detector.cu"
"src/finding/kernels/specializations/apply_interaction_default_detector.cu"
"src/finding/kernels/specializations/propagate_to_next_surface_default_detector.cu"
"src/finding/kernels/specializations/propagate_to_next_surface_inhomogeneous_field_default_detector.cu"
# Ambiguity resolution
"include/traccc/cuda/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp"
"src/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.cu"
Expand Down Expand Up @@ -142,7 +148,7 @@ target_compile_options( traccc_cuda
PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr> )
target_link_libraries( traccc_cuda
PUBLIC traccc::core detray::core vecmem::core covfie::core
PRIVATE CUDA::cudart traccc::device_common vecmem::cuda )
PRIVATE CUDA::cudart traccc::device_common vecmem::cuda covfie::cuda )

# Set up Thrust specifically for the traccc::cuda library.
thrust_create_target( traccc::cuda_thrust
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2024-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s).
#include "traccc/cuda/utils/bfield.hpp"
#include "traccc/cuda/utils/stream.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/edm/track_candidate_collection.hpp"
#include "traccc/edm/track_parameters.hpp"
#include "traccc/finding/finding_config.hpp"
#include "traccc/geometry/detector.hpp"
#include "traccc/utils/algorithm.hpp"
#include "traccc/utils/bfield.hpp"
#include "traccc/utils/detector_type_utils.hpp"
#include "traccc/utils/memory_resource.hpp"
#include "traccc/utils/messaging.hpp"

// VecMem include(s).
#include <vecmem/utils/copy.hpp>

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

namespace traccc::cuda {

/// CKF track finding algorithm
class combinatorial_kalman_filter_algorithm
: public algorithm<edm::track_candidate_collection<default_algebra>::buffer(
const default_detector::view&,
const covfie::field<traccc::const_bfield_backend_t<
default_detector::device::scalar_type>>::view_t&,
const measurement_collection_types::const_view&,
const bound_track_parameters_collection_types::const_view&)>,
public algorithm<edm::track_candidate_collection<default_algebra>::buffer(
const default_detector::view&,
const covfie::field<traccc::cuda::inhom_bfield_backend_t<
default_detector::device::scalar_type>>::view_t&,
const measurement_collection_types::const_view&,
const bound_track_parameters_collection_types::const_view&)>,
public messaging {

public:
/// Configuration type
using config_type = finding_config;
/// Output type
using output_type =
edm::track_candidate_collection<default_algebra>::buffer;

/// Constructor with the algorithm's configuration
explicit combinatorial_kalman_filter_algorithm(
const config_type& config, const traccc::memory_resource& mr,
vecmem::copy& copy, stream& str,
std::unique_ptr<const Logger> logger = getDummyLogger().clone());

/// Execute the algorithm
///
/// @param det The (default) detector object
/// @param field The (constant) magnetic field object
/// @param measurements All measurements in an event
/// @param seeds All seeds in an event to start the track finding
/// with
///
/// @return A container of the found track candidates
///
output_type operator()(
const default_detector::view& det,
const covfie::field<const_bfield_backend_t<
default_detector::device::scalar_type>>::view_t& field,
const measurement_collection_types::const_view& measurements,
const bound_track_parameters_collection_types::const_view& seeds)
const override;

/// Execute the algorithm
///
/// @param det The (default) detector object
/// @param field The inhomogeneous magnetic field object
/// @param measurements All measurements in an event
/// @param seeds All seeds in an event to start the track finding
/// with
///
/// @return A container of the found track candidates
///
output_type operator()(
const default_detector::view& det,
const covfie::field<cuda::inhom_bfield_backend_t<
default_detector::device::scalar_type>>::view_t& field,
const measurement_collection_types::const_view& measurements,
const bound_track_parameters_collection_types::const_view& seeds)
const override;

private:
/// Algorithm configuration
config_type m_config;
/// Memory resource used by the algorithm
traccc::memory_resource m_mr;
/// Copy object used by the algorithm
std::reference_wrapper<vecmem::copy> m_copy;
/// The CUDA stream to use
stream& m_stream;
/// Warp size of the GPU being used
unsigned int m_warp_size;
}; // class combinatorial_kalman_filter_algorithm

} // namespace traccc::cuda
27 changes: 27 additions & 0 deletions device/cuda/include/traccc/cuda/utils/bfield.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Covfie include(s)
#include <covfie/core/backend/primitive/constant.hpp>
#include <covfie/core/backend/transformer/affine.hpp>
#include <covfie/core/backend/transformer/linear.hpp>
#include <covfie/core/backend/transformer/strided.hpp>
#include <covfie/core/field.hpp>
#include <covfie/core/vector.hpp>
#include <covfie/cuda/backend/primitive/cuda_device_array.hpp>

namespace traccc::cuda {

template <typename scalar_t>
using inhom_bfield_backend_t = covfie::backend::affine<covfie::backend::linear<
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
covfie::backend::cuda_device_array<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenswat is the one to tell us this, but we should try texture memory right away, right? I assume that's a different type.

covfie::vector::vector_d<scalar_t, 3>>>>>;

} // namespace traccc::cuda
33 changes: 33 additions & 0 deletions device/cuda/src/finding/combinatorial_kalman_filter_algorithm.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

// Local include(s).
#include "traccc/cuda/finding/combinatorial_kalman_filter_algorithm.hpp"

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

namespace traccc::cuda {

combinatorial_kalman_filter_algorithm::combinatorial_kalman_filter_algorithm(
const config_type& config, const traccc::memory_resource& mr,
vecmem::copy& copy, stream& str, std::unique_ptr<const Logger> logger)
: messaging(std::move(logger)),
m_config{config},
m_mr{mr},
m_copy{copy},
m_stream{str} {

// Check the configuration.
if (m_config.min_track_candidates_per_track == 0) {
throw std::invalid_argument(
"The minimum number of track candidates per track must be at least "
"1.");
}
}

} // namespace traccc::cuda
Loading
Loading
0