Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CpuBuffer.h
Go to the documentation of this file.
1// @(#)root/tmva/tmva/dnn:$Id$
2// Author: Simon Pfreundschuh 12/08/16
3
4/*************************************************************************
5 * Copyright (C) 2016, Simon Pfreundschuh *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/////////////////////////////////////////////////////////////
13// CPU Buffer interface class for the generic data loader. //
14/////////////////////////////////////////////////////////////
15
16#ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUBUFFER
17#define TMVA_DNN_ARCHITECTURES_CPU_CPUBUFFER
18
19#include "TMVA/DNN/DataLoader.h"
20
21#include <memory>
22
23namespace TMVA
24{
25namespace DNN
26{
27
28/** TCpuBuffer
29 *
30 * Since the memory on the CPU is homogeneous, only one buffer class is required.
31 * The host and device buffer classes are the same and copying between the host
32 * and device buffer is achieved by simply swapping the memory pointers.
33 *
34 * Memory is handled as a shared pointer to a pointer of type AFloat, which is
35 * the floating point type used for the implementation.
36 *
37 * Copying and assignment of TCpuBuffer objects performs only a shallow copy
38 * meaning the underlying data is shared between those objects.
39 *
40 * \tparam AFloat The floating point type used for the computations.
41 */
42template<typename AFloat>
44{
45private:
46
47 size_t fSize;
48 size_t fOffset;
49 std::shared_ptr<AFloat *> fBuffer;
50
52 {
53 void operator()(AFloat ** pointer);
54 friend TCpuBuffer;
56
57public:
58
59 /** Construct buffer to hold \p size numbers of type \p AFloat.*/
60 TCpuBuffer(size_t size);
61 TCpuBuffer() = default;
62 TCpuBuffer(const TCpuBuffer &) = default;
63 TCpuBuffer( TCpuBuffer &&) = default;
64 TCpuBuffer & operator=(const TCpuBuffer &) = default;
66
67 inline operator AFloat * () const { return data(); }
68 AFloat * data() const {return (* fBuffer) + fOffset;}
69
71 private:
72 AFloat& fBeginRet;
73 public:
75 AFloat& operator*()
76 {
77 return fBeginRet;
78 }
79 };
81 return FakeIteratorBegin(*((* fBuffer) + fOffset));
82 }
83
84
85
86 /** Return sub-buffer of size \p start starting at element \p offset. */
87 TCpuBuffer GetSubBuffer(size_t offset, size_t start) const;
88
89 AFloat & operator[](size_t i) {return (*fBuffer.get())[fOffset + i];}
90 AFloat operator[](size_t i) const {return (*fBuffer.get())[fOffset + i];}
91
92 /** Copy data from another buffer. No real copying is performed, only the
93 * data pointers are swapped. */
94 void CopyFrom(const TCpuBuffer &);
95 /** Copy data to another buffer. No real copying is performed, only the
96 * data pointers are swapped. */
97 void CopyTo(TCpuBuffer &) const;
98
99 /**
100 * copy pointer from an external
101 */
102
103 size_t GetSize() const {return fSize;}
104
105 size_t GetUseCount() const { return fBuffer.use_count(); }
106};
107
108} // namespace DNN
109} // namespace TMVA
110
111#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
TCpuBuffer GetSubBuffer(size_t offset, size_t start) const
Return sub-buffer of size start starting at element offset.
Definition CpuBuffer.cxx:47
size_t GetSize() const
copy pointer from an external
Definition CpuBuffer.h:103
AFloat * data() const
Definition CpuBuffer.h:68
void CopyTo(TCpuBuffer &) const
Copy data to another buffer.
Definition CpuBuffer.cxx:65
TCpuBuffer & operator=(const TCpuBuffer &)=default
AFloat & operator[](size_t i)
Definition CpuBuffer.h:89
AFloat operator[](size_t i) const
Definition CpuBuffer.h:90
TCpuBuffer(TCpuBuffer &&)=default
FakeIteratorBegin begin()
Definition CpuBuffer.h:80
void CopyFrom(const TCpuBuffer &)
Copy data from another buffer.
Definition CpuBuffer.cxx:57
std::shared_ptr< AFloat * > fBuffer
Definition CpuBuffer.h:49
TCpuBuffer & operator=(TCpuBuffer &&)=default
TCpuBuffer(const TCpuBuffer &)=default
struct TMVA::DNN::TCpuBuffer::TDestructor fDestructor
size_t GetUseCount() const
Definition CpuBuffer.h:105
Double_t x[n]
Definition legend1.C:17
create variable transformations
void operator()(AFloat **pointer)
Definition CpuBuffer.cxx:30