GEGELATI

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CodeGen::ProgramGenerationEngine Class Reference

Class in charge of generating inference C code for all the Program of a TPG. More...

`#include <programGenerationEngine.h>`

Inheritance diagram for CodeGen::ProgramGenerationEngine:

## Public Member Functions
virtual void | processLine () override
| inherited from Program::ProgramEngine
| ProgramGenerationEngine (const std::string &filename, const Environment &env, const std::string &path="./")
| Constructor of the class.
| ProgramGenerationEngine (const std::string &filename, const Program::Program &p, const std::string &path="./")
| Constructor of the class.
| ~ProgramGenerationEngine ()
| Destructor of the class.
void | generateCurrentLine ()
| Generate the current line of the program.
void | generateProgram (uint64_t progID, const bool ignoreException=false)
| Generate the C code that corresponds to the member program of the class.
Public Member Functions inherited from Program::ProgramEngine
void | setProgram (const Program &prog)
| Method for changing the Program executed by a ProgramExecutionEngin.
template<class T >
void | setDataSources (const std::vector< std::reference_wrapper< T > > &dataSrc)
| Method for changing the dataSources on which the Program will be executed.
const std::vector< std::reference_wrapper< const Data::DataHandler > > & | getDataSources () const
| Get the DataHandler of the ProgramExecutionEngine.
const bool | next ()
| Increments the programCounter and checks for the end of the Program.
const Line & | getCurrentLine () const
| Get the Program Line corresponding to the current programCounter.
const Instructions::Instruction & | getCurrentInstruction () const
| Get the Instruction corresponding to the current programCounter.
const void | fetchCurrentOperands (std::vector< Data::UntypedSharedPtr > &operands) const
| Get the operands for the current Instruction.
uint64_t | getOperandLocation (uint64_t idxOp) const
| Get the location for the current Instruction.
virtual void | iterateThroughtProgram (const bool ignoreException)
| Function that iterates through the lines of the program and execute the function processLine().
virtual std::vector< double > | getRegisterValues (uint64_t nbRegisters)
| Return the current registers value of the program indicated.

## Protected Member Functions
void | initGlobalVar (size_t nbConstant)
| Set global variables in the file holding the programs.
std::string | completeFormat (const Instructions::Instruction &instruction) const
| Generates the line of C code that implements the instruction in parameter.
void | openFile (const std::string &filename, const std::string &path, size_t nbConstant)
| Function used to open the file that is generated.
void | initOperandCurrentLine ()
| Function called to generate the initialization of all operands of an instruction.
std::string | getNameSourceData (const uint64_t &idx)
| Method returning the name of the data source in the file generated.
Protected Member Functions inherited from Program::ProgramEngine
| ProgramEngine ()=delete
| Default constructor is deleted.
| ProgramEngine (const Environment &env)
| Constructor of the class.
template<class T >
| ProgramEngine (const Program &prog, const std::vector< std::reference_wrapper< T > > &dataSrc)
| Constructor of the class.
| ProgramEngine (const Program &prog)
| Constructor of the class.

## Protected Attributes
std::ofstream | fileC
| The file in which programs will be added.
std::ofstream | fileH
| The file in which prototypes of programs will be added.
Data::DataHandlerPrinter | dataPrinter
| Utility class used to print data accesses in generated code.
Protected Attributes inherited from Program::ProgramEngine
const Program * | program
Data::PrimitiveTypeArray< double > | registers
| Registers used for the Program execution.
std::vector< std::reference_wrapper< const Data::DataHandler > > | dataSources
| Data sources from the environment used for archiving a program.
std::vector< std::reference_wrapper< const Data::DataHandler > > | dataScsConstsAndRegs
| Data sources (including registers) used in the Program.
uint64_t | programCounter
| Program counter of the execution engine.

## Static Protected Attributes
static const std::regex | operand_regex
static const std::regex | constant_regex
static const std::string | nameDataVariable
| Name given to the global variable in generated files.
static const std::string | nameRegVariable
| name of the registers in the TPG's programs.
static const std::string | nameConstantVariable
| name of the array of constants in the TPG's programs.
static const std::string | nameOperandVariable
| name of the temporary operand used in the TPG's programs.

## Detailed Description

Class in charge of generating inference C code for all the Program of a TPG.

This class generates header and C source code files that implements the Program of a TPG. Code can be generated only if all instructions of the Program are printable, that is, if they inherits from PrintableInstruction.

In the generated code, inclusion of externHeader.h allows including necessary headers (like math.h) to compile the generated code without modifying it.

## Constructor & Destructor Documentation

## ◆ ProgramGenerationEngine() [1/2]

CodeGen::ProgramGenerationEngine::ProgramGenerationEngine | ( | const std::string & | filename,
|  | const Environment & | env,
|  | const std::string & | path = "./" )
| inline

Constructor of the class.

The constructor initializes the member of the parent class (ProgramEngine) and the file "filename" is opened with the flag std::ofstream::out to generate the program in the file and replace any previous content.

Parameters

  [in] | filename | a const reference used to generate the filename of the file that holds the programs of the TPG graph. The filename holding the programs of the TPG is : 'filename'_program.c
  [in] | env | a const reference to the Environment of the TPGGraph
  [in] | path | a const reference to the path in which the file must be generated. By default, the file is generated in the current directory.

