File indexing completed on 2025-09-17 08:59:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #pragma once
0015
0016 #include "RaytraceImager.hh"
0017
0018 #include "corecel/data/CollectionStateStore.hh"
0019 #include "corecel/sys/KernelLauncher.hh"
0020
0021 #include "Image.hh"
0022
0023 #include "detail/RaytraceExecutor.hh"
0024
0025 #define CELER_INST_RAYTRACE_IMAGER
0026
0027 namespace celeritas
0028 {
0029
0030 template<class G>
0031 struct RaytraceImager<G>::CachedStates
0032 {
0033 template<MemSpace M>
0034 using StateStore = CollectionStateStore<GeoStateData, M>;
0035
0036 StateStore<MemSpace::host> host;
0037 StateStore<MemSpace::device> device;
0038
0039
0040 template<MemSpace M>
0041 StateStore<M>& get()
0042 {
0043 if constexpr (M == MemSpace::host)
0044 {
0045 return host;
0046 }
0047 else
0048 {
0049 return device;
0050 }
0051 }
0052 };
0053
0054
0055
0056
0057
0058 template<class G>
0059 RaytraceImager<G>::RaytraceImager(SPGeometry geo)
0060 : geo_{std::move(geo)}, cache_{std::make_shared<CachedStates>()}
0061 {
0062 CELER_EXPECT(geo_);
0063 CELER_ENSURE(cache_);
0064 }
0065
0066
0067
0068
0069
0070 template<class G>
0071 void RaytraceImager<G>::operator()(Image<MemSpace::host>* image)
0072 {
0073 return this->raytrace_impl(image);
0074 }
0075
0076
0077
0078
0079
0080 template<class G>
0081 void RaytraceImager<G>::operator()(Image<MemSpace::device>* image)
0082 {
0083 return this->raytrace_impl(image);
0084 }
0085
0086
0087
0088
0089
0090 template<class G>
0091 template<MemSpace M>
0092 void RaytraceImager<G>::raytrace_impl(Image<M>* image)
0093 {
0094 CELER_EXPECT(image);
0095
0096 auto const& img_params = *image->params();
0097 auto const& geo_params = *geo_;
0098 auto& geo_state_store = cache_->template get<M>();
0099
0100 if (img_params.num_lines() != geo_state_store.size())
0101 {
0102 using StateStore = typename CachedStates::template StateStore<M>;
0103
0104
0105 if (geo_state_store)
0106 {
0107 geo_state_store = {};
0108 }
0109 geo_state_store
0110 = StateStore{geo_params.host_ref(), img_params.num_lines()};
0111 }
0112
0113
0114 this->launch_raytrace_kernel(geo_params.template ref<M>(),
0115 geo_state_store.ref(),
0116 img_params.template ref<M>(),
0117 image->ref());
0118 }
0119
0120
0121
0122
0123
0124 template<class G>
0125 void RaytraceImager<G>::launch_raytrace_kernel(
0126 GeoParamsCRef<MemSpace::host> const& geo_params,
0127 GeoStateRef<MemSpace::host> const& geo_states,
0128 ImageParamsCRef<MemSpace::host> const& img_params,
0129 ImageStateRef<MemSpace::host> const& img_state) const
0130 {
0131 using CalcId = detail::VolumeIdCalculator;
0132 using Executor = detail::RaytraceExecutor<GeoTrackView, CalcId>;
0133
0134 launch_kernel(
0135 geo_states.size(),
0136 Executor{geo_params, geo_states, img_params, img_state, CalcId{}});
0137 }
0138
0139
0140
0141
0142
0143 #if !CELER_USE_DEVICE
0144 template<class G>
0145 void RaytraceImager<G>::launch_raytrace_kernel(
0146 GeoParamsCRef<MemSpace::device> const&,
0147 GeoStateRef<MemSpace::device> const&,
0148 ImageParamsCRef<MemSpace::device> const&,
0149 ImageStateRef<MemSpace::device> const&) const
0150 {
0151 CELER_NOT_CONFIGURED("CUDA OR HIP");
0152 }
0153 #endif
0154
0155
0156 }