8 #include "KernelProbe.hpp" 12 KernelProbe::KernelProbe() { initialize_base(); }
14 KernelProbe::KernelProbe(
const char *probename, HyPerCol *hc) {
16 int status = initialize(probename, hc);
17 assert(status == PV_SUCCESS);
20 KernelProbe::~KernelProbe() {}
22 int KernelProbe::initialize_base() {
return PV_SUCCESS; }
24 int KernelProbe::initialize(
const char *probename, HyPerCol *hc) {
25 int status = BaseConnectionProbe::initialize(probename, hc);
26 assert(name && parent);
33 ioParam_kernelIndex(ioFlag);
34 ioParam_arborId(ioFlag);
35 ioParam_outputWeights(ioFlag);
36 ioParam_outputPlasticIncr(ioFlag);
37 ioParam_outputPatchIndices(ioFlag);
41 void KernelProbe::ioParam_kernelIndex(
enum ParamsIOFlag ioFlag) {
42 parent->parameters()->ioParamValue(ioFlag, name,
"kernelIndex", &kernelIndex, 0);
45 void KernelProbe::ioParam_arborId(
enum ParamsIOFlag ioFlag) {
46 parent->parameters()->ioParamValue(ioFlag, name,
"arborId", &arborID, 0);
49 void KernelProbe::ioParam_outputWeights(
enum ParamsIOFlag ioFlag) {
50 parent->parameters()->ioParamValue(
51 ioFlag, name,
"outputWeights", &outputWeights,
true );
54 void KernelProbe::ioParam_outputPlasticIncr(
enum ParamsIOFlag ioFlag) {
55 parent->parameters()->ioParamValue(
56 ioFlag, name,
"outputPlasticIncr", &outputPlasticIncr,
false );
59 void KernelProbe::ioParam_outputPatchIndices(
enum ParamsIOFlag ioFlag) {
60 parent->parameters()->ioParamValue(
61 ioFlag, name,
"outputPatchIndices", &outputPatchIndices,
false );
72 auto *targetHyPerConn = getTargetHyPerConn();
73 assert(targetHyPerConn);
74 if (targetHyPerConn->getSharedWeights() ==
false) {
75 if (parent->getCommunicator()->globalCommRank() == 0) {
77 "%s: %s is not using shared weights.\n",
79 targetHyPerConn->getDescription_c());
81 MPI_Barrier(parent->getCommunicator()->communicator());
84 return Response::SUCCESS;
87 Response::Status KernelProbe::allocateDataStructures() {
88 auto status = BaseHyPerConnProbe::allocateDataStructures();
92 auto *targetHyPerConn = getTargetHyPerConn();
93 assert(targetHyPerConn);
94 if (getKernelIndex() < 0 || getKernelIndex() >= targetHyPerConn->getNumDataPatches()) {
96 "KernelProbe \"%s\": kernelIndex %d is out of bounds. " 100 targetHyPerConn->getNumDataPatches() - 1);
102 if (getArbor() < 0 || getArbor() >= getTargetHyPerConn()->getNumAxonalArbors()) {
104 "KernelProbe \"%s\": arborId %d is out of bounds. (min 0, max %d)\n",
107 getTargetHyPerConn()->getNumAxonalArbors() - 1);
110 if (!mOutputStreams.empty()) {
111 output(0) <<
"Probe \"" << name <<
"\", kernel index " << getKernelIndex() <<
", arbor index " 112 << getArbor() <<
".\n";
114 if (getOutputPatchIndices()) {
115 patchIndices(targetHyPerConn);
118 return Response::SUCCESS;
122 if (mOutputStreams.empty()) {
123 return Response::NO_ACTION;
126 const int rank = icComm->commRank();
127 auto *targetHyPerConn = getTargetHyPerConn();
128 assert(targetHyPerConn !=
nullptr);
129 int nxp = targetHyPerConn->getPatchSizeX();
130 int nyp = targetHyPerConn->getPatchSizeY();
131 int nfp = targetHyPerConn->getPatchSizeF();
132 int patchSize = nxp * nyp * nfp;
134 const float *wdata = targetHyPerConn->getWeightsDataStart(arborID) + patchSize * kernelIndex;
135 const float *dwdata =
137 ? targetHyPerConn->getDeltaWeightsDataStart(arborID) + patchSize * kernelIndex
139 output(0) <<
"Time " << timed <<
", Conn \"" << getTargetConn()->getName() <<
", nxp=" << nxp
140 <<
", nyp=" << nyp <<
", nfp=" << nfp <<
"\n";
141 for (
int f = 0; f < nfp; f++) {
142 for (
int y = 0; y < nyp; y++) {
143 for (
int x = 0; x < nxp; x++) {
144 int k = kIndex(x, y, f, nxp, nyp, nfp);
145 output(0) <<
" x=" << x <<
", y=" << y <<
", f=" << f <<
" (index " << k <<
"):";
146 if (getOutputWeights()) {
147 output(0) <<
" weight=" << wdata[k];
149 if (getOutputPlasticIncr()) {
150 output(0) <<
" dw=" << dwdata[k];
157 return Response::SUCCESS;
160 int KernelProbe::patchIndices(
HyPerConn *conn) {
161 pvAssert(!mOutputStreams.empty());
162 int nxp = conn->getPatchSizeX();
163 int nyp = conn->getPatchSizeY();
164 int nfp = conn->getPatchSizeF();
165 int nPreExt = conn->getNumGeometryPatches();
166 assert(nPreExt == conn->getPre()->getNumExtended());
167 const PVLayerLoc *loc = conn->getPre()->getLayerLoc();
168 const PVHalo *halo = &loc->halo;
172 int nxPreExt = nxPre + loc->halo.lt + loc->halo.rt;
173 int nyPreExt = nyPre + loc->halo.dn + loc->halo.up;
174 for (
int kPre = 0; kPre < nPreExt; kPre++) {
175 Patch const *patch = conn->getPatch(kPre);
176 int xOffset = kxPos(patch->offset, nxp, nyp, nfp);
177 int yOffset = kyPos(patch->offset, nxp, nyp, nfp);
178 int kxPre = kxPos(kPre, nxPreExt, nyPreExt, nfPre) - loc->halo.lt;
179 int kyPre = kyPos(kPre, nxPreExt, nyPreExt, nfPre) - loc->halo.up;
180 int kfPre = featureIndex(kPre, nxPreExt, nyPreExt, nfPre);
181 output(0) <<
" presynaptic neuron " << kPre;
182 output(0) <<
" (x=" << kxPre <<
", y=" << kyPre <<
", f=" << kfPre;
183 output(0) <<
") uses kernel index " << conn->calcDataIndexFromPatchIndex(kPre);
184 output(0) <<
", starting at x=" << xOffset <<
", y=" << yOffset <<
"\n";
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
PrintStream & output(int b)
static bool completed(Status &a)
virtual Response::Status outputState(double timef) override
virtual void initNumValues() override
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override