Skip to content

Commit 2757ac6

Browse files
committed
Add clamping to magnetic field types
Currently, our magnetic field types are unclamped which means that an out-of-bounds access can yield a segmentation fault. Although we never really should go OOB, it does sometimes happen due to numerical instability. This commit adds a clamping transformer to our magnetic field backends to ensure that we never access invalid memory.
1 parent 748fe50 commit 2757ac6

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

core/include/traccc/utils/bfield.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// Covfie include(s).
1414
#include <covfie/core/backend/primitive/constant.hpp>
1515
#include <covfie/core/backend/transformer/affine.hpp>
16+
#include <covfie/core/backend/transformer/clamp.hpp>
1617
#include <covfie/core/backend/transformer/linear.hpp>
1718
#include <covfie/core/backend/transformer/strided.hpp>
1819
#include <covfie/core/field.hpp>
@@ -93,13 +94,20 @@ using const_bfield_backend_t =
9394
::covfie::backend::constant<::covfie::vector::vector_d<scalar_t, 3>,
9495
::covfie::vector::vector_d<scalar_t, 3>>;
9596

96-
/// Inhomogeneous magnetic field backend type
97+
/// Inhomogeneous magnetic field used for IO
9798
template <typename scalar_t>
98-
using inhom_bfield_backend_t =
99+
using inhom_io_bfield_backend_t =
99100
covfie::backend::affine<covfie::backend::linear<covfie::backend::strided<
100101
covfie::vector::vector_d<std::size_t, 3>,
101102
covfie::backend::array<covfie::vector::vector_d<scalar_t, 3>>>>>;
102103

104+
/// Inhomogeneous magnetic field backend type
105+
template <typename scalar_t>
106+
using inhom_bfield_backend_t = covfie::backend::affine<
107+
covfie::backend::linear<covfie::backend::clamp<covfie::backend::strided<
108+
covfie::vector::vector_d<std::size_t, 3>,
109+
covfie::backend::array<covfie::vector::vector_d<scalar_t, 3>>>>>>;
110+
103111
/// Construct a constant magnetic field object
104112
template <typename scalar_t>
105113
::covfie::field<const_bfield_backend_t<scalar_t>> construct_const_bfield(

device/cuda/src/utils/bfield.cuh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Covfie include(s).
1111
#include <covfie/core/backend/primitive/constant.hpp>
1212
#include <covfie/core/backend/transformer/affine.hpp>
13+
#include <covfie/core/backend/transformer/clamp.hpp>
1314
#include <covfie/core/backend/transformer/linear.hpp>
1415
#include <covfie/core/backend/transformer/strided.hpp>
1516
#include <covfie/core/field.hpp>
@@ -20,9 +21,10 @@ namespace traccc::cuda {
2021

2122
/// Inhomogeneous B-field backend type for CUDA
2223
template <typename scalar_t>
23-
using inhom_bfield_backend_t = covfie::backend::affine<covfie::backend::linear<
24-
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
25-
covfie::backend::cuda_device_array<
26-
covfie::vector::vector_d<scalar_t, 3>>>>>;
24+
using inhom_bfield_backend_t =
25+
covfie::backend::affine<covfie::backend::linear<covfie::backend::clamp<
26+
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
27+
covfie::backend::cuda_device_array<
28+
covfie::vector::vector_d<scalar_t, 3>>>>>>;
2729

2830
} // namespace traccc::cuda

device/sycl/src/utils/bfield.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Covfie include(s).
1111
#include <covfie/core/backend/primitive/constant.hpp>
1212
#include <covfie/core/backend/transformer/affine.hpp>
13+
#include <covfie/core/backend/transformer/clamp.hpp>
1314
#include <covfie/core/backend/transformer/linear.hpp>
1415
#include <covfie/core/backend/transformer/strided.hpp>
1516
#include <covfie/core/field.hpp>
@@ -20,9 +21,10 @@ namespace traccc::sycl {
2021

2122
/// Inhomogeneous B-field backend type for CUDA
2223
template <typename scalar_t>
23-
using inhom_bfield_backend_t = covfie::backend::affine<covfie::backend::linear<
24-
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
25-
covfie::backend::sycl_device_array<
26-
covfie::vector::vector_d<scalar_t, 3>>>>>;
24+
using inhom_bfield_backend_t =
25+
covfie::backend::affine<covfie::backend::linear<covfie::backend::clamp<
26+
covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
27+
covfie::backend::sycl_device_array<
28+
covfie::vector::vector_d<scalar_t, 3>>>>>>;
2729

2830
} // namespace traccc::sycl

extern/covfie/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ message( STATUS "Fetching covfie as part of the traccc project" )
1313

1414
# Declare where to get covfie from.
1515
set( TRACCC_COVFIE_SOURCE
16-
"URL;https://github.com/acts-project/covfie/archive/refs/tags/v0.13.0.tar.gz;URL_MD5;9dbff64d68a9d8c88acff12e8f99584a"
16+
"URL;https://github.com/acts-project/covfie/archive/refs/tags/v0.15.1.tar.gz;URL_MD5;aa54f7e7e1a83edd02660e2778d29109"
1717
CACHE STRING "Source for covfie, when built as part of this project" )
1818
mark_as_advanced( TRACCC_COVFIE_SOURCE )
1919
FetchContent_Declare( covfie SYSTEM ${TRACCC_COVFIE_SOURCE} )

io/src/read_bfield.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ void read_bfield(covfie::field<inhom_bfield_backend_t<traccc::scalar>>& field,
3535

3636
// Construct/fill the magnetic field from the file.
3737
TRACCC_INFO("Reading magnetic field from file: " << filename);
38-
field = covfie::field<inhom_bfield_backend_t<traccc::scalar>>(ifile);
38+
field = covfie::field<inhom_bfield_backend_t<traccc::scalar>>(
39+
covfie::field<inhom_io_bfield_backend_t<traccc::scalar>>(ifile));
3940
}
4041

4142
} // namespace binary

0 commit comments

Comments
 (0)