PetaVision  Alpha
PV::BaseConnection Class Referenceabstract
Inheritance diagram for PV::BaseConnection:
PV::BaseObject PV::CheckpointerDataInterface PV::Observer PV::HyPerConn PV::CloneConn PV::CopyConn PV::GapConn PV::IdentConn PV::ImprintConn PV::KernelConn PV::MomentumConn PV::PoolingConn PV::privateTransposeConn PV::TransposeConn PV::TransposePoolingConn

BaseConnection Parameters

List of parameters needed from the BaseConnection class

char * preLayerName
 
char * postLayerName
 
HyPerLayerpre
 
HyPerLayerpost
 
ChannelType channel
 
int numAxonalArborLists
 
bool plasticityFlag
 
bool convertRateToSpikeCount
 
bool receiveGpu
 
bool initializeFromCheckpointFlag = true
 
BaseConnectionProbe ** probes
 
int numProbes
 
bool initInfoCommunicatedFlag
 
bool dataStructuresAllocatedFlag
 
bool initialValuesSetFlag
 
int delayArraySize
 
int * delays
 
float * fDelayArray
 
int getDelayArraySize ()
 
virtual void ioParam_preLayerName (enum ParamsIOFlag ioFlag)
 preLayerName: Specifies the connection's pre layer More...
 
virtual void ioParam_postLayerName (enum ParamsIOFlag ioFlag)
 postLayerName: Specifies the connection's post layer More...
 
virtual void ioParam_channelCode (enum ParamsIOFlag ioFlag)
 channelCode: Specifies which channel in the post layer this connection is attached to More...
 
virtual void ioParam_delay (enum ParamsIOFlag ioFlag)
 delay: Specifies delay(s) which the post layer will receive data More...
 
virtual void ioParam_numAxonalArbors (enum ParamsIOFlag ioFlag)
 numAxonalArbors: Specifies the number of arbors to use in this connection
 
virtual void ioParam_plasticityFlag (enum ParamsIOFlag ioFlag)
 plasticityFlag: Specifies if the weights will update
 
virtual void ioParam_convertRateToSpikeCount (enum ParamsIOFlag ioFlag)
 convertRateToSpikeCount: If true, presynaptic activity should be converted from a rate to a count. More...
 
virtual void ioParam_receiveGpu (enum ParamsIOFlag ioFlag)
 receiveGpu: If PetaVision was compiled with GPU acceleration and this flag is set to true, the connection uses the GPU to update the postsynaptic layer's GSyn. If compiled without GPU acceleration, it is an error to set this flag to true.
 
virtual void ioParam_initializeFromCheckpointFlag (enum ParamsIOFlag ioFlag)
 initializeFromCheckpointFlag: If set to true, initialize using checkpoint direcgtory set in HyPerCol. More...
 
virtual int setInitialValues ()=0
 
virtual int respondConnectionUpdate (ConnectionUpdateMessage const *message)
 
virtual int respondConnectionFinalizeUpdate (ConnectionFinalizeUpdateMessage const *message)
 
virtual int respondConnectionOutput (ConnectionOutputMessage const *message)
 
virtual bool needUpdate (double time, double dt)=0
 
virtual int initializeDelays (const float *fDelayArray, int size)
 
int maxDelaySteps ()
 
int initialize_base ()
 
static int decodeChannel (int channel_code, ChannelType *channel_type)
 

Public Member Functions

virtual ~BaseConnection ()
 
virtual int communicateInitInfo (CommunicateInitInfoMessage const *message) override
 
virtual int deliver ()=0
 
virtual int finalizeUpdate (double timed, double dt)
 
ChannelType getChannel ()
 
bool getConvertRateToSpikeCount ()
 
bool getDataStructuresAllocatedFlag ()
 
int getDelay (int arbor)
 
std::string const & getDescription () const
 
char const * getDescription_c () const
 
bool getInitialValuesSetFlag ()
 
