GEGELATI
|
Base class for all sources of data to be accessed by a TPG Instruction executed within a Program. More...
#include <dataHandler.h>
Public Member Functions | |
DataHandler () | |
Default constructor of the DataHandler class. | |
virtual | ~DataHandler ()=default |
Default destructor. | |
DataHandler (const DataHandler &other)=default | |
Default copy constructor. | |
virtual DataHandler * | clone () 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... | |
|
pure virtual |
Check a given DataHandler can handle data for the given data type.
[in] | type | the std::type_info whose availability in the DataHandler is being tested. |
Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
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.
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 >.
|
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.
[in] | type | the std::type_info of data whose access pattern is analyzed. |
[in] | address | the location of the data to retrieve. |
Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
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.
[in] | type | the std::type_info of data whose address space is retrieved. |
Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
pure virtual |
Get data of the given type, from the given address.
Data is returned as an UntypedSharedPtr, with two possible allocations:
[in] | type | the std::type_info of data retrieved. |
[in] | address | the location of the data to retrieve. |
std::invalid_argument | if the given data type is not provided by the DataHandler. |
std::out_of_range | if the given address is invalid for the given data type. |
Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
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.
Implemented in Data::Array2DWrapper< T >, Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
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.
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, ..)
|
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.
Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
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.
Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
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 >.
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.
[in] | rawLocation | integer number between 0 and the environment largestAddressSpace. (unchecked) |
[in] | type | the type of data accessed. |
std::domain_error | if the data type is not supported by the data handler. |
|
protectedpure virtual |
Update the cachedHash value.
This methods trigger an update of the cachedHash value and returns the new value.
Implemented in Data::ArrayWrapper< T >, Data::ArrayWrapper< Constant >, and Data::ArrayWrapper< double >.
|
mutableprotected |
Cached value returned by the getHash() function.
The value of the hash is updated whenever the updateHash function is called.
|
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.
|
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.
|
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.