Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 08:20:30

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2025-2026 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Local include(s).
0009 #include "traccc/hip/utils/make_magnetic_field.hpp"
0010 
0011 // Project include(s).
0012 #include "traccc/bfield/magnetic_field_types.hpp"
0013 
0014 // Covfie include(s).
0015 #include <covfie/core/backend/primitive/constant.hpp>
0016 #include <covfie/core/backend/transformer/affine.hpp>
0017 #include <covfie/core/backend/transformer/clamp.hpp>
0018 #include <covfie/core/backend/transformer/linear.hpp>
0019 #include <covfie/core/backend/transformer/strided.hpp>
0020 #include <covfie/core/concepts.hpp>
0021 #include <covfie/core/field.hpp>
0022 #include <covfie/core/vector.hpp>
0023 #include <covfie/hip/backend/primitive/hip_device_array.hpp>
0024 
0025 // System include(s).
0026 #include <stdexcept>
0027 
0028 namespace traccc::hip {
0029 
0030 /// Inhomogeneous B-field backend type using HIP global memory
0031 template <typename scalar_t>
0032 using inhom_global_bfield_backend_t =
0033     covfie::backend::affine<covfie::backend::linear<covfie::backend::clamp<
0034         covfie::backend::strided<covfie::vector::vector_d<std::size_t, 3>,
0035                                  covfie::backend::hip_device_array<
0036                                      covfie::vector::vector_d<scalar_t, 3>>>>>>;
0037 // Test that the type is a valid backend for a field
0038 static_assert(
0039     covfie::concepts::field_backend<inhom_global_bfield_backend_t<float>>,
0040     "hip::inhom_global_bfield_backend_t is not a valid field backend type");
0041 
0042 magnetic_field make_magnetic_field(const magnetic_field& bfield,
0043                                    const magnetic_field_storage storage) {
0044   if (bfield.is<const_bfield_backend_t<float>>()) {
0045     return magnetic_field{covfie::field<const_bfield_backend_t<float>>{
0046         bfield.as_field<const_bfield_backend_t<float>>()}};
0047   } else if (bfield.is<const_bfield_backend_t<double>>()) {
0048     return magnetic_field{covfie::field<const_bfield_backend_t<double>>{
0049         bfield.as_field<const_bfield_backend_t<double>>()}};
0050   } else if (bfield.is<host::inhom_bfield_backend_t<float>>()) {
0051     // Convenience access to the Covfie field object.
0052     const auto& in_field =
0053         bfield.as_field<host::inhom_bfield_backend_t<float>>();
0054     // At single precision we can use either global or texture memory.
0055     if (storage == magnetic_field_storage::global_memory) {
0056       return magnetic_field{
0057           covfie::field<hip::inhom_global_bfield_backend_t<float>>(in_field)};
0058     } else {
0059       throw std::invalid_argument(
0060           "Unsupported storage method chosen for inhomogeneous b-field");
0061     }
0062   } else if (bfield.is<host::inhom_bfield_backend_t<double>>()) {
0063     // At double precision we can only use global memory.
0064     if (storage == magnetic_field_storage::global_memory) {
0065       return magnetic_field{
0066           covfie::field<hip::inhom_global_bfield_backend_t<double>>(
0067               bfield.as_field<host::inhom_bfield_backend_t<double>>())};
0068     } else {
0069       throw std::invalid_argument(
0070           "Unsupported storage method chosen for inhomogeneous b-field");
0071     }
0072   } else {
0073     throw std::invalid_argument("Unsupported b-field type received");
0074   }
0075 }
0076 
0077 }  // namespace traccc::hip