PetaVision  Alpha
PV::Weights Class Reference

#include <Weights.hpp>

Inheritance diagram for PV::Weights:
PV::ImpliedWeights

Public Member Functions

 Weights (std::string const &name)
 
 Weights (std::string const &name, int patchSizeX, int patchSizeY, int patchSizeF, PVLayerLoc const *preLoc, PVLayerLoc const *postLoc, int numArbors, bool sharedWeights, double timestamp)
 
virtual ~Weights ()
 
void allocateDataStructures ()
 
int calcDataIndexFromPatchIndex (int patchIndex) const
 
float calcMaxWeight ()
 
float calcMaxWeight (int arbor)
 
float calcMinWeight ()
 
float calcMinWeight (int arbor)
 
void checkpointWeightPvp (Checkpointer *checkpointer, char const *objectName, char const *bufferName, bool compressFlag)
 
void copyToGPU ()
 
float * getData (int arbor)
 
float * getData (int arbor, double timestamp)
 
float * getDataFromDataIndex (int arbor, int dataIndex)
 
float * getDataFromDataIndex (int arbor, int dataIndex, double timestamp)
 
float * getDataFromPatchIndex (int arbor, int patchIndex)
 
float * getDataFromPatchIndex (int arbor, int patchIndex, double timestamp)
 
float const * getDataReadOnly (int arbor) const
 
PVCuda::CudaBuffer * getDeviceData () const
 
PVCuda::CudaBuffer * getDevicePatchToDataLookup () const
 
std::shared_ptr< PatchGeometrygetGeometry () const
 
std::string const & getName () const
 
int getNumArbors () const
 
int getNumDataPatches () const
 
int getNumDataPatchesF () const
 
int getNumDataPatchesX () const
 
int getNumDataPatchesY () const
 
Patch const & getPatch (int patchIndex) const
 
int getPatchSizeF () const
 
int getPatchSizeOverall () const
 
int getPatchSizeX () const
 
int getPatchSizeY () const
 
int getPatchStrideF () const
 
int getPatchStrideX () const
 
int getPatchStrideY () const
 
bool getSharedFlag () const
 
double getTimestamp () const
 
bool getWeightsArePlastic () const
 
void initialize (std::shared_ptr< PatchGeometry > geometry, int numArbors, bool sharedWeights, double timestamp)
 
void initialize (Weights const *baseWeights)
 
void initialize (int patchSizeX, int patchSizeY, int patchSizeF, PVLayerLoc const *preLoc, PVLayerLoc const *postLoc, int numArbors, bool sharedWeights, double timestamp)
 
bool isUsingGPU ()
 
void setCudaDevice (PVCuda::CudaDevice *device)
 
void setMargins (PVHalo const &preHalo, PVHalo const &postHalo)
 
void setTimestamp (double timestamp)
 
void setWeightsArePlastic ()
 
void useGPU ()
 

Protected Member Functions

 Weights ()
 
void allocateCudaBuffers ()
 
void setName (std::string const &name)
 
void setNumDataPatches (int numDataPatchesX, int numDataPatchesY, int numDataPatchesF)
 

Private Member Functions

virtual void initNumDataPatches ()
 

Private Attributes

std::vector< int > dataIndexLookupTable
 
PVCuda::CudaDevice * mCudaDevice = nullptr
 
std::vector< std::vector< float > > mData
 
PVCuda::CudaBuffer * mDeviceData = nullptr
 
PVCuda::CudaBuffer * mDevicePatchToDataLookup = nullptr
 
std::shared_ptr< PatchGeometrymGeometry = nullptr
 
std::string mName
 
int mNumArbors
 
int mNumDataPatchesF
 
int mNumDataPatchesX
 
int mNumDataPatchesY
 
bool mSharedFlag
 
double mTimestamp
 
double mTimestampGPU
 
bool mUsingGPUFlag = false
 
bool mWeightsArePlastic = false
 

Detailed Description

Weights enpapsulates the patch geometry and patch data for a HyPerConn-type connection It makes use of a PatchGeometry object (either creating it itself or using an already existing object). It handles both shared and nonshared versions of the connection data used by HyPerConn, and handles multiple arbors.

If instantiating with the constructor that only takes the name argument, one of the initialize() methods must be called. The initialize() methods differ in how the PatchGeometry object is specified. Afterward, the allocateDataStructures() method must be called before the weights object is ready. If the Weights is constructed with sharedWeights off, NumDataPatchesX and NumDataPatchesY are the same as the PatchGeometry object's numPatchesX and numPatchesY.