bool getInitInfoCommunicatedFlag ()
 
char const * getKeyword () const
 
MPIBlock const * getMPIBlock ()
 
char const * getName () const
 
int getNumProbes ()
 
bool getPlasticityFlag ()
 
HyPerLayergetPost ()
 
const char * getPostLayerName ()
 
HyPerLayergetPre ()
 
const char * getPreLayerName ()
 
BaseConnectionProbegetProbe (int i)
 
bool getReceiveGpu ()
 
virtual int initializeState () overridefinal
 
virtual int insertProbe (BaseConnectionProbe *p)
 
int ioParams (enum ParamsIOFlag ioFlag)
 
bool isUsingGPU () const
 
int numberOfAxonalArborLists ()
 
virtual int outputProbeParams ()
 
virtual int outputState (double timed)=0
 
HyPerLayerpostSynapticLayer ()
 
HyPerLayerpreSynapticLayer ()
 
virtual int registerData (Checkpointer *checkpointer)
 
virtual int respond (std::shared_ptr< BaseMessage const > message) override
 
virtual int updateState (double timed, double dt)=0
 

Protected Member Functions

 BaseConnection ()
 
virtual int allocateDataStructures ()
 
virtual int cleanup ()
 
virtual int copyInitialStateToGPU ()
 
int getPreAndPostLayerNames (const char *name, char **preLayerNamePtr, char **postLayerNamePtr)
 
virtual int handleMissingPreAndPostLayerNames ()
 
int initialize (const char *name, HyPerCol *hc)
 
virtual int ioParamsFillGroup (enum ParamsIOFlag ioFlag)
 
virtual int prepareCheckpointWrite ()
 
virtual int processCheckpointRead ()
 
virtual int readStateFromCheckpoint (Checkpointer *checkpointer) override
 
int respondAllocateData (AllocateDataMessage const *message)
 
int respondCleanup (CleanupMessage const *message)
 
int respondCommunicateInitInfo (CommunicateInitInfoMessage const *message)
 
int respondCopyInitialStateToGPUMessage (CopyInitialStateToGPUMessage const *message)
 
int respondInitializeState (InitializeStateMessage const *message)
 
int respondPrepareCheckpointWrite (PrepareCheckpointWriteMessage const *message)
 
int respondProcessCheckpointRead (ProcessCheckpointReadMessage const *message)
 
int respondReadStateFromCheckpoint (ReadStateFromCheckpointMessage< Checkpointer > const *message)
 
int respondRegisterData (RegisterDataMessage< Checkpointer > const *message)
 
void setChannelType (ChannelType ch)
 
void setConvertRateToSpikeCount (bool convertRateToSpikeCountFlag)
 
void setDataStructuresAllocatedFlag ()
 
void setDelay (int arborId, double delay)
 
virtual int setDescription ()
 
void setInitialValuesSetFlag ()
 
void setInitInfoCommunicatedFlag ()
 
int setName (char const *name)
 
void setNumberOfAxonalArborLists (int numArbors)
 
int setParent (HyPerCol *hc)
 
void setPostLayerName (const char *postName)
 
virtual int setPreAndPostLayerNames ()
 
void setPreLayerName (const char *preName)
 
void setReceiveGpu ()
 

Static Protected Member Functions

static int inferPreAndPostFromConnName (const char *name, int rank, char **preLayerNamePtr, char **postLayerNamePtr)
 

Protected Attributes

std::string description
 
bool mDataStructuresAllocatedFlag = false
 
bool mInitialValuesSetFlag = false
 
bool mInitInfoCommunicatedFlag = false
 
bool mUsingGPUFlag = false
 
char * name = nullptr
 
HyPerColparent = nullptr
 

Detailed Description

Definition at line 27 of file BaseConnection.hpp.

Constructor & Destructor Documentation

PV::BaseConnection::~BaseConnection ( )
virtual

Destructor for BaseConnection

