PetaVision  Alpha
WeightsFileIO.hpp
1 #ifndef WEIGHTSFILEIO_HPP_
2 #define WEIGHTSFILEIO_HPP_
3 
4 #include "components/Weights.hpp"
5 #include "io/FileStream.hpp"
6 #include "structures/MPIBlock.hpp"
7 #include "utils/BufferUtilsPvp.hpp"
8 #include <vector>
9 
10 namespace PV {
11 
18  public:
19  WeightsFileIO(FileStream *fileStream, MPIBlock const *mpiBlock, Weights *weights);
20 
21  ~WeightsFileIO() {}
22 
23  double readWeights(int frameNumber);
24 
25  void writeWeights(double timestamp, bool compress);
26 
32  static void
33  moveToFrame(BufferUtils::WeightHeader &header, FileStream &fileStream, int frameNumber);
34 
35  private:
36  BufferUtils::WeightHeader readHeader(int frameNumber);
37 
38  void checkHeader(BufferUtils::WeightHeader const &header);
39 
40  bool isCompressedHeader(BufferUtils::WeightHeader const &header);
41 
42  double readSharedWeights(int frameNumber, BufferUtils::WeightHeader const &header);
43 
44  double readNonsharedWeights(int frameNumber, BufferUtils::WeightHeader const &header);
45 
46  void writeSharedWeights(double timestamp, bool compress);
47 
48  void writeNonsharedWeights(double timestamp, bool compress);
49 
65  long calcArborSizeFile(bool compressed);
66 
73  long calcArborSizeLocal(bool compressed);
74 
75  void calcPatchBox(int &startPatchX, int &endPatchX, int &startPatchY, int &endPatchY);
76 
77  void calcPatchRange(
78  int nPre,
79  int nPost,
80  int preStartBorder,
81  int preEndBorder,
82  int patchSize,
83  int &startPatch,
84  int &endPatch);
85 
86  int calcNeededBorder(int nPre, int nPost, int patchSize);
87 
88  void loadWeightsFromBuffer(
89  std::vector<unsigned char> const &dataFromFile,
90  int arbor,
91  float minValue,
92  float maxValue,
93  bool compressed);
94 
95  void decompressPatch(
96  unsigned char const *dataFromFile,
97  float *destWeights,
98  int count,
99  float minValue,
100  float maxValue);
101 
102  void storeSharedPatches(
103  std::vector<unsigned char> &dataFromFile,
104  int arbor,
105  float minValue,
106  float maxValue,
107  bool compressed);
108 
109  void storeNonsharedPatches(
110  std::vector<unsigned char> &dataFromFile,
111  int arbor,
112  float minValue,
113  float maxValue,
114  bool compressed);
115 
116  void compressPatch(
117  unsigned char *dataForFile,
118  float const *sourceWeights,
119  int count,
120  float minValue,
121  float maxValue);
122 
130  void writePatch(unsigned char const *patchBuffer, bool compressed);
131 
132  // Data members
133  private:
134  FileStream *mFileStream = nullptr;
135  MPIBlock const *mMPIBlock = nullptr;
136  Weights *mWeights = nullptr;
137 
138  int const mRootProcess = 0;
139  int const tagbase = 500;
140 }; // class WeightsFileIO
141 
142 } // namespace PV
143 
144 #endif // WEIGHTSFILEIO_HPP_
long calcArborSizeFile(bool compressed)
long calcArborSizeLocal(bool compressed)
void writePatch(unsigned char const *patchBuffer, bool compressed)
static void moveToFrame(BufferUtils::WeightHeader &header, FileStream &fileStream, int frameNumber)