## ◆ ProgramGenerationEngine() [2/2]

CodeGen::ProgramGenerationEngine::ProgramGenerationEngine | ( | const std::string & | filename,
|  | const Program::Program & | p,
|  | const std::string & | path = "./" )
| inline

Constructor of the class.

The constructor initializes the member of the parent class (ProgramEngine) and the file "filename" is open with the flag std::ofstream::out to generate the program in the file.

This constructor is useful to create a ProgramGeneration engine

Parameters

  [in] | filename | a const reference used to generate the filename of the file that holds the programs of the TPG graph. The filename holding the programs of the TPG is : 'filename'_program.c
  [in] | p | const reference to a Program
  [in] | path | const reference to the path in which the file is generated

## ◆ ~ProgramGenerationEngine()

CodeGen::ProgramGenerationEngine::~ProgramGenerationEngine | ( |  | ) |
| inline

Destructor of the class.

Close both files and add endif at the end of the generated header.

## Member Function Documentation

## ◆ completeFormat()

std::string CodeGen::ProgramGenerationEngine::completeFormat | ( | const Instructions::Instruction & | instruction | ) | const
| protected

Generates the line of C code that implements the instruction in parameter.

Replace each operand from the printTemplate of the printableInstruction with a pointer to the data of the environment, through the printed global variables.

Parameters

  [in] | instruction | that as to be converted into a line of code

Returns
  a copy of the printTemplate with the variables changed according to the operand of the instruction.

## ◆ generateCurrentLine()

void CodeGen::ProgramGenerationEngine::generateCurrentLine | ( |  | ) |

Generate the current line of the program.

Generate the line of code that corresponds to the current line in the program of the TPG.

## ◆ generateProgram()

void CodeGen::ProgramGenerationEngine::generateProgram | ( | uint64_t | progID,
|  | const bool | ignoreException = false )

Generate the C code that corresponds to the member program of the class.

Print a function in the file "filename"_program.c that regroups all the instruction of the program and return a double. The name of the printed function is based on the identifier of the program. The declaration of function of the program with ID=1 is double P1(int* action)

Parameters

  [in] | progID | : unique identifier of the program used to generate the name of the function in the C file.
  [in] | ignoreException | When true, all exceptions thrown when fetching current instructions, operands are caught and the current program Line is simply ignored. When false, all lines of the Program are assumed to be correct by construction, and any exception is re-thrown for higher-level handling, thus stopping the program. Exception thrown by getCurrentLine are never ignored.

## ◆ getNameSourceData()

std::string CodeGen::ProgramGenerationEngine::getNameSourceData | ( | const uint64_t & | idx | ) |
| protected

Method returning the name of the data source in the file generated.

Parameters

  [in] | idx | const uint64_t reference to the index of the data source in Environment of the Program.

Returns
  the name of the variable to use to access the data source in the generated program

## ◆ initGlobalVar()

void CodeGen::ProgramGenerationEngine::initGlobalVar | ( | size_t | nbConstant | ) |
| protected

Set global variables in the file holding the programs.

Global variables printed in the generated code are used by this code to access the data from the LearningEnvironment. This methot sets the type of the global variable accordingly to the type of the data sources of the Environment of the printed Program.

Parameters

  [in] | nbConstant | size_t of the number of Data::Constant available for a Program.

## ◆ initOperandCurrentLine()

void CodeGen::ProgramGenerationEngine::initOperandCurrentLine | ( |  | ) |
| protected

Function called to generate the initialization of all operands of an instruction.

This function prints in the C source file the declaration and the initialization for each operand of the current line.

## ◆ openFile()

void CodeGen::ProgramGenerationEngine::openFile | ( | const std::string & | filename,
|  | const std::string & | path,
|  | size_t | nbConstant )
| protected

Function used to open the file that is generated.

This is function is called in both constructor of the class. It open the source file and the header file. It also adds the include guards in the header.

Parameters

  [in] | filename | const reference to the name of the file.
  [in] | path | const reference to the path of the file.
  [in] | nbConstant | number of constant used in the program of the TPG.

## ◆ processLine()

void CodeGen::ProgramGenerationEngine::processLine | ( |  | ) |
| overridevirtual

inherited from Program::ProgramEngine

Implements Program::ProgramEngine.

## Member Data Documentation

## ◆ constant_regex

const std::regex CodeGen::ProgramGenerationEngine::constant_regex
| staticprotected

regex used to identify constant in the printTemplate of an Instruction.

## ◆ nameDataVariable

const std::string CodeGen::ProgramGenerationEngine::nameDataVariable
| staticprotected

Name given to the global variable in generated files.

"nameDataVariable"1 corresponds to the first variable "nameDataVariable"2 is used if an other data is given ...

## ◆ operand_regex

const std::regex CodeGen::ProgramGenerationEngine::operand_regex
| staticprotected

regex used to identify operand in the printTemplate of an Instruction.

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

Karol Desnos kdesn.nosp@m.os@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2019 - 2022) Quentin Vacher qvach.nosp@m.er@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2025) 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.

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

- D:/a/gegelati/gegelati/gegelatilib/include/codeGen/programGenerationEngine.h
- D:/a/gegelati/gegelati/gegelatilib/src/codeGen/programGenerationEngine.cpp