GEGELATI
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Data::DataHandler Class Referenceabstract

Base class for all sources of data to be accessed by a TPG Instruction executed within a Program. More...

#include <dataHandler.h>

Inheritance diagram for Data::DataHandler:
Data::ArrayWrapper< Constant > Data::ArrayWrapper< double > Data::ArrayWrapper< T > Data::PrimitiveTypeArray< Constant > Data::PrimitiveTypeArray< double > Data::Array2DWrapper< T > Data::PrimitiveTypeArray< T > Data::ConstantHandler Data::PrimitiveTypeArray2D< T >

Public Member Functions

 DataHandler ()
 Default constructor of the DataHandler class.
 
virtual ~DataHandler ()=default
 Default destructor.
 
 DataHandler (const DataHandler &other)=default
 Default copy constructor.
 
virtual DataHandlerclone () const =0
 Return a copy of the DataHandler (with all its content). More...
 
size_t getId () const
 Get the ID of the DataHandler. More...
 
size_t getHash () const
 Get the current value of the hash for this DataHandler. More...
 
virtual bool canHandle (const std::type_info &type) const =0
 Check a given DataHandler can handle data for the given data type. More...
 
virtual size_t getAddressSpace (const std::type_info &type) const =0
 Get the getAddressSpace size for the given data type. More...
 
virtual size_t getLargestAddressSpace () const =0
 Get the largest AddressSpace for all data types handled by the DataHandler. More...
 
virtual void resetData ()=0
 Generic method for DataHandler to reset their data. More...
 
virtual UntypedSharedPtr getDataAt (const std::type_info &type, const size_t address) const =0
 Get data of the given type, from the given address. More...
 
virtual std::vector< size_t > getAddressesAccessed (const std::type_info &type, const size_t address) const =0
 Get the set of addresses actually used when getting the given type of data, at the given address. More...
 
uint64_t scaleLocation (const uint64_t rawLocation, const std::type_info &type) const
 Scale a location from the Environment largestAddressSpace to the largestAddressSpace of the dataHandler, for the given data type. More...
 
virtual const std::type_info & getNativeType () const =0
 Function returning the native type of the DataHandler. More...
 
virtual std::vector< size_t > getDimensionsSize () const =0
 Give the size of each dimension (if any) of the DataHandler. More...
 

Protected Member Functions

virtual size_t updateHash () const =0
 Update the cachedHash value. More...
 

Protected Attributes

const size_t id
 Identifier of each DataHandler. More...
 
size_t cachedHash
 Cached value returned by the getHash() function. More...
 
bool invalidCachedHash
 Boolean value indicating whether the current cachedValue is valid, or not. More...
 

Static Protected Attributes

static size_t count = 0
 Static count used to initialize the id of each DataHandler. More...
 

Detailed Description

Base class for all sources of data to be accessed by a TPG Instruction executed within a Program.

Member Function Documentation

◆ canHandle()

virtual bool Data::DataHandler::canHandle ( const std::type_info &  type) const
pure virtual

Check a given DataHandler can handle data for the given data type.

Parameters
[in]typethe std::type_info whose availability in the DataHandler is being tested.
Returns
true if the DataHandler can handle data for the given data type, and false otherwise.

Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ clone()

virtual DataHandler * Data::DataHandler::clone ( ) const
pure virtual

Return a copy of the DataHandler (with all its content).

The returned copy should always have the same polymorphic type as the original object, and give the same hash and data until the original or the copy is modified.

Returns
a pointer to the clone.

Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, Data::ArrayWrapper< double >, Data::PrimitiveTypeArray< T >, Data::PrimitiveTypeArray< Constant >, Data::PrimitiveTypeArray< double >, and Data::PrimitiveTypeArray2D< T >.

◆ getAddressesAccessed()

virtual std::vector< size_t > Data::DataHandler::getAddressesAccessed ( const std::type_info &  type,
const size_t  address 
) const
pure virtual

Get the set of addresses actually used when getting the given type of data, at the given address.

When accessing a DataHandler with a type differing from the native storage type of the DataHandler, like an array for example, the DataHandler may need to use several of its data element to create and return the requested type. Keeping track of what addresses have been accessed and used may be usefull to better explain what part of the data was used in a learning process, or to identify introns when the DataHandler in question are the registers of the execution engine. This method returns the list of addresses that are used when requesting a given type of data, at a given address.

Parameters
[in]typethe std::type_info of data whose access pattern is analyzed.
[in]addressthe location of the data to retrieve.
Returns
a std::vector containing the addresses of data accessed. In case the given type of data is invalid, or the address, an empty vector is returned.

Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ getAddressSpace()

virtual size_t Data::DataHandler::getAddressSpace ( const std::type_info &  type) const
pure virtual

Get the getAddressSpace size for the given data type.

Since a single DataHandler may be able to provide data of different types, the addressable space may vary depending on the accessed data type. This method returns the size of addressable data for each type of data.

Parameters
[in]typethe std::type_info of data whose address space is retrieved.
Returns
the size of the retrieved address space, or 0 if the data type is not handled by the DataHandler.

Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ getDataAt()

virtual UntypedSharedPtr Data::DataHandler::getDataAt ( const std::type_info &  type,
const size_t  address 
) const
pure virtual

Get data of the given type, from the given address.

