|
7 | 7 |
|
8 | 8 | // Detray test include(s)
|
9 | 9 | #include "detector_cuda_kernel.hpp"
|
| 10 | +#include "detray/core/detail/alignment.hpp" |
| 11 | +#include "detray/definitions/detail/algebra.hpp" |
10 | 12 | #include "detray/test/utils/detectors/build_toy_detector.hpp"
|
| 13 | +#include "detray/test/utils/types.hpp" |
11 | 14 |
|
12 | 15 | // Vecmem include(s)
|
13 | 16 | #include <vecmem/memory/cuda/device_memory_resource.hpp>
|
@@ -96,3 +99,80 @@ TEST(detector_cuda, detector) {
|
96 | 99 | EXPECT_EQ(cylinders_host[i] == cylinders_device[i], true);
|
97 | 100 | }
|
98 | 101 | }
|
| 102 | + |
| 103 | +TEST(detector_cuda, detector_alignment) { |
| 104 | + // memory resources |
| 105 | + vecmem::host_memory_resource host_mr; |
| 106 | + vecmem::cuda::device_memory_resource dev_mr; |
| 107 | + vecmem::cuda::managed_memory_resource mng_mr; |
| 108 | + |
| 109 | + // helper object for performing memory copies to CUDA devices |
| 110 | + vecmem::cuda::copy cuda_cpy; |
| 111 | + |
| 112 | + // create toy geometry in host memory |
| 113 | + auto [det_host, names_host] = build_toy_detector(host_mr); |
| 114 | + |
| 115 | + // copy static detector data (including the initial set of transforms) to |
| 116 | + // the device |
| 117 | + // use synchronous copy and fixed size buffers |
| 118 | + auto det_buff_static = detray::get_buffer(det_host, dev_mr, cuda_cpy); |
| 119 | + |
| 120 | + // ---------- construct an "aligned" transform store --------- |
| 121 | + // a few typedefs |
| 122 | + using test_algebra = test::algebra; |
| 123 | + using scalar = dscalar<test_algebra>; |
| 124 | + using point3 = dpoint3D<test_algebra>; |
| 125 | + |
| 126 | + // build a vector of aligned transforms on the host |
| 127 | + // for populating this vector take all transforms of the detector |
| 128 | + // and shift them by the same translation |
| 129 | + typename detector_host_t::transform_container tf_store_aligned_host; |
| 130 | + |
| 131 | + point3 shift{.1f * unit<scalar>::mm, .2f * unit<scalar>::mm, |
| 132 | + .3f * unit<scalar>::mm}; |
| 133 | + |
| 134 | + tf_store_aligned_host.reserve( |
| 135 | + det_host.transform_store().size(), |
| 136 | + typename decltype(det_host)::transform_container::context_type{}); |
| 137 | + |
| 138 | + for (const auto& tf : det_host.transform_store()) { |
| 139 | + point3 shifted = tf.translation() + shift; |
| 140 | + tf_store_aligned_host.push_back( |
| 141 | + transform_t{shifted, tf.x(), tf.y(), tf.z()}); |
| 142 | + } |
| 143 | + |
| 144 | + // copy the vector of aligned transforms to the device |
| 145 | + // again, use synchronous copy and fixed size buffers |
| 146 | + auto tf_buff_aligned = |
| 147 | + get_buffer(tf_store_aligned_host, dev_mr, cuda_cpy, copy::sync, |
| 148 | + vecmem::data::buffer_type::fixed_size); |
| 149 | + |
| 150 | + // Get the view of the aligned detector using the vector of aligned transforms |
| 151 | + // and the static part of the detector copied to the device earlier |
| 152 | + auto detector_view_aligned = |
| 153 | + detail::misaligned_detector_view<detector_host_t>(det_buff_static, |
| 154 | + tf_buff_aligned); |
| 155 | + // Get the view of the static detector |
| 156 | + auto detector_view_static = detray::get_data(det_buff_static); |
| 157 | + |
| 158 | + // make two vectors for surface transforms copied from device side |
| 159 | + vecmem::vector<transform_t> surfacexf_device_static(det_host.surfaces().size(), |
| 160 | + &mng_mr); |
| 161 | + vecmem::vector<transform_t> surfacexf_device_aligned(det_host.surfaces().size(), |
| 162 | + &mng_mr); |
| 163 | + // views of the above vectors |
| 164 | + auto surfacexf_data_static = vecmem::get_data(surfacexf_device_static); |
| 165 | + auto surfacexf_data_aligned = vecmem::get_data(surfacexf_device_aligned); |
| 166 | + |
| 167 | + // run the test code to extract the surface transforms for the static |
| 168 | + // and misaligned detector views and to store them into the vectors |
| 169 | + detector_alignment_test(detector_view_static, detector_view_aligned, |
| 170 | + surfacexf_data_static, surfacexf_data_aligned); |
| 171 | + |
| 172 | + // check that the relevant transforms have been properly shifted |
| 173 | + for (unsigned int i = 0u; i < surfacexf_device_static.size(); i++) { |
| 174 | + auto transdiff = surfacexf_device_aligned[i].translation() |
| 175 | + - surfacexf_device_static[i].translation(); |
| 176 | + EXPECT_EQ(transdiff == shift, true); |
| 177 | + } |
| 178 | +} |
0 commit comments