Skip to content

Commit

Permalink
Merge pull request #566 from niermann999/ref-remove-bfield-from-det
Browse files Browse the repository at this point in the history
ref: remove b-field from detector
  • Loading branch information
beomki-yeo authored Oct 18, 2023
2 parents dd6308d + 3e947cd commit 8b3e0d5
Show file tree
Hide file tree
Showing 67 changed files with 429 additions and 923 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
SCALAR_TYPE: ["float", "double"]
PLATFORM:
- NAME: "HOST"
CONTAINER: "ghcr.io/acts-project/ubuntu2004:v30"
CONTAINER: "ghcr.io/acts-project/ubuntu2004:v43"
OPTIONS: -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=ON -DDETRAY_VC_PLUGIN=ON

# The system to run on.
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ file( GLOB _detray_core_private_headers
detray_add_library( detray_core core
${_detray_core_public_headers} ${_detray_core_private_headers} )
target_link_libraries( detray_core
INTERFACE covfie::core vecmem::core detray::Thrust )
INTERFACE vecmem::core detray::Thrust )

# Generate a version header for the project.
configure_file( "cmake/version.hpp.in"
Expand Down
208 changes: 32 additions & 176 deletions core/include/detray/core/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "detray/core/detail/container_buffers.hpp"
#include "detray/core/detail/container_views.hpp"
#include "detray/core/detector_metadata.hpp"
#include "detray/definitions/bfield_backends.hpp"
#include "detray/definitions/containers.hpp"
#include "detray/definitions/qualifiers.hpp"
#include "detray/geometry/detail/volume_descriptor.hpp"
Expand All @@ -32,7 +31,7 @@
namespace detray {

/// @brief Forward declaration of a detector view type
template <typename device_bfield_bknd_t, typename metadata, typename bfield_t>
template <typename metadata>
struct detector_view;

/// @brief The detector definition.
Expand All @@ -46,13 +45,11 @@ struct detector_view;
/// @tparam container_t type collection of the underlying containers
/// @tparam source_link the surface source link
template <typename metadata_t = default_metadata,
typename bfield_t = covfie::field<bfield::const_bknd_t>,
typename container_t = host_container_types>
class detector {

// Allow the building of the detector containers
friend class volume_builder_interface<
detector<metadata_t, bfield_t, container_t>>;
friend class volume_builder_interface<detector<metadata_t, container_t>>;

public:
/// Algebra types
Expand All @@ -65,8 +62,6 @@ class detector {

using metadata = metadata_t;

using bfield_type = bfield_t;

/// Raw container types
template <typename T, std::size_t N>
using array_type = typename container_t::template array_type<T, N>;
Expand Down Expand Up @@ -128,22 +123,15 @@ class detector {
using volume_finder =
typename metadata::template volume_finder<container_t>;

// TODO: Remove
template <typename device_bfield_t>
using detector_view_type =
detector_view<device_bfield_t, metadata, bfield_t>;

// TODO: rename back to 'view_type' etc, once covfie is wrapped in the
// container view/buffer formalism
/// Detector view types
using view_t = dmulti_view<
using view_type = dmulti_view<
dvector_view<volume_type>, typename transform_container::view_type,
typename mask_container::view_type,
typename material_container::view_type,
typename surface_container::view_type, dvector_view<surface_type>,
typename volume_finder::view_type>;

using const_view_t =
using const_view_type =
dmulti_view<dvector_view<const volume_type>,
typename transform_container::const_view_type,
typename mask_container::const_view_type,
Expand All @@ -153,7 +141,7 @@ class detector {
typename volume_finder::const_view_type>;

/// Detector buffer types
using buffer_t = dmulti_buffer<
using buffer_type = dmulti_buffer<
dvector_buffer<volume_type>, typename transform_container::buffer_type,
typename mask_container::buffer_type,
typename material_container::buffer_type,
Expand All @@ -179,39 +167,20 @@ class detector {
_surfaces(resource),
_surface_lookup(&resource),
_volume_finder(resource),
_resource(&resource),
_bfield() {}

/// @param resource memory resource for the allocation of members and
/// externally provided magnetic field @param field
DETRAY_HOST
detector(vecmem::memory_resource &resource, bfield_type &&field)
: _volumes(&resource),
_transforms(resource),
_masks(resource),
_materials(resource),
_surfaces(resource),
_surface_lookup(&resource),
_volume_finder(resource),
_resource(&resource),
_bfield(std::move(field)) {}
_resource(&resource) {}

/// Constructor with detector_data
template <typename detector_data_type,
std::enable_if_t<!std::is_base_of_v<vecmem::memory_resource,
detector_data_type>,
bool> = true>
DETRAY_HOST_DEVICE explicit detector(detector_data_type &det_data)
: _volumes(detray::detail::get<0>(det_data._detector_data.m_view)),
_transforms(detray::detail::get<1>(det_data._detector_data.m_view)),
_masks(detray::detail::get<2>(det_data._detector_data.m_view)),
_materials(detray::detail::get<3>(det_data._detector_data.m_view)),
_surfaces(detray::detail::get<4>(det_data._detector_data.m_view)),
_surface_lookup(
detray::detail::get<5>(det_data._detector_data.m_view)),
_volume_finder(
detray::detail::get<6>(det_data._detector_data.m_view)),
_bfield(det_data._bfield_view) {}
template <typename detector_view_t,
typename std::enable_if_t<
detail::is_device_view_v<detector_view_t>, bool> = true>
DETRAY_HOST_DEVICE explicit detector(detector_view_t &det_data)
: _volumes(detray::detail::get<0>(det_data.m_view)),
_transforms(detray::detail::get<1>(det_data.m_view)),
_masks(detray::detail::get<2>(det_data.m_view)),
_materials(detray::detail::get<3>(det_data.m_view)),
_surfaces(detray::detail::get<4>(det_data.m_view)),
_surface_lookup(detray::detail::get<5>(det_data.m_view)),
_volume_finder(detray::detail::get<6>(det_data.m_view)) {}
/// @}

/// Add a new volume and retrieve a reference to it.
Expand Down Expand Up @@ -542,14 +511,23 @@ class detector {
return *std::max_element(n_candidates.begin(), n_candidates.end());
}

/// @brief Add a bfield to the detector
DETRAY_HOST
void set_bfield(bfield_type &&field) {
_bfield = std::forward<bfield_type>(field);
/// @returns view of a detector
DETRAY_HOST auto get_data() -> view_type {
return view_type{
detray::get_data(_volumes), detray::get_data(_transforms),
detray::get_data(_masks), detray::get_data(_materials),
detray::get_data(_surfaces), detray::get_data(_surface_lookup),
detray::get_data(_volume_finder)};
}

DETRAY_HOST_DEVICE
inline const bfield_type &get_bfield() const { return _bfield; }
/// @returns const view of a detector
DETRAY_HOST auto get_data() const -> const_view_type {
return const_view_type{
detray::get_data(_volumes), detray::get_data(_transforms),
detray::get_data(_masks), detray::get_data(_materials),
detray::get_data(_surfaces), detray::get_data(_surface_lookup),
detray::get_data(_volume_finder)};
}

/// @param names maps a volume to its string representation.
/// @returns a string representation of the detector.
Expand Down Expand Up @@ -618,128 +596,6 @@ class detector {
/// The memory resource represents how and where (host, device, managed)
/// the memory for the detector containers is allocated
vecmem::memory_resource *_resource = nullptr;

/// Storage for magnetic field data
bfield_type _bfield;
};

/// @brief The detector data buffer
///
/// Contains the buffers for all detector components plus the covfie device
/// field type, which is being copied to device when this type gets constructed
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
struct detector_buffer {

using detector_type = detector<metadata_t, bfield_t, host_container_types>;

/// Automatic buffer creation with the given parameters
detector_buffer(detector_type &det, vecmem::memory_resource &mr,
vecmem::copy &cpy,
detray::copy cpy_type = detray::copy::sync,
vecmem::data::buffer_type buff_type =
vecmem::data::buffer_type::fixed_size)
: _detector_buffer(detray::get_buffer(detray::get_data(det.volumes()),
mr, cpy, cpy_type, buff_type),
detray::get_buffer(det.transform_store(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.mask_store(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.material_store(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.surface_store(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.surface_lookup(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.volume_search_grid(), mr, cpy,
cpy_type, buff_type)),
_bfield(det.get_bfield()) {}

/// Buffers were created manually
detector_buffer(
const detector_type &det,
detail::get_buffer_t<typename detector_type::volume_container>
&&vol_buffer,
typename detector_type::transform_container::buffer_type &&trf_buffer,
typename detector_type::mask_container::buffer_type &&msk_buffer,
typename detector_type::material_container::buffer_type &&mat_buffer,
typename detector_type::surface_container::buffer_type &&sf_buffer,
detail::get_buffer_t<typename detector_type::surface_lookup_container>
&&sf_lkp_buffer,
typename detector_type::volume_finder::buffer_type &&vgrd_buffer)
: _detector_buffer(std::move(vol_buffer), std::move(trf_buffer),
std::move(msk_buffer), std::move(mat_buffer),
std::move(sf_buffer), std::move(sf_lkp_buffer),
std::move(vgrd_buffer)),
_bfield(det.get_bfield()) {}

/// Buffers for the vecemem types
typename detector_type::buffer_t _detector_buffer;
/// Covfie device field
covfie::field<device_bfield_bknd_t> _bfield;
};

/// @brief The detector view
///
/// Contains the views for all detector components, including the device view
/// of the bfield
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
struct detector_view {

using detector_type = detector<metadata_t, bfield_t, host_container_types>;

detector_view(detector_type &det)
: _detector_data(detray::get_data(det.volumes()),
detray::get_data(det.transform_store()),
detray::get_data(det.mask_store()),
detray::get_data(det.material_store()),
detray::get_data(det.surface_store()),
detray::get_data(det.surface_lookup()),
detray::get_data(det.volume_search_grid())),
_bfield_view(det.get_bfield()) {}

detector_view(
detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> &det_buff)
: _detector_data(detray::get_data(det_buff._detector_buffer)),
_bfield_view(det_buff._bfield) {}

/// Views for the vecmem types
typename detector_type::view_t _detector_data;
/// Covfie field view
covfie::field_view<device_bfield_bknd_t> _bfield_view;
};

/// Stand-alone function that @returns the detector view for transfer to
/// device.
///
/// @param detector the detector to be tranferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_view<device_bfield_bknd_t, metadata_t, bfield_t> get_data(
detector<metadata_t, bfield_t, host_container_types> &det) {
return {det};
}

/// Stand-alone function that @returns the detector buffer for transfer to
/// device.
///
/// @param detector the detector to be transferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> get_buffer(
detector<metadata_t, bfield_t, host_container_types> &det,
vecmem::memory_resource &mr, vecmem::copy &cpy,
detray::copy cpy_type = detray::copy::sync,
vecmem::data::buffer_type buff_type =
vecmem::data::buffer_type::fixed_size) {
return {det, mr, cpy, cpy_type, buff_type};
}

/// Stand-alone function that @returns the detector view for transfer to
/// device.
///
/// @param detector the detector to be transferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_view<device_bfield_bknd_t, metadata_t, bfield_t> get_data(
detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> &det_buff) {
return {det_buff};
}

} // namespace detray
9 changes: 3 additions & 6 deletions core/include/detray/propagator/rk_stepper.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,
// First Runge-Kutta point
const vector3 pos = stepping().pos();
const vector3 dir = stepping().dir();
const typename magnetic_field_t::output_t bvec =
magnetic_field.at(pos[0], pos[1], pos[2]);
const auto bvec = magnetic_field.at(pos[0], pos[1], pos[2]);
sd.b_first[0] = bvec[0];
sd.b_first[1] = bvec[1];
sd.b_first[2] = bvec[2];
Expand All @@ -190,8 +189,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,

// Second Runge-Kutta point
const vector3 pos1 = pos + half_h * dir + h2 * 0.125f * sd.k1;
const typename magnetic_field_t::output_t bvec1 =
magnetic_field.at(pos1[0], pos1[1], pos1[2]);
const auto bvec1 = magnetic_field.at(pos1[0], pos1[1], pos1[2]);
sd.b_middle[0] = bvec1[0];
sd.b_middle[1] = bvec1[1];
sd.b_middle[2] = bvec1[2];
Expand All @@ -202,8 +200,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,

// Last Runge-Kutta point
const vector3 pos2 = pos + h * dir + h2 * 0.5f * sd.k3;
const typename magnetic_field_t::output_t bvec2 =
magnetic_field.at(pos2[0], pos2[1], pos2[2]);
const auto bvec2 = magnetic_field.at(pos2[0], pos2[1], pos2[2]);
sd.b_last[0] = bvec2[0];
sd.b_last[1] = bvec2[1];
sd.b_last[2] = bvec2[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct multi_axis_data {
multi_axis_data() = default;

/// Construct containers using a specific memory resources
DETRAY_HOST_DEVICE
DETRAY_HOST
multi_axis_data(vecmem::memory_resource &resource)
: m_axes_data(&resource), m_edges(&resource) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct grid_data {
grid_data() = default;

/// Construct containers using a memory resources
DETRAY_HOST_DEVICE
DETRAY_HOST
grid_data(vecmem::memory_resource &resource) : m_bin_data(&resource) {}

/// Construct grid data from containers - move
Expand Down
Loading

0 comments on commit 8b3e0d5

Please sign in to comment.