Skip to content

Commit

Permalink
Extended fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo authored and niermann999 committed Oct 18, 2023
1 parent 181c684 commit d43e8fd
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 68 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
4 changes: 2 additions & 2 deletions io/include/detray/io/common/grid_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class grid_reader : public reader_interface<detector_t> {
typename binning_ts = types::type_list<>, typename... Ts>
static void deserialize(std::queue<n_axis::bounds> &bound_ids,
std::queue<n_axis::binning> &binning_ids,
Ts &&...data) {
Ts &&... data) {
using namespace n_axis;

constexpr std::size_t n_bounds_types{types::size<bounds_ts>};
Expand Down Expand Up @@ -152,7 +152,7 @@ class grid_reader : public reader_interface<detector_t> {
template <typename bounds_ts, typename binning_ts, typename... Ts,
std::enable_if_t<types::size<bounds_ts> == Dim, bool> = true>
static void deserialize(std::queue<n_axis::binning> &binning_ids,
Ts &&...data) {
Ts &&... data) {

using namespace n_axis;

Expand Down
1 change: 1 addition & 0 deletions tests/benchmarks/cuda/benchmark_propagator_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// Project include(s)
#include "benchmark_propagator_cuda_kernel.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/simulation/event_generator/track_generators.hpp"

// Vecmem include(s)
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/cuda/benchmark_propagator_cuda_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "detray/definitions/algebra.hpp"
#include "detray/definitions/units.hpp"
#include "detray/detectors/bfield.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/detectors/toy_metadata.hpp"
#include "detray/propagator/actor_chain.hpp"
#include "detray/propagator/actors/aborters.hpp"
#include "detray/propagator/actors/parameter_resetter.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "detray/definitions/algebra.hpp"
#include "detray/definitions/units.hpp"
#include "detray/detectors/bfield.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/detectors/toy_metadata.hpp"
#include "detray/propagator/actor_chain.hpp"
#include "detray/propagator/actors/aborters.hpp"
#include "detray/propagator/actors/parameter_resetter.hpp"
Expand Down Expand Up @@ -44,6 +44,7 @@ using detector_device_t = detector<toy_metadata, device_container_types>;
// These types are identical in host and device code for all bfield types
using transform3 = typename detector_host_t::transform3;
using vector3_t = typename transform3::vector3;
using point3_t = typename transform3::point3;
using matrix_operator = standard_matrix_operator<scalar>;
using track_t = free_track_parameters<transform3>;
using free_matrix = typename track_t::covariance_type;
Expand All @@ -59,9 +60,6 @@ using constraints_t = constrained_step<>;
template <typename bfield_view_t>
using rk_stepper_t = rk_stepper<bfield_view_t, transform3, constraints_t>;

// Detector configuration
toy_det_config toy_cfg{};

// Geomery navigation configurations
constexpr unsigned int theta_steps{10u};
constexpr unsigned int phi_steps{10u};
Expand Down Expand Up @@ -229,7 +227,7 @@ inline void compare_propagation_results(
const vector3_t &device_pos = device_positions[i][j];

auto relative_error =
static_cast<point3>(1. / host_pl * (host_pos - device_pos));
static_cast<point3_t>(1. / host_pl * (host_pos - device_pos));

ASSERT_NEAR(getter::norm(relative_error), 0.f, is_close);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/unit_tests/device/cuda/navigator_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
* Mozilla Public License Version 2.0
*/

#include <gtest/gtest.h>
// Project include(s)
#include "detray/detectors/create_toy_geometry.hpp"
#include "navigator_cuda_kernel.hpp"

// vecmem include(s)
#include <vecmem/memory/cuda/device_memory_resource.hpp>
#include <vecmem/memory/cuda/managed_memory_resource.hpp>

#include "navigator_cuda_kernel.hpp"
#include "vecmem/utils/cuda/copy.hpp"

// GTest include(s)
#include <gtest/gtest.h>

TEST(navigator_cuda, navigator) {

// Helper object for performing memory copies.
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/device/cuda/navigator_cuda_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
// Project include(s)
#include "detray/definitions/algebra.hpp"
#include "detray/definitions/units.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/detectors/toy_metadata.hpp"
#include "detray/propagator/line_stepper.hpp"
#include "detray/propagator/navigator.hpp"
#include "detray/simulation/event_generator/track_generators.hpp"

using namespace detray;

using transform3 = __plugin::transform3<scalar>;
using point3 = __plugin::point3<scalar>;

// some useful type declarations
using detector_host_t = detector<toy_metadata, host_container_types>;
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/device/cuda/propagator_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// Project include(s)
#include "detray/detectors/bfield.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "propagator_cuda_kernel.hpp"

// Vecmem include(s)
Expand All @@ -32,7 +33,7 @@ TEST_P(CudaPropConstBFieldMng, propagator) {
auto field = bfield::create_const_field(B);

// Create the toy geometry
auto [det, names] = create_toy_geometry(mng_mr, toy_cfg);
auto [det, names] = create_toy_geometry(mng_mr);

run_propagation_test<bfield::const_bknd_t>(
&mng_mr, det, detray::get_data(det), std::move(field));
Expand All @@ -54,7 +55,7 @@ TEST_P(CudaPropConstBFieldCpy, propagator) {
auto field = bfield::create_const_field(B);

// Create the toy geometry
auto [det, names] = create_toy_geometry(host_mr, toy_cfg);
auto [det, names] = create_toy_geometry(host_mr);

auto det_buff = detray::get_buffer(det, dev_mr, cuda_cpy);

Expand Down Expand Up @@ -116,7 +117,7 @@ TEST(CudaPropagatorValidation10, inhomogeneous_bfield_cpy) {
auto field = bfield::create_inhom_field();

// Create the toy geometry with inhomogeneous bfield from file
auto [det, names] = create_toy_geometry(host_mr, toy_cfg);
auto [det, names] = create_toy_geometry(host_mr);

auto det_buff = detray::get_buffer(det, dev_mr, cuda_cpy);

Expand Down
26 changes: 14 additions & 12 deletions tests/unit_tests/device/sycl/propagator.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

// Project include(s)
#include "detray/detectors/create_toy_geometry.hpp"
#include "propagator_sycl_kernel.hpp"

// Vecmem include(s)
Expand Down Expand Up @@ -43,14 +44,16 @@ TEST_P(SyclPropConstBFieldMng, propagator) {
vecmem::sycl::shared_memory_resource shared_mr;

// Set the magnetic field
const vector3 B = GetParam();
const vector3_t B = GetParam();
auto field = bfield::create_const_field(B);

// Create the toy geometry
toy_cfg.bfield_vec(B);
auto [det, names] = create_toy_geometry(shared_mr, toy_cfg);
auto [det, names] = create_toy_geometry(shared_mr);

run_propagation_test<bfield::const_bknd_t>(
&shared_mr, &q, det, detray::get_data<bfield::const_bknd_t>(det));
auto det_view = detray::get_data(det);

run_propagation_test<bfield::const_bknd_t>(&shared_mr, &q, det, det_view,
field);
}

class SyclPropConstBFieldCpy : public ::testing::TestWithParam<vector3_t> {};
Expand All @@ -71,17 +74,16 @@ TEST_P(SyclPropConstBFieldCpy, propagator) {
vecmem::sycl::copy sycl_cpy(q_wrapper);

// Set the magnetic field
const vector3 B = GetParam();
const vector3_t B = GetParam();
auto field = bfield::create_const_field(B);

// Create the toy geometry
toy_cfg.bfield_vec(B);
auto [det, names] = create_toy_geometry(host_mr, toy_cfg);
auto [det, names] = create_toy_geometry(host_mr);

auto det_buff =
detray::get_buffer<bfield::const_bknd_t>(det, dev_mr, sycl_cpy);
auto det_buff = detray::get_buffer(det, dev_mr, sycl_cpy);

run_propagation_test<bfield::const_bknd_t>(&shared_mr, &q, det,
detray::get_data(det_buff));
run_propagation_test<bfield::const_bknd_t>(
&shared_mr, &q, det, detray::get_data(det_buff), field);
}

INSTANTIATE_TEST_SUITE_P(SyclPropagatorValidation1, SyclPropConstBFieldMng,
Expand Down
11 changes: 6 additions & 5 deletions tests/unit_tests/device/sycl/propagator_kernel.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void propagator_test(

reinterpret_cast<::sycl::queue*>(queue.queue())
->submit([&](::sycl::handler& h) {
h.parallel_for(ndrange, [det_data, tracks_data, candidates_data,
path_lengths_data, positions_data,
jac_transports_data](
h.parallel_for(ndrange, [det_data, field_data, tracks_data,
candidates_data, path_lengths_data,
positions_data, jac_transports_data](
::sycl::nd_item<1> item) {
detector_device_t dev_det(det_data);

Expand All @@ -43,7 +43,8 @@ void propagator_test(
candidates(candidates_data);
vecmem::jagged_device_vector<scalar> path_lengths(
path_lengths_data);
vecmem::jagged_device_vector<vector3> positions(positions_data);
vecmem::jagged_device_vector<vector3_t> positions(
positions_data);
vecmem::jagged_device_vector<free_matrix> jac_transports(
jac_transports_data);

Expand Down Expand Up @@ -93,7 +94,7 @@ void propagator_test(
}

/// Explicit instantiation for a constant magnetic field
template void propagator_test<bfield::const_bknd_t>(
template void propagator_test<bfield::const_bknd_t, detector_host_t>(
detector_host_t::view_type, covfie::field_view<bfield::const_bknd_t>,
vecmem::data::vector_view<track_t>&,
vecmem::data::jagged_vector_view<intersection_t<detector_host_t>>&,
Expand Down
1 change: 1 addition & 0 deletions tutorials/src/device/cuda/detector_construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "detector_construction.hpp"

#include "detray/detectors/bfield.hpp"
#include "detray/detectors/create_toy_geometry.hpp"

// Vecmem include(s)
#include <vecmem/memory/cuda/device_memory_resource.hpp>
Expand Down
3 changes: 2 additions & 1 deletion tutorials/src/device/cuda/detector_construction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#pragma once

// Project include(s).
#include "detray/core/detector.hpp"
#include "detray/definitions/units.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/detectors/toy_metadata.hpp"
#include "detray/tutorial/types.hpp"

namespace detray::tutorial {
Expand Down
25 changes: 11 additions & 14 deletions tutorials/src/device/cuda/propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Project include(s)
#include "propagation.hpp"

#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/simulation/event_generator/track_generators.hpp"

// Vecmem include(s)
Expand All @@ -16,23 +17,23 @@

#include "vecmem/utils/cuda/copy.hpp"

// System

/// Prepare the data and move it to device
int main() {
// VecMem memory resource(s)
vecmem::cuda::managed_memory_resource mng_mr;

// Set the magnetic field
// Create the bfield
const auto B =
detray::tutorial::vector3{0. * detray::unit<detray::scalar>::T,
0. * detray::unit<detray::scalar>::T,
2. * detray::unit<detray::scalar>::T};

// Define the name of the input file: use detray unittest data in this case
const std::string field_file = !std::getenv("DETRAY_BFIELD_FILE")
? ""
: std::getenv("DETRAY_BFIELD_FILE");
detray::tutorial::field_host_t bfield =
detray::io::read_bfield<detray::bfield::inhom_field_t>(field_file);
detray::tutorial::field_t bfield = detray::bfield::create_const_field(B);

// Create the toy geometry
detray::toy_det_config toy_cfg{};
auto [det, names] = detray::create_toy_geometry(mng_mr, toy_cfg);
auto [det, names] = detray::create_toy_geometry(mng_mr);

// Create the vector of initial track parameters
vecmem::vector<detray::free_track_parameters<detray::tutorial::transform3>>
Expand Down Expand Up @@ -61,17 +62,13 @@ int main() {
auto det_data = detray::get_data(det);
auto tracks_data = detray::get_data(tracks);

// Get the device bfield
detray::tutorial::field_device_t device_field(bfield);
detray::tutorial::field_device_t::view_t device_field_view(device_field);

// Create navigator candidates buffer
vecmem::copy copy; //< Helper object for performing memory copies.
auto candidates_buffer =
detray::create_candidates_buffer(det, theta_steps * phi_steps, mng_mr);
copy.setup(candidates_buffer);

// Run the propagator test for GPU device
detray::tutorial::propagation(det_data, device_field_view, tracks_data,
detray::tutorial::propagation(det_data, bfield, tracks_data,
candidates_buffer);
}
23 changes: 6 additions & 17 deletions tutorials/src/device/cuda/propagation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#pragma once

// Project include(s).
#include "detray/core/detector.hpp"
#include "detray/definitions/units.hpp"
#include "detray/detectors/bfield.hpp"
#include "detray/detectors/create_toy_geometry.hpp"
#include "detray/detectors/toy_metadata.hpp"
#include "detray/propagator/actor_chain.hpp"
#include "detray/propagator/actors/aborters.hpp"
#include "detray/propagator/actors/parameter_resetter.hpp"
Expand All @@ -22,9 +23,6 @@
#include "detray/tracks/tracks.hpp"
#include "detray/tutorial/types.hpp"

// Covfie include(s)
#include <covfie/cuda/backend/primitive/cuda_device_array.hpp>

namespace detray::tutorial {

// Detector
Expand All @@ -36,18 +34,9 @@ using detector_device_t =
using navigator_t = navigator<detector_device_t>;
using intersection_t = navigator_t::intersection_type;

// Magnetic field types
using inhom_cuda_bknd_t = covfie::backend::affine<
covfie::backend::nearest_neighbour<covfie::backend::strided<
covfie::vector::ulong3,
covfie::backend::cuda_device_array<
covfie::vector::vector_d<detray::scalar, 3>>>>>;
using field_host_t = covfie::field<detray::bfield::inhom_bknd_t>;
using field_device_t = covfie::field<inhom_cuda_bknd_t>;

// Stepper (only running device propagation, so need the device field type)
using stepper_t =
rk_stepper<field_device_t::view_t, detray::tutorial::transform3>;
// Stepper
using field_t = detray::bfield::const_field_t;
using stepper_t = rk_stepper<field_t::view_t, detray::tutorial::transform3>;

// Actors
using actor_chain_t =
Expand All @@ -62,7 +51,7 @@ using propagator_t = propagator<stepper_t, navigator_t, actor_chain_t>;
/// Propagation tutorial function
void propagation(
typename detector_host_t::view_type det_data,
covfie::field_view<inhom_cuda_bknd_t> field_data,
typename field_t::view_t field_data,
const vecmem::data::vector_view<
free_track_parameters<detray::tutorial::transform3>>
tracks_data,
Expand Down
4 changes: 2 additions & 2 deletions tutorials/src/device/cuda/propagation_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inline constexpr detray::scalar path_limit{2.f *
/// Kernel that runs the entire propagation loop
__global__ void propagation_kernel(
typename detray::tutorial::detector_host_t::view_type det_data,
covfie::field_view<detray::tutorial::inhom_cuda_bknd_t> field_data,
typename detray::tutorial::field_t::view_t field_data,
const vecmem::data::vector_view<
detray::free_track_parameters<detray::tutorial::transform3>>
tracks_data,
Expand Down Expand Up @@ -67,7 +67,7 @@ __global__ void propagation_kernel(

void propagation(
typename detray::tutorial::detector_host_t::view_type det_data,
covfie::field_view<detray::tutorial::inhom_cuda_bknd_t> field_data,
typename detray::tutorial::field_t::view_t field_data,
const vecmem::data::vector_view<
detray::free_track_parameters<detray::tutorial::transform3>>
tracks_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct tel_det_config {
template <
typename... Args,
std::enable_if_t<(std::is_same_v<Args, scalar> || ...), bool> = true>
tel_det_config(Args &&...args) : m_mask(0u, std::forward<Args>(args)...) {}
tel_det_config(Args &&... args) : m_mask(0u, std::forward<Args>(args)...) {}

/// Mask of the test surfaces
mask<mask_shape_t> m_mask;
Expand Down

0 comments on commit d43e8fd

Please sign in to comment.