Data is returned as an UntypedSharedPtr, with two possible allocations:

  • Classic pointer: The returned data is natively contained in the DataHandler and could be accessed through a regular pointer. In this case the returned UntypedSharedPtr is associated with an empty destructor function as its destructor to avoid any deallocation on the shared_ptr deletion.
  • Shared pointer: The returned data is a temporary object that was constructed on request from data in the DataHandler. Once it has been used, on deletion of the shared pointer, this temporary object is deallocated using its default destructor.
Parameters
[in]typethe std::type_info of data retrieved.
[in]addressthe location of the data to retrieve.
Exceptions
std::invalid_argumentif the given data type is not provided by the DataHandler.
std::out_of_rangeif the given address is invalid for the given data type.
Returns
a shared pointer to the requested const data.

Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ getDimensionsSize()

virtual std::vector< size_t > Data::DataHandler::getDimensionsSize ( ) const
pure virtual

Give the size of each dimension (if any) of the DataHandler.

Function that returns a std::vector<size_t> that contain the size of each dimension of the date in the DataHandler. For a scalar value, a one-element vector containing only value 1 is returned. For a 1D array the vector contains the size of the array, for a 2D array the vector holds the height and the width of the DataHandler.

This info is currently used only to support the code generation feature of GEGELATI.

Returns
a std::vector containing the size of each dimension of a DataHandler

Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ getHash()

size_t Data::DataHandler::getHash ( ) const

Get the current value of the hash for this DataHandler.

This method returns the value of the hash, and updates it if necessary.

Returns
the cached value of the Hash.

◆ getId()

size_t Data::DataHandler::getId ( ) const

Get the ID of the DataHandler.

Two DataHandler should have the same ID only if the are copy from each other, possibly holding different data. This property will be used to simplify check that two different DataHandler have the exact same characteristics (handled types, addressSpace, ..)

◆ getLargestAddressSpace()

virtual size_t Data::DataHandler::getLargestAddressSpace ( ) const
pure virtual

Get the largest AddressSpace for all data types handled by the DataHandler.

This method relies on the getAddressSpace and getHandledTypes methods to compute the size of the largest addressSpace required by the dataHandler.

Returns
the size of the largest addressSpace.

Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ getNativeType()

virtual const std::type_info & Data::DataHandler::getNativeType ( ) const
pure virtual

Function returning the native type of the DataHandler.

For example, in case of a Data::PrimitiveTypeArray<double> this function return typeid(double).

This info is currently used only to support the code generation feature of GEGELATI.

Returns
std::type_info of the template

Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

◆ resetData()

virtual void Data::DataHandler::resetData ( )
pure virtual

Generic method for DataHandler to reset their data.

Method used to reset the data handled by a DataHandler. Each DataHandler can implement a custom behavior, or even no behavior at all for this method.

This method shall invalidate the cachedHash.

Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, Data::ArrayWrapper< double >, Data::PrimitiveTypeArray< T >, Data::PrimitiveTypeArray< Constant >, Data::PrimitiveTypeArray< double >, and Data::PrimitiveTypeArray2D< T >.

◆ scaleLocation()

uint64_t Data::DataHandler::scaleLocation ( const uint64_t  rawLocation,
const std::type_info &  type 
) const

Scale a location from the Environment largestAddressSpace to the largestAddressSpace of the dataHandler, for the given data type.

This function computes a valid location for the current DataHandler with the given data type. This location is computed from the given rawLocation with a simple modulo. The choice of the Modulo was made for simplicity and faster execution, but may introduce a bias towards low values. If this becomes a problem, a proper scaling with a division would be needed.

Parameters
[in]rawLocationinteger number between 0 and the environment largestAddressSpace. (unchecked)
[in]typethe type of data accessed.
Returns
(rawLocation % dataHandler.largestAddressSpace(type))
Exceptions
std::domain_errorif the data type is not supported by the data handler.

◆ updateHash()

virtual size_t Data::DataHandler::updateHash ( ) const
protectedpure virtual

Update the cachedHash value.

This methods trigger an update of the cachedHash value and returns the new value.

Returns
the new value of the cachedhash attribute.

Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.

Member Data Documentation

◆ cachedHash

size_t Data::DataHandler::cachedHash
mutableprotected

Cached value returned by the getHash() function.

The value of the hash is updated whenever the updateHash function is called.

◆ count

size_t Data::DataHandler::count = 0
staticprotected

Static count used to initialize the id of each DataHandler.

Copyright or © or Copr. IETR/INSA - Rennes (2019 - 2021) :

Karol Desnos kdesn.nosp@m.os@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2019 - 2020) Nicolas Sourbier nsour.nosp@m.bie@.nosp@m.insa-.nosp@m.renn.nosp@m.es.fr (2019 - 2020) Thomas Bourgoin tbour.nosp@m.goi@.nosp@m.insa-.nosp@m.renn.nosp@m.es.fr (2021)

GEGELATI is an open-source reinforcement learning framework for training artificial intelligence based on Tangled Program Graphs (TPGs).

This software is governed by the CeCILL-C license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".

As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.

In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.

The fact that you are presently reading this means that you have had knowledge of the CeCILL-C license and that you accept its terms.

◆ id

const size_t Data::DataHandler::id
protected

Identifier of each DataHandler.

This identifier should be used as a seed for the initialization of the hash calculation. Two DataHandler resulting from a copy should thus have the same id.

◆ invalidCachedHash

bool Data::DataHandler::invalidCachedHash
mutableprotected

Boolean value indicating whether the current cachedValue is valid, or not.

When getting the value of the hash, it shall be automatically updated when invalidCachedHash is set to true. Whenever the data contained in a DataHandler is modifier, the invalidCachedHash attribute shall be set to true.


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