File indexing completed on 2025-10-29 08:39:39
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <numeric>
0010 #include <vector>
0011
0012 #include "Collection.hh"
0013 #include "Copier.hh"
0014 #include "Filler.hh"
0015
0016 namespace celeritas
0017 {
0018
0019
0020
0021
0022
0023
0024
0025 template<class T, Ownership W, MemSpace M, class I>
0026 void fill(T&& value, Collection<T, W, M, I>* col)
0027 {
0028 static_assert(W != Ownership::const_reference,
0029 "const references cannot be filled");
0030 CELER_EXPECT(col);
0031 Filler<T, M> fill_impl{std::forward<T>(value)};
0032 fill_impl((*col)[AllItems<T, M>{}]);
0033 }
0034
0035
0036
0037
0038
0039 template<class T, Ownership W, MemSpace M, class I>
0040 void fill_sequence(Collection<T, W, M, I>* dst, StreamId stream)
0041 {
0042 static_assert(W != Ownership::const_reference,
0043 "const references cannot be filled");
0044 CELER_EXPECT(dst);
0045
0046 std::vector<T> src(dst->size());
0047 std::iota(src.begin(), src.end(), T{0});
0048 Copier<T, M> copy{(*dst)[AllItems<T, M>{}], stream};
0049 copy(MemSpace::host, make_span(src));
0050 }
0051
0052
0053
0054
0055
0056 template<class T, Ownership W, MemSpace M, class I, std::size_t E>
0057 void copy_to_host(Collection<T, W, M, I> const& src,
0058 Span<T, E> dst,
0059 StreamId sid = {})
0060 {
0061 CELER_EXPECT(src.size() == dst.size());
0062 Copier<T, MemSpace::host> copy_to_result{dst, sid};
0063 copy_to_result(M, src[AllItems<T, M>{}]);
0064 }
0065
0066
0067
0068
0069
0070
0071
0072 template<class T, Ownership W, MemSpace M, class I>
0073 auto copy_to_host(Collection<T, W, M, I> const& src)
0074 {
0075 Collection<T, Ownership::value, MemSpace::host, I> result;
0076 result = src;
0077 return result;
0078 }
0079
0080
0081 }