File indexing completed on 2025-01-18 09:54:46
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <memory>
0011
0012 #include "corecel/Types.hh"
0013
0014 #include "AuxInterface.hh"
0015 #include "CollectionStateStore.hh"
0016 #include "ParamsDataInterface.hh"
0017
0018 namespace celeritas
0019 {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 template<template<Ownership, MemSpace> class S, MemSpace M>
0032 class AuxStateData final : public AuxStateInterface
0033 {
0034 public:
0035
0036
0037 using Ref = S<Ownership::reference, M>;
0038
0039
0040 public:
0041
0042 template<template<Ownership, MemSpace> class P>
0043 inline AuxStateData(HostCRef<P> const& p,
0044 StreamId stream_id,
0045 size_type size);
0046
0047
0048 explicit operator bool() const { return static_cast<bool>(store_); }
0049
0050
0051 size_type size() const { return store_.size(); }
0052
0053
0054 Ref& ref() { return store_.ref(); }
0055
0056
0057 Ref const& ref() const { return store_.ref(); }
0058
0059 private:
0060 CollectionStateStore<S, M> store_;
0061 };
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template<template<Ownership, MemSpace> class S, template<Ownership, MemSpace> class P>
0074 std::unique_ptr<AuxStateInterface>
0075 make_aux_state(ParamsDataInterface<P> const& params,
0076 MemSpace m,
0077 StreamId stream_id,
0078 size_type size)
0079 {
0080 if (m == MemSpace::host)
0081 {
0082 return std::make_unique<AuxStateData<S, MemSpace::host>>(
0083 params.host_ref(), stream_id, size);
0084 }
0085 else if (m == MemSpace::device)
0086 {
0087 return std::make_unique<AuxStateData<S, MemSpace::device>>(
0088 params.host_ref(), stream_id, size);
0089 }
0090 CELER_ASSERT_UNREACHABLE();
0091 }
0092
0093
0094
0095
0096
0097
0098
0099 template<template<Ownership, MemSpace> class S, MemSpace M>
0100 template<template<Ownership, MemSpace> class P>
0101 AuxStateData<S, M>::AuxStateData(HostCRef<P> const& p,
0102 StreamId stream_id,
0103 size_type size)
0104 : store_{p, stream_id, size}
0105 {
0106 }
0107
0108
0109 }