File indexing completed on 2026-10-26 09:34:33
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010
0011 #include "corecel/Types.hh"
0012
0013 #include "AuxInterface.hh"
0014 #include "ParamsDataInterface.hh"
0015 #include "StateDataStore.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template<template<Ownership, MemSpace> class S, MemSpace M>
0042 class AuxState final : public AuxStateInterface
0043 {
0044 public:
0045
0046
0047 using Ref = S<Ownership::reference, M>;
0048
0049
0050 public:
0051
0052 template<template<Ownership, MemSpace> class P>
0053 inline AuxState(HostCRef<P> const& p, StreamId stream_id, size_type size);
0054
0055
0056 inline AuxState(StreamId stream_id, size_type size);
0057
0058
0059 explicit operator bool() const { return static_cast<bool>(store_); }
0060
0061
0062 size_type size() const { return store_.size(); }
0063
0064
0065 Ref& ref() { return store_.ref(); }
0066
0067
0068 Ref const& ref() const { return store_.ref(); }
0069
0070 private:
0071 StateDataStore<S, M> store_;
0072 };
0073
0074
0075
0076
0077
0078
0079 template<template<Ownership, MemSpace> class S,
0080 template<Ownership, MemSpace> class P>
0081 std::unique_ptr<AuxStateInterface> make_aux_state(
0082 ParamsDataInterface<P> const& params,
0083 MemSpace m,
0084 StreamId stream_id,
0085 size_type size)
0086 {
0087 if (m == MemSpace::host)
0088 {
0089 using ASD = AuxState<S, MemSpace::host>;
0090 return std::make_unique<ASD>(params.host_ref(), stream_id, size);
0091 }
0092 else if (m == MemSpace::device)
0093 {
0094 using ASD = AuxState<S, MemSpace::device>;
0095 return std::make_unique<ASD>(params.host_ref(), stream_id, size);
0096 }
0097 CELER_ASSERT_UNREACHABLE();
0098 }
0099
0100
0101
0102
0103
0104 template<template<Ownership, MemSpace> class S>
0105 std::unique_ptr<AuxStateInterface> make_aux_state(
0106 MemSpace m, StreamId stream_id, size_type size)
0107 {
0108 if (m == MemSpace::host)
0109 {
0110 using ASD = AuxState<S, MemSpace::host>;
0111 return std::make_unique<ASD>(stream_id, size);
0112 }
0113 else if (m == MemSpace::device)
0114 {
0115 using ASD = AuxState<S, MemSpace::device>;
0116 return std::make_unique<ASD>(stream_id, size);
0117 }
0118 CELER_ASSERT_UNREACHABLE();
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128 template<template<Ownership, MemSpace> class S, MemSpace M>
0129 template<template<Ownership, MemSpace> class P>
0130 AuxState<S, M>::AuxState(
0131 HostCRef<P> const& p, StreamId stream_id, size_type size)
0132 : store_{p, stream_id, size}
0133 {
0134 }
0135
0136
0137
0138
0139
0140 template<template<Ownership, MemSpace> class S, MemSpace M>
0141 AuxState<S, M>::AuxState(StreamId stream_id, size_type size)
0142 : store_{stream_id, size}
0143 {
0144 }
0145
0146
0147 }