If sharedWeights is on, NumDataPatchesX is PreLoc.nx / PostLoc.nx if this quantity is greater than one, and 1 otherwise. Note that the PatchGeometry object requires that the quotient of PreLoc.nx and PostLoc.nx be an integral power of two (1, 2, 4, 8, ...; or 1/2, 1/4, 1/8, ...). NumDataPatchesY is defined similarly in terms of PreLoc.ny / PostLoc.ny.

In both cases, numDataPatchesF is the same as the PatchGeometry object's NumPatchesF.

Definition at line 45 of file Weights.hpp.

Constructor & Destructor Documentation

PV::Weights::Weights ( std::string const &  name)

Instantiates the Weights object and sets the name, but does not set any of the other data members. One of the initialize() methods and then the allocateDataStructures() method has to be called before the Weights object is ready to use.

Definition at line 17 of file Weights.cpp.

PV::Weights::Weights ( std::string const &  name,
int  patchSizeX,
int  patchSizeY,
int  patchSizeF,
PVLayerLoc const *  preLoc,
PVLayerLoc const *  postLoc,
int  numArbors,
bool  sharedWeights,
double  timestamp 
)

Instantiates the Weights object and then calls the initialize() method with the arguments after the name argument.

Definition at line 19 of file Weights.cpp.

virtual PV::Weights::~Weights ( )
inlinevirtual

The destructor for Weights.

Definition at line 71 of file Weights.hpp.

PV::Weights::Weights ( )
inlineprotected

The default constructor, called by derived classes (e.g. PoolingWeights). Derived classes need to call Weights::initialize themselves

Definition at line 280 of file Weights.hpp.

Member Function Documentation

void PV::Weights::allocateDataStructures ( )

Allocates the patch geometry and the the patch data vector. The Weights object is not completely initialized until this method is called. Once allocateDataStructures() is called once, subsequent calls return immediately and have no effect.

Definition at line 83 of file Weights.cpp.

float PV::Weights::calcMaxWeight ( )

Calculates the maximum value of the patch data over all arbors. For nonshared weights, only the active regions of the patches are considered when taking the minimum.

Definition at line 277 of file Weights.cpp.

float PV::Weights::calcMaxWeight ( int  arbor)

Calculates the maximum value of the patch data over the given arbor. For nonshared weights, only the active regions of the patches are considered when taking the minimum.

Definition at line 288 of file Weights.cpp.

float PV::Weights::calcMinWeight ( )

Calculates the minimum value of the patch data over all arbors. For nonshared weights, only the active regions of the patches are considered when taking the minimum.

Definition at line 238 of file Weights.cpp.

float PV::Weights::calcMinWeight ( int  arbor)

Calculates the minimum value of the patch data over the given arbor. For nonshared weights, only the active regions of the patches are considered when taking the minimum.

Definition at line 249 of file Weights.cpp.

void PV::Weights::copyToGPU ( )

If CUDA is being used, copy the weights onto the GPU.

Definition at line 317 of file Weights.cpp.

float * PV::Weights::getData ( int  arbor)

Returns a pointer to the patch data for the given arbor

Definition at line 196 of file Weights.cpp.

float* PV::Weights::getData ( int  arbor,
double  timestamp 
)

Returns a modifiable pointer to the patch data for the given arbor, and sets the timestamp to the given value

float * PV::Weights::getDataFromDataIndex ( int  arbor,
int  dataIndex 
)

Returns a pointer to the patch data for the given data index

Definition at line 200 of file Weights.cpp.

float* PV::Weights::getDataFromDataIndex ( int  arbor,
int  dataIndex,
double  timestamp 
)

Returns a modifiable pointer to the patch data for the given data index, and sets the timestamp to the given value

float * PV::Weights::getDataFromPatchIndex ( int  arbor,
int  patchIndex 
)

Returns a pointer to the patch data for data index corresponding to the given patch index

Definition at line 205 of file Weights.cpp.

float* PV::Weights::getDataFromPatchIndex ( int  arbor,
int  patchIndex,
double  timestamp 
)

Returns a modifiable pointer to the patch data for data index corresponding to the given patch index, and sets the timestamp to the give value

float const * PV::Weights::getDataReadOnly ( int  arbor) const

Returns a read-only pointer to the patch data for the given arbor

Definition at line 198 of file Weights.cpp.

std::shared_ptr<PatchGeometry> PV::Weights::getGeometry ( ) const
inline

The get-method for the PatchGeometry object

Definition at line 148 of file Weights.hpp.

