Skip to content
Snippets Groups Projects
Cyril Moineau's avatar
Cyril Moineau authored
[Feat] Add simple conv export template

See merge request !4
5236e4ef
History

Aidge module template

You can copy and use this module template to build your own custom module for Aidge. Everything is already in place for adding new C++ and/or Python functionnalities and make them available to Aidge users as an add-on module.

This module also contains the basic features and files to start building your own aidge export. Please refer to the Export Related Files part.

Steps

  1. Edit your module name and version number in the project_name.txt and version.txt files respectively.

  2. Add your C++ headers and sources in the include/aidge and src folders respectively.

    2.1. If you need Python binding for your C++ functions, you can add them in the python_binding folder;

    2.2. You can add your unit tests, using Catch2, in the unit_tests folder.

  3. Add your pure Python sources in the aidge_module_template folder. Don't forget to rename it to match the name of your module.

  4. If you want to use Gitlab CI, everything is already pre-configured. Just follow the instructions in the .gitlab-ci.yml file.

Content

Aidge Module

There are 3 independent basic examples embedded in this module template to help get you started:

  • Example 1: a simple C++ function (first part in header; source) extending the Aidge API that is also binded in Python. A simple C++ unit test is included as well (source);
  • Example 2: an operator custom backend implementation in C++ (second part in header; source) that is automatically registered in Aidge;
  • Example 3: a pure Pyhon function (source) extending the Aidge API (Python only). A simple Python unit test is included as well (source).

Export Related Files

Most of the export related files are located within the aidge_module_template/aidge_module_template/ folder.
Here is a quick description of the folder tree :

  • kernels : Hold the kernels' implementations
  • operators : Hold the files registering the supported kernels into the export backend
  • static : Utilitary files needed by the generated export
  • templates : Jinja templates used to generate export files
    • configuration : Header files for layer's configuration
    • kernel_forward : Layer's forward call function
  • export.py : Main export() function
  • export_registry.py : Hold the ExportLib class
  • export_utils.py : Utilitary functions used to manipulate the graph before the export step
  • generate_main.py
  • node_export.py
  • utils.py

If your new aidge module is not an export, you may delete these files and folders.

A notebook has been provided to help you understand the steps to follow to create and export a simple model using this basic export.

Please refer to the Export User Guide and the Export Tutorials to get more details on how exports work in Aidge.

Installation

For C++ API

To build and install the C++ API of this module, create a build sub-directory and inside build run:

cmake -DCMAKE_PREFIX_PATH=path/to/aidge/install/folder -DCMAKE_INSTALL_PREFIX:PATH=path/to/install/folder ..
make all install

Where path/to/aidge/install/folder is the install path of Aidge and the other Aidge modules and path/to/install/folder is the install path for your new module (which may be the same as the Aidge install folder).

Compilation options

Option Value type Description
-DCMAKE_INSTALL_PREFIX:PATH str Path to the install folder
-DCMAKE_BUILD_TYPE str If Debug, compile in debug mode, Release compile with highest optimisations, default= Release
-DWERROR bool If ON show warning as error during compilation phase, default=OFF
-DPYBIND bool If ON activate python binding, default=ON

If you have compiled with PyBind you can find at the root of the build file the python lib aidge_core.cpython*.so

For Python API

To build and install the Python API of this module on Linux using pip, follow those steps:

  1. Create your python environnement with python >= 3.7. For example using virtualenv:
virtualenv -p python3.8 py_env_aidge
source py_env_aidge/bin/activate
  1. Optionnal: Set the desired install path (which should be the same that you used for Aidge and other Aidge modules):
export AIDGE_INSTALL='<path_to_aidge>/install'

By default aidge install its library in the lib/ folder of your python env, following PEP405 standard.

  1. Build your aidge_module_template module:
pip install . -v

Run tests

CPP

Inside of the build folder, run:

ctest --output-on-failure

Python

Inside the aidge_module_template sub-folder, run:

python -m unittest discover -s tests -v