Definition at line 601 of file BaseConnection.cpp.

PV::BaseConnection::BaseConnection ( )
protected

The constructor implicitly called by derived classes' constructors. It calls initialize_base(), but not initialize().

Note that BaseConnection has no public constructors; only derived classes can be constructed directly.

Definition at line 20 of file BaseConnection.cpp.

Member Function Documentation

int PV::BaseConnection::communicateInitInfo ( CommunicateInitInfoMessage const *  message)
overridevirtual

communicateInitInfo is used to allow connections and layers to set params and related member variables based on what other layers or connections are doing. (For example, CloneConn sets many parameters the same as its originalConn.) After a connection is constructed, it is not properly initialized until communicateInitInfo(), allocateDataStructures(), and initializeState() have been called.

Return values: PV_POSTPONE means that communicateInitInfo() cannot be run until other layers'/connections' own communicateInitInfo() have been run successfully.

PV_SUCCESS and PV_FAILURE have their usual meanings.

communicateInitInfo() is called by passing a CommunicateInitInfoMessage to respond(), which is usually done in HyPerCol::run.

Reimplemented from PV::BaseObject.

Reimplemented in PV::PlasticCloneConn, PV::HyPerConn, PV::TransposePoolingConn, PV::PoolingConn, PV::IdentConn, PV::privateTransposeConn, PV::CloneConn, PV::TransposeConn, and PV::CopyConn.

Definition at line 460 of file BaseConnection.cpp.

static int PV::BaseConnection::decodeChannel ( int  channel_code,
ChannelType *  channel_type 
)
inlinestatic

Type-safe method of translating an integer channel_code into an allowed channel type. If channel_code corresponds to a recognized channel type, *channel_type is set accordingly and the function returns successfully. Otherwise, *channel_type is undefined and the function returns PV_FAILURE.

Definition at line 421 of file BaseConnection.hpp.

virtual int PV::BaseConnection::deliver ( )
pure virtual

A pure virtual function for modifying the post-synaptic layer's GSyn buffer based on the connection and the presynaptic activity

Implemented in PV::HyPerConn, and PV::privateTransposeConn.

virtual int PV::BaseConnection::finalizeUpdate ( double  timed,
double  dt 
)
inlinevirtual

A virtual function for performing any necessary updates after the normalizers are called.

Reimplemented in PV::HyPerConn, PV::CloneConn, PV::PoolingConn, PV::privateTransposeConn, and PV::TransposeConn.

Definition at line 94 of file BaseConnection.hpp.

bool PV::BaseObject::getDataStructuresAllocatedFlag ( )
inlineinherited

Get-method for mDataStructuresAllocatedFlag, which is false on initialization and then becomes true once setDataStructuresAllocatedFlag() is called.

Definition at line 65 of file BaseObject.hpp.

int PV::BaseConnection::getDelay ( int  arbor)
inline

Returns the delay (in timesteps) belonging the given arbor.

Definition at line 156 of file BaseConnection.hpp.

bool PV::BaseObject::getInitialValuesSetFlag ( )
inlineinherited

Get-method for mInitialValuesSetFlag, which is false on initialization and then becomes true once setInitialValuesSetFlag() is called.

Definition at line 71 of file BaseObject.hpp.

bool PV::BaseObject::getInitInfoCommunicatedFlag ( )
inlineinherited

Get-method for mInitInfoCommunicatedFlag, which is false on initialization and then becomes true once setInitInfoCommunicatedFlag() is called.

Definition at line 58 of file BaseObject.hpp.

int PV::BaseConnection::getNumProbes ( )
inline

Returns the number of probes that have been attached to this connection

Definition at line 166 of file BaseConnection.hpp.

int PV::BaseConnection::getPreAndPostLayerNames ( const char *  name,
char **  preLayerNamePtr,
char **  postLayerNamePtr 
)
protected

Sets *preLayerNamePtr and *postLayerNamePtr according to the preLayerName and postLayerName parameters in the parameter group specified by the name and params arguments.