std::string const& PV::Weights::getName ( ) const
inline

The get-method for the name of the object

Definition at line 145 of file Weights.hpp.

int PV::Weights::getNumArbors ( ) const
inline

The get-method for the number of arbors

Definition at line 151 of file Weights.hpp.

int PV::Weights::getNumDataPatches ( ) const
inline

Returns the overall number of data patches

Definition at line 174 of file Weights.hpp.

int PV::Weights::getNumDataPatchesF ( ) const
inline

The get-method for the number of data patches in the feature direction. For both shared and nonshared weights, this is the number of features in the presynaptic layer.

Definition at line 171 of file Weights.hpp.

int PV::Weights::getNumDataPatchesX ( ) const
inline

The get-method for the number of data patches in the x-direction. For shared weights, this is the number of kernels in the x-direction. For nonshared weights, it is the number of neurons in the extended region in the x-direction.

Definition at line 158 of file Weights.hpp.

int PV::Weights::getNumDataPatchesY ( ) const
inline

The get-method for the number of data patches in the y-direction. For shared weights, this is the number of kernels in the y-direction. For nonshared weights, it is the number of neurons in the extended region in the y-direction.

Definition at line 165 of file Weights.hpp.

Patch const & PV::Weights::getPatch ( int  patchIndex) const

Returns a nonmutable reference to the patch info for the given patch index.

Definition at line 194 of file Weights.cpp.

int PV::Weights::getPatchSizeF ( ) const
inline

The get-method for the patch size in the feature dimension

Definition at line 225 of file Weights.hpp.

int PV::Weights::getPatchSizeOverall ( ) const
inline

Returns getPatchSizeX() * getPatchSizeY() * getPatchSizeF(), the overall number of items in a patch.

Definition at line 231 of file Weights.hpp.

int PV::Weights::getPatchSizeX ( ) const
inline

The get-method for the patch size in the x-dimension

Definition at line 219 of file Weights.hpp.

int PV::Weights::getPatchSizeY ( ) const
inline

The get-method for the patch size in the y-dimension

Definition at line 222 of file Weights.hpp.

int PV::Weights::getPatchStrideF ( ) const
inline

Returns the memory stride between adjacent feature indices with the same x- and y- coordinates

Definition at line 236 of file Weights.hpp.

int PV::Weights::getPatchStrideX ( ) const
inline

Returns the memory stride between adjacent x-coordinates with the same y-coordinate and feature index

Definition at line 242 of file Weights.hpp.

int PV::Weights::getPatchStrideY ( ) const
inline

Returns the memory stride between adjacent y-coordinates with the same x-coordinate and feature index

Definition at line 248 of file Weights.hpp.

bool PV::Weights::getSharedFlag ( ) const
inline

The get-method for the sharedWeights flag

Definition at line 142 of file Weights.hpp.

double PV::Weights::getTimestamp ( ) const
inline

Retrieves a previously set timestamp

Definition at line 216 of file Weights.hpp.

void PV::Weights::initialize ( std::shared_ptr< PatchGeometry geometry,
int  numArbors,
bool  sharedWeights,
double  timestamp 
)

An initializer that uses the specified PatchGeometry object as its patch geometry. This method allows two Weights objects to share the same PatchGeometry object.

Definition at line 34 of file Weights.cpp.

void PV::Weights::initialize ( Weights const *  baseWeights)

A constructor that uses the geometry of an existing Weights object. The PatchGeometry object is shared, and the other data members are copied.

Definition at line 55 of file Weights.cpp.

void PV::Weights::initialize ( int  patchSizeX,
int  patchSizeY,
int  patchSizeF,
PVLayerLoc const *  preLoc,
PVLayerLoc const *  postLoc,
int  numArbors,
bool  sharedWeights,
double  timestamp 
)

An initializer that takes the patch size and pre- and post-synaptic PVLayerLoc arguments to define the PatchGeometry object.

Definition at line 64 of file Weights.cpp.

void PV::Weights::setMargins ( PVHalo const &  preHalo,
PVHalo const &  postHalo 
)

Copies the given halos into the halos of the PatchGeometry object. in the PatchIt is an error to call this method after the PatchGeometry object's allocateDataStructures method has been called. (Recall that multiple Weights objects can share a PatchGeometry object).

Definition at line 78 of file Weights.cpp.

void PV::Weights::setTimestamp ( double  timestamp)
inline

Sets the timestamp

Definition at line 213 of file Weights.hpp.


The documentation for this class was generated from the following files: