PetaVision  Alpha
Messages.hpp
1 /*
2  * Messages.hpp
3  *
4  * Created on: Jul 21, 2016
5  * Author: pschultz
6  *
7  * The subclasses of BaseMessage used by the HyPerCol.
8  */
9 
10 #ifndef MESSAGES_HPP_
11 #define MESSAGES_HPP_
12 
13 #include "cMakeHeader.h"
14 #include "observerpattern/BaseMessage.hpp"
15 #include "observerpattern/Observer.hpp"
16 #include "utils/Timer.hpp"
17 #include <map>
18 #include <string>
19 
20 #ifdef PV_USE_CUDA
21 #include "arch/cuda/CudaDevice.hpp"
22 #endif // PV_USE_CUDA
23 
24 namespace PV {
25 
27  public:
28  CommunicateInitInfoMessage(std::map<std::string, Observer *> const &hierarchy) {
29  setMessageType("CommunicateInitInfo");
30  mHierarchy = hierarchy;
31  }
32  template <typename T>
33  T *lookup(std::string const &name) const {
34  auto search = mHierarchy.find(name);
35  if (search == mHierarchy.end()) {
36  return nullptr;
37  }
38  else {
39  T *result = dynamic_cast<T *>(search->second);
40  return result;
41  }
42  }
43  std::map<std::string, Observer *> mHierarchy;
44 };
45 
46 #ifdef PV_USE_CUDA
48  public:
49  SetCudaDeviceMessage(PVCuda::CudaDevice *device) {
50  setMessageType("SetCudaDevice");
51  mCudaDevice = device;
52  }
53  PVCuda::CudaDevice *mCudaDevice = nullptr;
54 };
55 #endif // PV_USE_CUDA
56 
58  public:
59  AllocateDataMessage() { setMessageType("AllocateDataStructures"); }
60 };
61 
63  public:
64  LayerSetMaxPhaseMessage(int *maxPhase) {
65  setMessageType("LayerSetPhase");
66  mMaxPhase = maxPhase;
67  }
68  int *mMaxPhase = nullptr;
69 };
70 
72  public:
73  LayerWriteParamsMessage() { setMessageType("LayerWriteParams"); }
74 };
75 
77  public:
78  ConnectionWriteParamsMessage() { setMessageType("ConnectionWriteParams"); }
79 };
81  public:
82  ColProbeWriteParamsMessage() { setMessageType("ColProbeWriteParams"); }
83 };
85  public:
86  LayerProbeWriteParamsMessage() { setMessageType("LayerProbeWriteParams"); }
87 };
89  public:
90  ConnectionProbeWriteParamsMessage() { setMessageType("ConnectionProbeWriteParams"); }
91 };
92 
94  public:
95  InitializeStateMessage() { setMessageType("InitializeState"); }
96 };
97 
99  public:
100  CopyInitialStateToGPUMessage() { setMessageType("CopyInitialStateToGPU"); }
101 };
102 
104  public:
105  AdaptTimestepMessage() { setMessageType("AdaptTimestep"); }
106 };
107 
109  public:
110  ConnectionUpdateMessage(double simTime, double deltaTime) {
111  setMessageType("ConnectionUpdate");
112  mTime = simTime;
113  mDeltaT = deltaTime;
114  }
115  double mTime;
116  double mDeltaT; // TODO: this should be the nbatch-sized vector of adaptive
117  // timesteps
118 };
119 
121  public:
122  ConnectionNormalizeMessage() { setMessageType("ConnectionNormalizeMessage"); }
123 };
124 
126  public:
127  ConnectionFinalizeUpdateMessage(double simTime, double deltaTime) {
128  setMessageType("ConnectionFinalizeUpdate");
129  mTime = simTime;
130  mDeltaT = deltaTime;
131  }
132  double mTime;
133  double mDeltaT; // TODO: this should be the nbatch-sized vector of adaptive
134  // timesteps
135 };
136 
138  public:
139  ConnectionOutputMessage(double simTime, double deltaTime) {
140  setMessageType("ConnectionOutput");
141  mTime = simTime;
142  mDeltaT = deltaTime;
143  }
144  double mTime;
145  double mDeltaT;
146 };
147 
149  public:
150  LayerClearProgressFlagsMessage() { setMessageType("LayerClearProgressFlags"); }
151 };
152 
154  public:
156  int phase,
157  Timer *timer,
158 #ifdef PV_USE_CUDA
159  bool recvOnGpuFlag,
160 #endif // PV_USE_CUDA
161  double simTime,
162  double deltaTime,
163  bool *someLayerIsPending,
164  bool *someLayerHasActed) {
165  setMessageType("LayerRecvSynapticInput");
166  mPhase = phase;
167  mTimer = timer;
168 #ifdef PV_USE_CUDA
169  mRecvOnGpuFlag = recvOnGpuFlag;
170 #endif // PV_USE_CUDA
171  mTime = simTime;
172  mDeltaT = deltaTime;
173  mSomeLayerIsPending = someLayerIsPending;
174  mSomeLayerHasActed = someLayerHasActed;
175  }
176  int mPhase;
177  Timer *mTimer;
178 #ifdef PV_USE_CUDA
179  bool mRecvOnGpuFlag;
180 #endif // PV_USE_CUDA
181  double mTime;
182  double mDeltaT; // TODO: this should be the nbatch-sized vector of adaptive
183  // timesteps
184  bool *mSomeLayerIsPending;
185  bool *mSomeLayerHasActed;
186 };
187 
189  public:
191  int phase,
192 #ifdef PV_USE_CUDA
193  bool recvOnGpuFlag,
194  bool updateOnGpuFlag,
195 // updateState needs recvOnGpuFlag because correct order of updating depends on it.
196 #endif // PV_USE_CUDA
197  double simTime,
198  double deltaTime,
199  bool *someLayerIsPending,
200  bool *someLayerHasActed) {
201  setMessageType("LayerUpdateState");
202  mPhase = phase;
203 #ifdef PV_USE_CUDA
204  mRecvOnGpuFlag = recvOnGpuFlag;
205  mUpdateOnGpuFlag = updateOnGpuFlag;
206 #endif // PV_USE_CUDA
207  mTime = simTime;
208  mDeltaT = deltaTime;
209  mSomeLayerIsPending = someLayerIsPending;
210  mSomeLayerHasActed = someLayerHasActed;
211  }
212  int mPhase;
213 #ifdef PV_USE_CUDA
214  bool mRecvOnGpuFlag;
215  bool mUpdateOnGpuFlag;
216 #endif // PV_USE_CUDA
217  double mTime;
218  double mDeltaT; // TODO: this should be the nbatch-sized vector of adaptive
219  // timesteps
220  bool *mSomeLayerIsPending;
221  bool *mSomeLayerHasActed;
222 };
223 
224 #ifdef PV_USE_CUDA
226  public:
227  LayerCopyFromGpuMessage(int phase, Timer *timer) {
228  setMessageType("LayerCopyFromGpu");
229  mPhase = phase;
230  mTimer = timer;
231  }
232  int mPhase;
233  Timer *mTimer;
234 };
235 #endif // PV_USE_CUDA
236 
238  public:
239  LayerAdvanceDataStoreMessage(int phase) {
240  setMessageType("LayerAdvanceDataStore");
241  mPhase = phase;
242  }
243  int mPhase;
244 };
245 
247  public:
248  LayerPublishMessage(int phase, double simTime) {
249  setMessageType("LayerPublish");
250  mPhase = phase;
251  mTime = simTime;
252  }
253  int mPhase;
254  double mTime;
255 };
256 
257 // LayerUpdateActiveIndices message removed Feb 3, 2017.
258 // Active indices are updated by waitOnPublish, and by isExchangeFinished if
259 // the MPI exchange has completed.
260 
262  public:
263  LayerOutputStateMessage(int phase, double simTime) {
264  setMessageType("LayerOutputState");
265  mPhase = phase;
266  mTime = simTime;
267  }
268  int mPhase;
269  double mTime;
270 };
271 
273  public:
274  LayerCheckNotANumberMessage(int phase) {
275  setMessageType("LayerCheckNotANumber");
276  mPhase = phase;
277  }
278  int mPhase;
279 };
280 
282  public:
283  ColProbeOutputStateMessage(double simTime, double deltaTime) {
284  setMessageType("ColProbeOutputState");
285  mTime = simTime;
286  mDeltaTime = deltaTime;
287  }
288  double mTime;
289  double mDeltaTime;
290 };
291 
292 class CleanupMessage : public BaseMessage {
293  public:
294  CleanupMessage() { setMessageType("Cleanup"); }
295 };
296 
297 } /* namespace PV */
298 
299 #endif /* MESSAGES_HPP_ */