Definition at line 190 of file BaseConnection.cpp.

BaseConnectionProbe* PV::BaseConnection::getProbe ( int  i)
inline

Returns the probe with the indicated position in the list of probes. It does not do sanity checking on the value of i.

Definition at line 172 of file BaseConnection.hpp.

int PV::BaseConnection::handleMissingPreAndPostLayerNames ( )
protectedvirtual

Called by BaseConnection::communicateInitInfo of the params did not set pre- and post- layers.

Reimplemented in PV::FeedbackConn.

Definition at line 106 of file BaseConnection.cpp.

int PV::BaseConnection::inferPreAndPostFromConnName ( const char *  name,
int  rank,
char **  preLayerNamePtr,
char **  postLayerNamePtr 
)
staticprotected

The default behavior of BaseConnection::handleMissingPreAndPostLayerNames. It tries to parse the name argument of the connection in the form "PreLayerToPostLayer". Then "PreLayer" put into *preLayerNamePtr and "PostLayer" is put into *postLayerNamePtr, and PV_SUCCESS is returned. If name does not contain the string "To", or if it contains it in more than one place, then PV_FAILURE is returned and *preLayerNamePtr and *postLayerNamePtr are not changed. rank is the rank of the process under MPI; the root process will print a message to the error stream if the routine fails; non-root process will not. This routine uses malloc to fill *{pre,post}LayerNamePtr, so the routine calling this one is responsible for freeing them.

Definition at line 111 of file BaseConnection.cpp.

int PV::BaseConnection::initialize ( const char *  name,
HyPerCol hc 
)
protected

The initialization routine. It should be called during the initialization routine of any derived class.

It sets the name and parent HyPerCol to the indicated arguments, and calls (via ioParams) the virtual ioParamsFillGroup method, which reads params from the parent HyPerCol's params.

Definition at line 43 of file BaseConnection.cpp.

int PV::BaseConnection::initialize_base ( )
private

Called by the constructor, initialize_base() sets member variables to safe values (e.g. pointers to NULL) and parameters to default values.

Definition at line 22 of file BaseConnection.cpp.

int PV::BaseConnection::initializeDelays ( const float *  fDelayArray,
int  size 
)
protectedvirtual

Allocates the delays array and calls setDelay() for each arbor. fDelayArray is an array of length size, of delays, measured in the same units as the parent HyPerCol's dt.

If size=0, all delays are set to zero. If size=1, all delays are set to fDelayArray[0] If size=numArbors, delays[k] is calculated from fDelayArray[k]. If size is any other value, it is an error.

Reimplemented in PV::privateTransposeConn.

Definition at line 542 of file BaseConnection.cpp.

int PV::BaseConnection::initializeState ( )
finaloverridevirtual

initializeState is used to set the initial values of the connection.

initializeState() is typically called by passing an InitializeStateMessage to respond(), which is usually done in HyPerCol::run.

Reimplemented from PV::BaseObject.

Definition at line 599 of file BaseConnection.cpp.

int PV::BaseConnection::insertProbe ( BaseConnectionProbe p)
virtual

Adds the given probe to the list of probes.

Reimplemented in PV::HyPerConn.

Definition at line 387 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_channelCode ( enum ParamsIOFlag  ioFlag)
protectedvirtual

channelCode: Specifies which channel in the post layer this connection is attached to

Channels can be -1 for no update, or >= 0 for channel number.
0 is excitatory, 1 is inhibitory

Reimplemented in PV::HyPerConn, and PV::GapConn.

Definition at line 279 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_convertRateToSpikeCount ( enum ParamsIOFlag  ioFlag)
protectedvirtual

convertRateToSpikeCount: If true, presynaptic activity should be converted from a rate to a count.

If this flag is true and the presynaptic layer is not spiking, the activity will be interpreted as a spike rate, and will be converted to a spike count when delivering activity to the postsynaptic GSyn buffer. If this flag is false, activity will not be converted.

