File indexing completed on 2025-01-18 10:10:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUBUFFER
0017 #define TMVA_DNN_ARCHITECTURES_CPU_CPUBUFFER
0018
0019 #include "TMVA/DNN/DataLoader.h"
0020
0021 #include <memory>
0022
0023 namespace TMVA
0024 {
0025 namespace DNN
0026 {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 template<typename AFloat>
0043 class TCpuBuffer
0044 {
0045 private:
0046
0047 size_t fSize;
0048 size_t fOffset;
0049 std::shared_ptr<AFloat *> fBuffer;
0050
0051 struct TDestructor
0052 {
0053 void operator()(AFloat ** pointer);
0054 friend TCpuBuffer;
0055 } fDestructor;
0056
0057 public:
0058
0059
0060 TCpuBuffer(size_t size);
0061 TCpuBuffer() = default;
0062 TCpuBuffer(const TCpuBuffer &) = default;
0063 TCpuBuffer( TCpuBuffer &&) = default;
0064 TCpuBuffer & operator=(const TCpuBuffer &) = default;
0065 TCpuBuffer & operator=( TCpuBuffer &&) = default;
0066
0067 operator AFloat * () const {return (* fBuffer) + fOffset;}
0068
0069 class FakeIteratorBegin{
0070 private:
0071 AFloat& fBeginRet;
0072 public:
0073 FakeIteratorBegin(AFloat& x): fBeginRet(x){}
0074 AFloat& operator*()
0075 {
0076 return fBeginRet;
0077 }
0078 };
0079 FakeIteratorBegin begin(){
0080 return FakeIteratorBegin(*((* fBuffer) + fOffset));
0081 }
0082
0083
0084
0085
0086 TCpuBuffer GetSubBuffer(size_t offset, size_t start) const;
0087
0088 AFloat & operator[](size_t i) {return (*fBuffer.get())[fOffset + i];}
0089 AFloat operator[](size_t i) const {return (*fBuffer.get())[fOffset + i];}
0090
0091
0092
0093 void CopyFrom(const TCpuBuffer &);
0094
0095
0096 void CopyTo(TCpuBuffer &) const;
0097
0098
0099
0100
0101
0102 size_t GetSize() const {return fSize;}
0103
0104 size_t GetUseCount() const { return fBuffer.use_count(); }
0105 };
0106
0107 }
0108 }
0109
0110 #endif