File indexing completed on 2025-09-15 08:55:04
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <algorithm>
0010
0011 #include "corecel/Assert.hh"
0012 #include "corecel/Macros.hh"
0013 #include "corecel/Types.hh"
0014 #include "corecel/cont/Span.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021
0022
0023 template<class T, MemSpace M>
0024 class Filler
0025 {
0026 public:
0027
0028 explicit Filler(T value) : value_{value} {}
0029
0030
0031 Filler(T value, StreamId stream) : value_{value}, stream_{stream} {}
0032
0033
0034 inline void operator()(Span<T> data) const;
0035
0036 private:
0037 T value_;
0038 StreamId stream_;
0039
0040 void fill_device_impl(Span<T> data) const;
0041 };
0042
0043
0044
0045
0046
0047 template<class T, MemSpace M>
0048 void Filler<T, M>::operator()(Span<T> data) const
0049 {
0050 if constexpr (M == MemSpace::device)
0051 {
0052 this->fill_device_impl(data);
0053 }
0054 else
0055 {
0056 std::fill(data.begin(), data.end(), value_);
0057 }
0058 }
0059
0060
0061 #if !CELER_USE_DEVICE
0062 template<class T, MemSpace M>
0063 CELER_FORCEINLINE void Filler<T, M>::fill_device_impl(Span<T>) const
0064 {
0065 CELER_DISCARD(stream_);
0066 CELER_ASSERT_UNREACHABLE();
0067 }
0068 #else
0069 extern template class Filler<real_type, MemSpace::device>;
0070 extern template class Filler<size_type, MemSpace::device>;
0071 extern template class Filler<int, MemSpace::device>;
0072 extern template class Filler<TrackSlotId, MemSpace::device>;
0073 #endif
0074
0075
0076 }