Reimplemented in PV::IdentConn.

Definition at line 349 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_delay ( enum ParamsIOFlag  ioFlag)
protectedvirtual

delay: Specifies delay(s) which the post layer will receive data

: Delays are specified in units of dt, but are rounded to be integer multiples of dt. If delay is a scalar, all arbors of the connection have that value of delay. If delay is an array, the length must match the number of arbors and the arbors are assigned the delays sequentially.

Definition at line 302 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_initializeFromCheckpointFlag ( enum ParamsIOFlag  ioFlag)
protectedvirtual

initializeFromCheckpointFlag: If set to true, initialize using checkpoint direcgtory set in HyPerCol.

Checkpoint read directory must be set in HyPerCol to initialize from checkpoint.

Reimplemented in PV::CloneConn, PV::CopyConn, PV::TransposeConn, PV::PoolingConn, PV::IdentConn, and PV::TransposePoolingConn.

Definition at line 377 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_postLayerName ( enum ParamsIOFlag  ioFlag)
protectedvirtual

postLayerName: Specifies the connection's post layer

Required parameter

Reimplemented in PV::FeedbackConn.

Definition at line 274 of file BaseConnection.cpp.

void PV::BaseConnection::ioParam_preLayerName ( enum ParamsIOFlag  ioFlag)
protectedvirtual

preLayerName: Specifies the connection's pre layer

Required parameter

Reimplemented in PV::FeedbackConn.

Definition at line 269 of file BaseConnection.cpp.

int PV::BaseConnection::ioParams ( enum ParamsIOFlag  ioFlag)

Method for reading or writing the params from group in the parent HyPerCol's parameters. The group from params is selected using the name of the connection.

Note that ioParams is not virtual. To add parameters in a derived class, override ioParamFillGroup.

Definition at line 240 of file BaseConnection.cpp.

int PV::BaseConnection::ioParamsFillGroup ( enum ParamsIOFlag  ioFlag)
protectedvirtual

The virtual method for reading parameters from the parent HyPerCol's parameters, and writing to the output params file.

BaseConnection::ioParamsFillGroup reads/writes the paremeters preLayerName, postLayerName, channelCode, delay, numAxonalArbors, and convertRateToSpikeCount.

Derived classes with additional parameters typically override ioParamsFillGroup to call the base class's ioParamsFillGroup method and then call ioParam_[parametername] for each of their parameters. The ioParam_[parametername] methods should call the parent HyPerCol's ioParamValue() and related methods, to ensure that all parameters that get read also get written to the outputParams-generated file.

Reimplemented in PV::HyPerConn, PV::PlasticCloneConn, PV::CloneConn, PV::TransposeConn, PV::TransposePoolingConn, PV::MomentumConn, PV::PoolingConn, PV::privateTransposeConn, PV::IdentConn, PV::ImprintConn, PV::CopyConn, and PV::RescaleConn.

Definition at line 248 of file BaseConnection.cpp.

bool PV::BaseObject::isUsingGPU ( ) const
inlineinherited

Returns true if the object requires the GPU; false otherwise. HyPerCol will not initialize the GPU unless one of the objects in its hierarchy returns true

Definition at line 79 of file BaseObject.hpp.

int PV::BaseConnection::maxDelaySteps ( )
protected

Returns the maximum value of the delay array, as a number of timesteps

Definition at line 577 of file BaseConnection.cpp.

virtual bool PV::BaseConnection::needUpdate ( double  time,
double  dt 
)
protectedpure virtual

A pure virtual method whose implementation returns true if an the weights should update on the given timestep and false if not.

Implemented in PV::HyPerConn, PV::TransposePoolingConn, PV::privateTransposeConn, PV::TransposeConn, and PV::CopyConn.

int PV::BaseConnection::outputProbeParams ( )
virtual

