8 #include "BackgroundLayer.hpp" 11 #include "../include/default_params.h" 14 BackgroundLayer::BackgroundLayer() { initialize_base(); }
16 BackgroundLayer::BackgroundLayer(
const char *name, HyPerCol *hc) {
21 BackgroundLayer::~BackgroundLayer() {}
23 int BackgroundLayer::initialize_base() {
29 int BackgroundLayer::initialize(
const char *name, HyPerCol *hc) {
30 int status_init = CloneVLayer::initialize(name, hc);
36 BackgroundLayer::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
37 auto status = HyPerLayer::communicateInitInfo(message);
41 originalLayer = message->lookup<HyPerLayer>(std::string(originalLayerName));
42 if (originalLayer == NULL) {
43 if (parent->getCommunicator()->globalCommRank() == 0) {
45 "%s: originalLayerName \"%s\" is not a layer in the HyPerCol.\n",
49 MPI_Barrier(parent->getCommunicator()->globalCommunicator());
52 const PVLayerLoc *srcLoc = originalLayer->getLayerLoc();
54 assert(srcLoc != NULL && loc != NULL);
55 if (srcLoc->nxGlobal != loc->nxGlobal || srcLoc->nyGlobal != loc->nyGlobal) {
56 if (parent->columnId() == 0) {
57 ErrorLog(errorMessage);
59 "%s: originalLayerName \"%s\" does not have the same X/Y dimensions.\n",
63 " original (nx=%d, ny=%d, nf=%d) versus (nx=%d, ny=%d, nf=%d)\n",
71 MPI_Barrier(parent->getCommunicator()->communicator());
74 if ((srcLoc->nf + 1) * repFeatureNum != loc->nf) {
75 if (parent->columnId() == 0) {
76 ErrorLog(errorMessage);
78 "%s: nf must have (n+1)*repFeatureNum (%d) features in BackgroundLayer \"%s\", " 79 "where n is the orig layer number of features.\n",
81 (srcLoc->nf + 1) * repFeatureNum,
84 " original (nx=%d, ny=%d, nf=%d) versus (nx=%d, ny=%d, nf=%d)\n",
92 MPI_Barrier(parent->getCommunicator()->communicator());
95 assert(srcLoc->nx == loc->nx && srcLoc->ny == loc->ny);
96 return Response::SUCCESS;
100 void BackgroundLayer::allocateV() {
104 void BackgroundLayer::ioParam_repFeatureNum(
enum ParamsIOFlag ioFlag) {
105 parent->parameters()->ioParamValue(ioFlag, name,
"repFeatureNum", &repFeatureNum, repFeatureNum);
106 if (repFeatureNum <= 0) {
107 Fatal() <<
"BackgroundLayer " << name <<
": repFeatureNum must an integer greater or equal " 108 "to 1 (1 feature means no replication)\n";
114 ioParam_repFeatureNum(ioFlag);
118 int BackgroundLayer::setActivity() {
119 float *activity = clayer->activity->data;
120 memset(activity, 0,
sizeof(
float) * clayer->numExtendedAllBatches);
124 Response::Status BackgroundLayer::updateState(
double timef,
double dt) {
125 float *A = clayer->activity->data;
126 const float *originalA = originalLayer->getCLayer()->activity->data;
128 const PVLayerLoc *locOriginal = originalLayer->getLayerLoc();
131 assert(locOriginal->nx == loc->nx);
132 assert(locOriginal->ny == loc->ny);
133 assert((locOriginal->nf + 1) * repFeatureNum == loc->nf);
137 int origNf = locOriginal->nf;
138 int thisNf = loc->nf;
139 int nbatch = loc->nbatch;
141 PVHalo const *halo = &loc->halo;
142 PVHalo const *haloOrig = &locOriginal->halo;
144 for (
int b = 0; b < nbatch; b++) {
145 float *ABatch = A + b * getNumExtended();
146 const float *originalABatch = originalA + b * originalLayer->getNumExtended();
151 #ifdef PV_USE_OPENMP_THREADS 152 #pragma omp parallel for 154 for (
int iY = 0; iY < ny; iY++) {
155 for (
int iX = 0; iX < nx; iX++) {
159 for (
int iF = 0; iF < origNf; iF++) {
160 int kextOrig = kIndex(
164 nx + haloOrig->lt + haloOrig->rt,
165 ny + haloOrig->dn + haloOrig->up,
167 float origActivity = originalABatch[kextOrig];
169 if (origActivity != 0) {
173 for (
int repIdx = 0; repIdx < repFeatureNum; repIdx++) {
175 int newFeatureIdx = ((iF + 1) * repFeatureNum) + repIdx;
176 assert(newFeatureIdx < thisNf);
181 nx + halo->lt + halo->rt,
182 ny + halo->dn + halo->up,
184 ABatch[kext] = origActivity;
188 for (
int repIdx = 0; repIdx < repFeatureNum; repIdx++) {
189 int kextBackground = kIndex(
190 iX, iY, repIdx, nx + halo->lt + halo->rt, ny + halo->dn + halo->up, thisNf);
191 ABatch[kextBackground] = outVal;
196 return Response::SUCCESS;
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
static bool completed(Status &a)