8 #include "HyPerDeliveryFacade.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "utils/MapLookupByType.hpp" 14 HyPerDeliveryFacade::HyPerDeliveryFacade(
char const *name, HyPerCol *hc) { initialize(name, hc); }
16 HyPerDeliveryFacade::HyPerDeliveryFacade() {}
18 HyPerDeliveryFacade::~HyPerDeliveryFacade() {
19 delete mDeliveryIntern;
22 int HyPerDeliveryFacade::initialize(
char const *name, HyPerCol *hc) {
23 return BaseDelivery::initialize(name, hc);
26 void HyPerDeliveryFacade::setObjectType() { mObjectType =
"HyPerDeliveryFacade"; }
32 if (ioFlag == PARAMS_IO_READ) {
33 createDeliveryIntern();
35 if (mDeliveryIntern) {
36 mDeliveryIntern->
ioParams(ioFlag,
false,
false);
42 parent->parameters()->ioParamString(
43 ioFlag, name,
"pvpatchAccumulateType", &mAccumulateTypeString,
"convolve");
44 if (ioFlag == PARAMS_IO_READ) {
45 pvAssert(mAccumulateTypeString and mAccumulateTypeString[0]);
47 for (
char *c = mAccumulateTypeString; *c !=
'\0'; c++) {
48 *c = (char)tolower((
int)*c);
51 if (strcmp(mAccumulateTypeString,
"convolve") == 0) {
52 mAccumulateType = HyPerDelivery::CONVOLVE;
54 else if (strcmp(mAccumulateTypeString,
"stochastic") == 0) {
55 mAccumulateType = HyPerDelivery::STOCHASTIC;
58 if (parent->getCommunicator()->globalCommRank() == 0) {
60 "%s error: pvpatchAccumulateType \"%s\" is unrecognized.\n",
62 mAccumulateTypeString);
63 ErrorLog().printf(
" Allowed values are \"convolve\" or \"stochastic\".\n");
65 MPI_Barrier(parent->getCommunicator()->globalCommunicator());
69 pvAssert(!parent->parameters()->presentAndNotBeenRead(name,
"receiveGpu"));
71 mReceiveGpu and mAccumulateType == HyPerDelivery::STOCHASTIC,
72 "%s sets receiveGpu to true and pvpatchAccumulateType to stochastic, " 73 "but stochastic release has not been implemented on the GPU.\n",
78 parent->parameters()->ioParamValue(
81 "updateGSynFromPostPerspective",
82 &mUpdateGSynFromPostPerspective,
83 mUpdateGSynFromPostPerspective);
86 void HyPerDeliveryFacade::createDeliveryIntern() {
88 if (getChannelCode() == CHANNEL_NOUPDATE) {
89 mDeliveryIntern =
nullptr;
93 if (getReceiveGpu()) {
95 if (getUpdateGSynFromPostPerspective()) {
96 baseObject = Factory::instance()->createByKeyword(
97 "PostsynapticPerspectiveGPUDelivery", name, parent);
100 baseObject = Factory::instance()->createByKeyword(
101 "PresynapticPerspectiveGPUDelivery", name, parent);
105 #endif // PV_USE_CUDA 108 switch (mAccumulateType) {
109 case HyPerDelivery::CONVOLVE:
110 if (getUpdateGSynFromPostPerspective()) {
111 baseObject = Factory::instance()->createByKeyword(
112 "PostsynapticPerspectiveConvolveDelivery", name, parent);
115 baseObject = Factory::instance()->createByKeyword(
116 "PresynapticPerspectiveConvolveDelivery", name, parent);
119 case HyPerDelivery::STOCHASTIC:
120 if (getUpdateGSynFromPostPerspective()) {
121 baseObject = Factory::instance()->createByKeyword(
122 "PostsynapticPerspectiveStochasticDelivery", name, parent);
125 baseObject = Factory::instance()->createByKeyword(
126 "PresynapticPerspectiveStochasticDelivery", name, parent);
134 if (baseObject !=
nullptr) {
136 pvAssert(mDeliveryIntern);
140 Response::Status HyPerDeliveryFacade::communicateInitInfo(
141 std::shared_ptr<CommunicateInitInfoMessage const> message) {
142 auto status = BaseDelivery::communicateInitInfo(message);
148 if (mDeliveryIntern) {
149 Response::Status internStatus = mDeliveryIntern->respond(message);
150 if (internStatus == Response::POSTPONE) {
151 return Response::POSTPONE;
154 mUsingGPUFlag = mDeliveryIntern->
isUsingGPU();
155 #endif // PV_USE_CUDA 158 return Response::SUCCESS;
163 HyPerDeliveryFacade::setCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) {
164 auto status = BaseDelivery::setCudaDevice(message);
165 if (status != Response::SUCCESS) {
168 if (mDeliveryIntern) {
169 status = mDeliveryIntern->respond(message);
173 #endif // PV_USE_CUDA 175 Response::Status HyPerDeliveryFacade::allocateDataStructures() {
176 auto status = BaseDelivery::allocateDataStructures();
178 auto internMessage = std::make_shared<AllocateDataMessage>();
179 status = mDeliveryIntern->respond(internMessage);
184 void HyPerDeliveryFacade::deliver() {
185 if (mDeliveryIntern) {
186 mDeliveryIntern->deliver();
190 void HyPerDeliveryFacade::deliverUnitInput(
float *recvBuffer) {
191 if (mDeliveryIntern) {
192 mDeliveryIntern->deliverUnitInput(recvBuffer);
197 return getChannelCode() == CHANNEL_NOUPDATE ?
true : mDeliveryIntern->
isAllInputReady();
virtual bool isAllInputReady() override
virtual void ioParam_updateGSynFromPostPerspective(enum ParamsIOFlag ioFlag)
updateGSynFromPostPerspective: Specifies if the connection should push from pre or pull from post...
virtual void ioParam_accumulateType(enum ParamsIOFlag ioFlag)
pvpatchAccumulateType: Specifies the method to accumulate synaptic input
static bool completed(Status &a)
virtual bool isAllInputReady() override
void ioParams(enum ParamsIOFlag ioFlag, bool printHeader, bool printFooter)
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override