File indexing completed on 2026-01-10 10:05:47
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Span.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/math/Algorithms.hh"
0014
0015 #include "../GeneratorData.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022 template<MemSpace M>
0023 using GeneratorDistributionRef
0024 = Collection<GeneratorDistributionData, Ownership::reference, M>;
0025
0026
0027 struct IsInvalid
0028 {
0029
0030 CELER_FUNCTION bool operator()(GeneratorDistributionData const& data) const
0031 {
0032 return !data;
0033 }
0034 };
0035
0036
0037
0038
0039
0040
0041
0042
0043 inline CELER_FUNCTION size_type find_distribution_index(Span<size_type> offsets,
0044 size_type value)
0045 {
0046 CELER_EXPECT(!offsets.empty());
0047
0048 auto iter = celeritas::lower_bound(offsets.begin(), offsets.end(), value);
0049 CELER_ASSERT(iter != offsets.end());
0050
0051 if (value == *iter)
0052 {
0053 ++iter;
0054 }
0055 return iter - offsets.begin();
0056 }
0057
0058
0059
0060 size_type remove_if_invalid(GeneratorDistributionRef<MemSpace::host> const&,
0061 size_type,
0062 size_type,
0063 StreamId);
0064 size_type remove_if_invalid(GeneratorDistributionRef<MemSpace::device> const&,
0065 size_type,
0066 size_type,
0067 StreamId);
0068
0069
0070
0071 size_type count_num_photons(GeneratorDistributionRef<MemSpace::host> const&,
0072 size_type,
0073 size_type,
0074 StreamId);
0075 size_type count_num_photons(GeneratorDistributionRef<MemSpace::device> const&,
0076 size_type,
0077 size_type,
0078 StreamId);
0079
0080
0081
0082 size_type inclusive_scan_photons(
0083 GeneratorDistributionRef<MemSpace::host> const&,
0084 Collection<size_type, Ownership::reference, MemSpace::host> const&,
0085 size_type,
0086 StreamId);
0087 size_type inclusive_scan_photons(
0088 GeneratorDistributionRef<MemSpace::device> const&,
0089 Collection<size_type, Ownership::reference, MemSpace::device> const&,
0090 size_type,
0091 StreamId);
0092
0093
0094
0095
0096 #if !CELER_USE_DEVICE
0097 inline size_type
0098 remove_if_invalid(GeneratorDistributionRef<MemSpace::device> const&,
0099 size_type,
0100 size_type,
0101 StreamId)
0102 {
0103 CELER_NOT_CONFIGURED("CUDA OR HIP");
0104 }
0105
0106 inline size_type
0107 count_num_photons(GeneratorDistributionRef<MemSpace::device> const&,
0108 size_type,
0109 size_type,
0110 StreamId)
0111 {
0112 CELER_NOT_CONFIGURED("CUDA OR HIP");
0113 }
0114
0115 inline size_type inclusive_scan_photons(
0116 GeneratorDistributionRef<MemSpace::device> const&,
0117 Collection<size_type, Ownership::reference, MemSpace::device> const&,
0118 size_type,
0119 StreamId)
0120 {
0121 CELER_NOT_CONFIGURED("CUDA OR HIP");
0122 }
0123 #endif
0124
0125 }
0126 }