PetaVision  Alpha
PoolingDelivery.hpp
1 /*
2  * PoolingDelivery.hpp
3  *
4  * Created on: Aug 24, 2017
5  * Author: Pete Schultz
6  */
7 
8 #ifndef POOLINGDELIVERY_HPP_
9 #define POOLINGDELIVERY_HPP_
10 
11 #include "components/ImpliedWeightsPair.hpp"
12 #include "components/PatchSize.hpp"
13 #include "delivery/BaseDelivery.hpp"
14 #include "layers/PoolingIndexLayer.hpp"
15 #ifdef PV_USE_CUDA
16 #include "cudakernels/CudaPoolingDeliverKernel.hpp"
17 #endif // PV_USE_CUDA
18 
19 namespace PV {
20 
24 class PoolingDelivery : public BaseDelivery {
25  protected:
42  virtual void ioParam_pvpatchAccumulateType(enum ParamsIOFlag ioFlag);
43 
58  virtual void ioParam_updateGSynFromPostPerspective(enum ParamsIOFlag ioFlag);
59 
60  // This doxygen comment may not be as edifying as it appears.
64  void ioParam_needPostIndexLayer(enum ParamsIOFlag ioFlag);
65 
69  void ioParam_postIndexLayerName(enum ParamsIOFlag ioFlag); // End of list of PoolingDelivery parameters.
71 
72  public:
73  enum AccumulateType { UNDEFINED, MAXPOOLING, SUMPOOLING, AVGPOOLING };
74 
75  PoolingDelivery(char const *name, HyPerCol *hc);
76 
77  virtual ~PoolingDelivery();
78 
79  void setConnectionData(ConnectionData *connectionData);
80 
81  virtual void deliver() override;
82 
83  virtual bool isAllInputReady() override;
84 
85  AccumulateType getAccumulateType() const { return mAccumulateType; }
86 
87  PoolingIndexLayer *getPostIndexLayer() const { return mPostIndexLayer; }
88 
97  static AccumulateType parseAccumulateTypeString(char const *typestring);
98 
99  protected:
100  PoolingDelivery();
101 
102  int initialize(char const *name, HyPerCol *hc);
103 
104  virtual void setObjectType() override;
105 
106  virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
107 
108  virtual Response::Status
109  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
110 
111 #ifdef PV_USE_CUDA
112  virtual Response::Status
113  setCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) override;
114 #endif // PV_USE_CUDA
115 
116  virtual Response::Status allocateDataStructures() override;
117 
118  void initializeDeliverKernelArgs();
119 
120  void allocateThreadGSyn();
121 
122  void deliverPostsynapticPerspective();
123 
124  void deliverPresynapticPerspective();
125 
126  void clearGateIdxBuffer();
127 
128 #ifdef PV_USE_CUDA
129  void deliverGPU();
130 #endif // PV_USE_CUDA
131 
132  // Data members
133  protected:
134  AccumulateType mAccumulateType = UNDEFINED;
135  char *mPvpatchAccumulateTypeString = nullptr;
136  bool mUpdateGSynFromPostPerspective = false;
137 
138  PatchSize *mPatchSize = nullptr;
139  ImpliedWeightsPair *mWeightsPair = nullptr;
140 
141  bool mNeedPostIndexLayer = false;
142  char *mPostIndexLayerName = nullptr;
143  PoolingIndexLayer *mPostIndexLayer = nullptr;
144 
145  std::vector<std::vector<float>> mThreadGSyn;
146  std::vector<std::vector<float>> mThreadGateIdxBuffer;
147 #ifdef PV_USE_CUDA
148  PVCuda::CudaPoolingDeliverKernel *mRecvKernel = nullptr; // Cuda kernel for updating GSyn
149 #endif // PV_USE_CUDA
150 
151 }; // end class PoolingDelivery
152 
153 } // end namespace PV
154 
155 #endif // POOLINGDELIVERY_HPP_
virtual bool isAllInputReady() override
void ioParam_needPostIndexLayer(enum ParamsIOFlag ioFlag)
virtual void ioParam_updateGSynFromPostPerspective(enum ParamsIOFlag ioFlag)
updateGSynFromPostPerspective: Specifies if the connection should push from pre or pull from post...
void ioParam_postIndexLayerName(enum ParamsIOFlag ioFlag)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_pvpatchAccumulateType(enum ParamsIOFlag ioFlag)
pvpatchAccumulateType: Specifies the method to accumulate synaptic input
static AccumulateType parseAccumulateTypeString(char const *typestring)