8 #include "InitVFromFile.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "utils/BufferUtilsMPI.hpp" 13 InitVFromFile::InitVFromFile() { initialize_base(); }
15 InitVFromFile::InitVFromFile(
char const *name, HyPerCol *hc) {
20 InitVFromFile::~InitVFromFile() { free(mVfilename); }
22 int InitVFromFile::initialize_base() {
return PV_SUCCESS; }
24 int InitVFromFile::initialize(
char const *name, HyPerCol *hc) {
25 int status = BaseInitV::initialize(name, hc);
37 parent->parameters()->ioParamString(
38 ioFlag, name,
"Vfilename", &mVfilename,
nullptr,
true );
39 if (mVfilename ==
nullptr) {
41 "InitVFromFile::initialize, group \"%s\": for InitVFromFile, string parameter " 43 "must be defined. Exiting\n",
49 parent->parameters()->ioParamValue(
50 ioFlag, name,
"frameNumber", &mFrameNumber, mFrameNumber,
true );
53 void InitVFromFile::calcV(
float *V,
const PVLayerLoc *loc) {
54 char const *ext = strrchr(mVfilename,
'.');
55 bool isPvpFile = (ext && strcmp(ext,
".pvp") == 0);
57 FileStream fileStream(mVfilename, std::ios_base::in | std::ios_base::binary,
false);
59 int fileType = header.fileType;
60 if (header.fileType == PVP_NONSPIKING_ACT_FILE_TYPE) {
61 readDenseActivityPvp(V, loc, fileStream, header);
64 if (getMPIBlock()->getRank() == 0) {
65 ErrorLog() <<
"InitVFromFile: filename \"" << mVfilename <<
"\" has fileType " 66 << header.fileType <<
", which is not supported for InitVFromFile.\n";
68 MPI_Barrier(getMPIBlock()->getComm());
74 if (getMPIBlock()->getRank() == 0) {
75 ErrorLog().printf(
"InitVFromFile: file \"%s\" is not a pvp file.\n", this->mVfilename);
77 MPI_Barrier(getMPIBlock()->getComm());
82 void InitVFromFile::readDenseActivityPvp(
87 auto mpiBlock = getMPIBlock();
88 bool isRootProc = mpiBlock->getRank() == 0;
89 std::size_t frameSize = (std::size_t)header.recordSize *
sizeof(
float) +
sizeof(double);
90 int numFrames = header.nBands;
91 int blockBatchDimension = mpiBlock->getBatchDimension();
92 for (
int m = 0; m < blockBatchDimension; m++) {
93 for (
int b = 0; b < loc->nbatch; b++) {
94 int globalBatchIndex = (mpiBlock->getStartBatch() + m) * loc->nbatch + b;
95 float *Vbatch = V + b * (loc->nx * loc->ny * loc->nf);
98 int frameIndex = (mFrameNumber + globalBatchIndex) % numFrames;
99 fileStream.setOutPos(
sizeof(header) + frameIndex *
sizeof(
float) * frameSize,
true);
100 int xStart = header.nx * mpiBlock->getStartColumn() / mpiBlock->getNumColumns();
101 int yStart = header.ny * mpiBlock->getStartRow() / mpiBlock->getNumRows();
102 pvpBuffer.resize(header.nx, header.ny, header.nf);
103 BufferUtils::readFrameWindow(fileStream, &pvpBuffer, header, xStart, yStart, 0);
106 pvpBuffer.resize(loc->nx, loc->ny, loc->nf);
108 BufferUtils::scatter(mpiBlock, pvpBuffer, loc->nx, loc->ny, m, 0);
109 std::vector<float> bufferData = pvpBuffer.asVector();
110 std::memcpy(Vbatch, bufferData.data(),
sizeof(float) * pvpBuffer.getTotalElements());
virtual void ioParam_frameNumber(enum ParamsIOFlag ioFlag)
frameNumber: selects which frame of the pvp file to use. The default value is zero. Note that this parameter is zero-indexed: for example, if a pvp file has five frames, the allowable values of this parameter are 0 through 4, inclusive. When batching, the batch element 0 loads the indicated frame, batch element 1 loads frameNumber + 1, etc. If the number of frames in the file is exhausted, the file wraps around to the beginning.
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_Vfilename(enum ParamsIOFlag ioFlag)
VFilename: The path to the file with the initial values. Relative paths are relative to the working d...
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override