Called by HyPerCol::outputParams to output the params groups for probes whose ownership has been transferred to this connection. (Does this need to be virtual?)

Reimplemented in PV::HyPerConn.

Definition at line 449 of file BaseConnection.cpp.

virtual int PV::BaseConnection::outputState ( double  timed)
pure virtual

A pure virtual function for writing the state of the connection to file(s) in the output directory. For example, HyPerConn writes the weights to a .pvp file with a schedule defined by writeStep and initialWriteTime.

Implemented in PV::HyPerConn, and PV::CloneConn.

void PV::BaseConnection::setChannelType ( ChannelType  ch)
protected

Sets the channel to the indicated argument. It is an error to try to change channels after communicateInitInfo() has completed successfully.

Definition at line 91 of file BaseConnection.cpp.

void PV::BaseObject::setDataStructuresAllocatedFlag ( )
inlineprotectedinherited

This method sets mDataStructuresAllocatedFlag to true.

Definition at line 111 of file BaseObject.hpp.

void PV::BaseConnection::setDelay ( int  arborId,
double  delay 
)
protected

Sets the delay of the given arbor to the given amount. delay is specified in the same units that the parent HyPerCol's dt parameter is specified in. Internally, the delay is set as an integral number of timesteps, specifically round(delay/dt).

Definition at line 588 of file BaseConnection.cpp.

virtual int PV::BaseConnection::setInitialValues ( )
protectedpure virtual

A pure virtual method for initializing the connection if we are neither restarting from a checkpoint or initializing the connection from a checkpoint. It should return PV_SUCCESS if successful, or PV_POSTPONE if it needs to wait for other objects to set their initial values before it can set its own initial values. (e.g. TransposeConn has to wait for original conn)

Implemented in PV::HyPerConn, PV::CopyConn, PV::PoolingConn, PV::TransposeConn, PV::TransposePoolingConn, and PV::privateTransposeConn.

void PV::BaseObject::setInitialValuesSetFlag ( )
inlineprotectedinherited

This method sets the flag returned by getInitialValuesSetFlag to true.

Definition at line 116 of file BaseObject.hpp.

void PV::BaseObject::setInitInfoCommunicatedFlag ( )
inlineprotectedinherited

This method sets mInitInfoCommunicatedFlag to true.

Definition at line 106 of file BaseObject.hpp.

void PV::BaseConnection::setNumberOfAxonalArborLists ( int  numArbors)
protected

Sets the number of arbors to the indicated argument. It is an error to try to change numArbors after communicateInitInfo() has completed successfully.

Definition at line 96 of file BaseConnection.cpp.

void PV::BaseConnection::setPostLayerName ( const char *  postName)
protected

Sets the postsynaptic layer name to the given string. It is an error to try to set postLayerName after it has already been set, or to call setPostLayerName() with a NULL argument.

Definition at line 74 of file BaseConnection.cpp.

int PV::BaseConnection::setPreAndPostLayerNames ( )
protectedvirtual

Sets the pre- and post-synaptic layer names according to the parent HyPerCol's params. Virtual to allow subclasses to infer layer names in other ways (for example, FeedbackConn flips pre- and post- layers from originalConn).

Reimplemented in PV::FeedbackConn.

Definition at line 52 of file BaseConnection.cpp.

void PV::BaseConnection::setPreLayerName ( const char *  preName)
protected

Sets the presynaptic layer name to the given string. It is an error to try to set preLayerName after it has already been set, or to call setPreLayerName() with a NULL argument.

Definition at line 56 of file BaseConnection.cpp.

virtual int PV::BaseConnection::updateState ( double  timed,
double  dt 
)
pure virtual

A pure virtual function for updating the state of the connection. timed is simulation time, and dt is the time increment between steps.

Implemented in PV::HyPerConn, PV::TransposePoolingConn, PV::privateTransposeConn, PV::TransposeConn, PV::CloneConn, and PV::CopyConn.


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