Skip to content
Snippets Groups Projects
Commit cda46ffd authored by Maxence Naud's avatar Maxence Naud
Browse files

Merge branch 'dev' into 'main'

v0.4.0

Closes #196 and #160

See merge request !279
parents 577e654a cc6b7704
No related branches found
No related tags found
1 merge request!279v0.4.0
Pipeline #63431 failed
Showing
with 416 additions and 231 deletions
---
Checks: "google-*, readability-identifier-naming"
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none
CheckOptions:
# Case style
# Following https://webkit.org/code-style-guidelines/ :
# CamelCase for class,struct, namespace
# camelBack for variables, functions
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.AbstractClassCase'
value: 'CamelCase'
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.ClassCase'
value: 'CamelCase'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ClassConstantCase'
value: 'camelBack'
- key: 'readability-identifier-naming.ClassConstantPrefix'
value: 's_'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ClassMemberCase'
value: 'camelBack'
- key: 'readability-identifier-naming.ClassMemberPrefix'
value: 's_'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ClassMethodCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantMemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantPointerParameterCase'
value: 'camelBack'
# camelBack for variables, functions
# camelBack for variables, functions
- key: 'readability-identifier-naming.ClassMemberCase'
value: 'camelBack'
- key: 'readability-identifier-naming.ClassMemberPrefix'
value: 's_'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ClassMethodCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantMemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstantPointerParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstexprFunctionCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstexprMethodCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ConstexprVariableCase'
value: 'camelBack'
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.EnumCase'
value: 'CamelCase'
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.EnumConstantCase'
value: 'CamelCase'
# camelBack for variables, functions
- key: 'readability-identifier-naming.FunctionCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.GlobalConstantCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.GlobalConstantPointerCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.GlobalFunctionCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.GlobalPointerCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.GlobalVariableCase'
value: 'camelBack'
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.InlineNamespaceCase'
value: 'CamelCase'
# camelBack for variables, functions
- key: 'readability-identifier-naming.LocalConstantCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.LocalConstantPointerCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.LocalPointerCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.LocalVariableCase'
value: 'camelBack'
- key: 'readability-identifier-naming.MacroDefinitionCase'
value: 'UPPER_CASE'
# camelBack for variables, functions
- key: 'readability-identifier-naming.MemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.MethodCase'
value: 'CamelCase'
# CamelCase for class,struct, namespace
- key: 'readability-identifier-naming.NamespaceCase'
value: 'CamelCase'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ParameterPackCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PointerParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PrivateMemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PrivateMemberPrefix'
value: 'm_'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PrivateMethodCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ProtectedMemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ProtectedMemberPrefix'
value: 'm_'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ProtectedMethodCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PublicMemberCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.PublicMethodCase'
value: 'camelBack'
- key: 'readability-identifier-naming.ScopedEnumConstantCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.StaticConstantCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.StaticVariableCase'
value: 'camelBack'
- key: 'readability-identifier-naming.StructCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TemplateParameterCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TemplateTemplateParameterCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TypeTemplateParameterIgnoredRegexp'
value: 'expr-type'
# CamelCase for Type aliases
- key: 'readability-identifier-naming.TypeAliasCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TypedefCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.TypeTemplateParameterCase'
value: 'CamelCase'
- key: 'readability-identifier-naming.UnionCase'
value: 'CamelCase'
# camelBack for variables, functions
- key: 'readability-identifier-naming.ValueTemplateParameterCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.VariableCase'
value: 'camelBack'
# camelBack for variables, functions
- key: 'readability-identifier-naming.VirtualMethodCase'
value: 'camelCase'
...
[codespell]
builtin = clear,rare,en-GB_to_en-US,names,informal,code
check-filenames =
check-hidden =
skip = */.git,*/build*,*/prefix,*/aidge_core,*/aidge_core.egg-info,*/cmake,*/future-std.clang-format
quiet-level = 2
# childs : used a lot and understandable
# dOut,inH,ro : used for testing
# deque : cpp data struct
# inout : commented code variable
# nd : commented code
# neighbours : exception to the gb to us english rule
# neighbouring : exception to the gb to us english rule
# endcode : documentation keyword
ignore-words-list = childs, dOut, inH, ro, deque, inout, stdio, nd, neighbours, neighbouring, endcode
...@@ -4,7 +4,7 @@ $ErrorActionPreference = "Stop" ...@@ -4,7 +4,7 @@ $ErrorActionPreference = "Stop"
$AIDGE_DEPENDENCIES = $env:AIDGE_DEPENDENCIES -split ' ' $AIDGE_DEPENDENCIES = $env:AIDGE_DEPENDENCIES -split ' '
Write-Host "Aidge dependencies : $AIDGE_DEPENDENCIES" Write-Host "Aidge dependencies : $AIDGE_DEPENDENCIES"
if ( $($AIDGE_DEPENDENCIES.Length) -eq 0) { if ( $($AIDGE_DEPENDENCIES.Length) -eq 0) {
Write-Host "- No dependencies provided for current repsitory" Write-Host "- No dependencies provided for current repository"
New-Item -ItemType Directory -Force -Path ".\build" | Out-Null New-Item -ItemType Directory -Force -Path ".\build" | Out-Null
Remove-Item -Path ".\build\*" -Recurse -Force Remove-Item -Path ".\build\*" -Recurse -Force
} else { } else {
......
# Version 0.4.0 (December 2024)
# Version 0.2.1 (May 14, 2024) # Version 0.2.1 (May 14, 2024)
* rework export mechanism * rework export mechanism
* change `Operator::computeOutputDims()` with `Operator::forwardDims()` * change `Operator::computeOutputDims()` with `Operator::forwardDims()`
* automatic docstring decorators for python * automatic docstring decorators for python
* add implementation of Operators only performing data/format manipulation * add implementation of Operators only performing data/format manipulation
......
...@@ -5,7 +5,7 @@ file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version) ...@@ -5,7 +5,7 @@ file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version)
project(aidge_core project(aidge_core
VERSION ${version} VERSION ${version}
DESCRIPTION "Core algorithms for operators and graph of the AIDGE framework" DESCRIPTION "Core algorithms for operators and graph of the AIDGE framework"
LANGUAGES CXX) LANGUAGES CXX)
message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") message(STATUS "Project name: ${CMAKE_PROJECT_NAME}")
message(STATUS "Project version: ${version}") message(STATUS "Project version: ${version}")
...@@ -14,6 +14,9 @@ add_definitions(-DPROJECT_VERSION="${version}") ...@@ -14,6 +14,9 @@ add_definitions(-DPROJECT_VERSION="${version}")
message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") message(STATUS "Project name: ${CMAKE_PROJECT_NAME}")
message(STATUS "Project version: ${version}") message(STATUS "Project version: ${version}")
# helper for LSP users
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Note : project name is {project} and python module name is also {project} # Note : project name is {project} and python module name is also {project}
set(module_name _${CMAKE_PROJECT_NAME}) # target name set(module_name _${CMAKE_PROJECT_NAME}) # target name
set(pybind_module_name ${CMAKE_PROJECT_NAME}) # name of submodule for python bindings set(pybind_module_name ${CMAKE_PROJECT_NAME}) # name of submodule for python bindings
...@@ -26,6 +29,7 @@ option(TEST "Enable tests" ON) ...@@ -26,6 +29,7 @@ option(TEST "Enable tests" ON)
option(COVERAGE "Enable coverage" OFF) option(COVERAGE "Enable coverage" OFF)
option(ENABLE_ASAN "Enable ASan (AddressSanitizer) for runtime analysis of memory use (over/underflow, memory leak, ...)" OFF) option(ENABLE_ASAN "Enable ASan (AddressSanitizer) for runtime analysis of memory use (over/underflow, memory leak, ...)" OFF)
############################################## ##############################################
# Import utils CMakeLists # Import utils CMakeLists
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
...@@ -36,22 +40,28 @@ endif() ...@@ -36,22 +40,28 @@ endif()
############################################## ##############################################
# Find system dependencies # Find system dependencies
Include(FetchContent)
set(FMT_VERSION 10.2.1) set(FMT_VERSION 10.2.1)
message(STATUS "Retrieving fmt ${FMT_VERSION} from git")
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG ${FMT_VERSION} # or a later release
)
set(FMT_SYSTEM_HEADERS ON) find_package(fmt ${FMT_VERSION} QUIET)
FetchContent_MakeAvailable(fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
find_package(Threads REQUIRED) if(NOT fmt_FOUND)
message(STATUS "fmt not found in system, retrieving from git")
Include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG ${FMT_VERSION}
)
set(FMT_SYSTEM_HEADERS ON)
FetchContent_MakeAvailable(fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
else()
message(STATUS "Found system fmt version ${fmt_VERSION}")
endif()
find_package(Threads REQUIRED)
############################################## ##############################################
# Create target and set properties # Create target and set properties
......
include README.md LICENCE include README.md LICENSE
recursive-include aidge_core *.py recursive-include aidge_core *.py
recursive-exclude aidge_core/unit_tests *.py recursive-exclude aidge_core/unit_tests *.py
......
...@@ -8,7 +8,7 @@ You can find here the C++ code of the Core library of Aidge. ...@@ -8,7 +8,7 @@ You can find here the C++ code of the Core library of Aidge.
## Pip installation ## Pip installation
To install aidge_core using pip, run the following command in your python environnement : To install aidge_core using pip, run the following command in your python environment :
``` bash ``` bash
pip install . -v pip install . -v
``` ```
...@@ -23,7 +23,7 @@ pip install . -v ...@@ -23,7 +23,7 @@ pip install . -v
To setup aidge_core using pip in development (or editable mode), use the `--no-build-isolation -e` options to pip. To setup aidge_core using pip in development (or editable mode), use the `--no-build-isolation -e` options to pip.
For instance run the following command in your python environnement for a typical setup : For instance run the following command in your python environment for a typical setup :
``` bash ``` bash
export AIDGE_BUILD_TEST=ON # enable C++ unit tests export AIDGE_BUILD_TEST=ON # enable C++ unit tests
export AIDGE_PYTHON_BUILD_TYPE= # default flags (no debug info but fastest build time) export AIDGE_PYTHON_BUILD_TYPE= # default flags (no debug info but fastest build time)
...@@ -85,7 +85,7 @@ make all install ...@@ -85,7 +85,7 @@ make all install
| Option | Value type | Description | | Option | Value type | Description |
|:----------:|:----------:|:-----------:| |:----------:|:----------:|:-----------:|
| *-DCMAKE_INSTALL_PREFIX:PATH* | ``str`` | Path to the install folder | | *-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 or "" (empty) , default= ``Release`` | | *-DCMAKE_BUILD_TYPE* | ``str`` | If ``Debug``, compile in debug mode, ``Release`` compile with highest optimizations or "" (empty) , default= ``Release`` |
| *-DWERROR* | ``bool`` | If ``ON`` show warning as error during compilation phase, default=``OFF`` | | *-DWERROR* | ``bool`` | If ``ON`` show warning as error during compilation phase, default=``OFF`` |
| *-DTEST* | ``bool`` | If ``ON`` build C++ unit tests, default=``ON`` | | *-DTEST* | ``bool`` | If ``ON`` build C++ unit tests, default=``ON`` |
| *-DPYBIND* | ``bool`` | If ``ON`` activate python binding, default=``OFF`` | | *-DPYBIND* | ``bool`` | If ``ON`` activate python binding, default=``OFF`` |
......
...@@ -7,8 +7,10 @@ http://www.eclipse.org/legal/epl-2.0. ...@@ -7,8 +7,10 @@ http://www.eclipse.org/legal/epl-2.0.
SPDX-License-Identifier: EPL-2.0 SPDX-License-Identifier: EPL-2.0
""" """
from .aidge_core import * # import so generated by PyBind from aidge_core.aidge_core import * # import so generated by PyBind
from .export_utils import ExportNode, generate_file, generate_str import aidge_core.export_utils
from .aidge_export_aidge import * import aidge_core.utils
from . import utils from aidge_core.aidge_export_aidge import serialize_to_cpp
from aidge_core.show_graphview import gview_to_json
from aidge_core.mem_info import *
from ._version import * from ._version import *
...@@ -5,4 +5,4 @@ FILE = Path(__file__).resolve() ...@@ -5,4 +5,4 @@ FILE = Path(__file__).resolve()
ROOT_EXPORT = FILE.parents[0] ROOT_EXPORT = FILE.parents[0]
from .operator_export import * from .operator_export import *
from .export import export from .export import serialize_to_cpp
...@@ -2,15 +2,14 @@ import aidge_core ...@@ -2,15 +2,14 @@ import aidge_core
import shutil import shutil
import os import os
from pathlib import Path from pathlib import Path
from .utils import supported_operators, OPERATORS_REGISTRY
from . import ROOT_EXPORT
from aidge_core import ExportNode, generate_file
import aidge_core.export_utils
from . import ROOT_EXPORT
from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.export_utils import generate_file
def export(export_folder: str, def serialize_to_cpp(export_folder: str,
graph_view: aidge_core.GraphView, graph_view: aidge_core.GraphView,
enable_python_binding: bool = True, enable_python_binding: bool = True,
): ):
...@@ -54,12 +53,11 @@ def export(export_folder: str, ...@@ -54,12 +53,11 @@ def export(export_folder: str,
### Generating an export for each nodes and dnn file ### ### Generating an export for each nodes and dnn file ###
list_configs = [] # List of headers to include in dnn.cpp to access attribute and parameters list_configs = [] # List of headers to include in dnn.cpp to access attribute and parameters
list_actions = [] # List of string to construct graph list_actions = [] # List of string to construct graph
set_operator = set() list_operators = [] # List of operator types used (to be made unique latter)
# Queue of Aidge nodes to explore, guarantee a topological exploration of the graph # Queue of Aidge nodes to explore, guarantee a topological exploration of the graph
open_nodes = list(graph_view.get_input_nodes()) open_nodes = list(graph_view.get_input_nodes())
# List of Aidge nodes already explored # List of Aidge nodes already explored
closed_nodes = [] closed_nodes = []
while open_nodes: while open_nodes:
node = open_nodes.pop(0) node = open_nodes.pop(0)
if node in closed_nodes: if node in closed_nodes:
...@@ -80,25 +78,37 @@ def export(export_folder: str, ...@@ -80,25 +78,37 @@ def export(export_folder: str,
continue continue
# Next nodes to treat are children of current node # Next nodes to treat are children of current node
open_nodes += list(node.get_children()) open_nodes += list(node.get_children())
node.get_operator().set_backend(ExportSerialize._name)
op_impl = node.get_operator().get_impl()
if op_impl is None:
raise RuntimeError(f"Operator {node.name()}[{node.type()}] doesn't have an implementation.")
if not isinstance(op_impl, ExportSerialize):
raise RuntimeError(f"Operator {node.name()}[{node.type()}] doesn't have an exportable backend ({op_impl}).")
required_specs = op_impl.get_required_spec()
specs = op_impl.get_best_match(required_specs)
export_node = op_impl.get_export_node(specs)
if export_node is None:
raise RuntimeError(f"Could not find export node for {node.name()}[{node.type()}].")
op = export_node(
node, None)
if node.type() in supported_operators(): # set_operator.add(node.type())
set_operator.add(node.type())
op = OPERATORS_REGISTRY[node.type()](node)
# TODO: list_configs and list_actions don't need to be passed by argument # TODO: list_configs and list_actions don't need to be passed by argument
# Export the configuration # Export the configuration
list_configs = op.export(export_folder_path, list_configs) list_configs += op.export(export_folder_path)
# Add forward kernel # Add forward kernel
list_actions = op.forward(list_actions) list_actions += op.forward()
else:
raise RuntimeError(f"Operator: {node.type()} is not supported")
closed_nodes.append(node) closed_nodes.append(node)
list_operators = list(dict.fromkeys(list_operators)) # make unique
# Generate full dnn.cpp # Generate full dnn.cpp
aidge_core.generate_file( aidge_core.export_utils.generate_file(
export_folder_path / "src/dnn.cpp", export_folder_path / "src/dnn.cpp",
ROOT_EXPORT / "templates/dnn.jinja", ROOT_EXPORT / "templates/dnn.jinja",
headers=list_configs, headers=list_configs,
operators=set_operator, operators=list_operators,
actions=list_actions, actions=list_actions,
) )
from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@ExportSerialize.register("Add", ImplSpec(IOSpec(dtype.any)))
class Add(ExportNodeCpp):
def __init__(self, node, mem_info):
super().__init__(node, mem_info)
self.config_template = ""
self.forward_template = str(
ROOT_EXPORT / "templates/graph_ctor/add.jinja")
self.include_list = ["aidge/operator/Add.hpp"]
self.kernels_to_copy = []
from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_input from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core import ExportNode, generate_file, generate_str from aidge_core.export_utils import ExportNodeCpp
from pathlib import Path from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("Conv") @ExportSerialize.register(["Conv1D", "Conv2D"], ImplSpec(IOSpec(dtype.any)))
class Conv(ExportNode): class Conv(ExportNodeCpp):
def __init__(self, node): def __init__(self, node, mem_info):
super().__init__(node) super().__init__(node, mem_info)
self.config_template = str(
def export(self, export_folder:Path, list_configs:list): ROOT_EXPORT / "templates/attributes/conv.jinja")
include_path = f"attributes/{self.name}.hpp" self.forward_template = str(
filepath = export_folder / f"include/{include_path}" ROOT_EXPORT /"templates/graph_ctor/conv.jinja")
self.include_list = ["aidge/operator/Conv.hpp"]
generate_file( self.kernels_to_copy = []
filepath, self.config_path = "include/attributes"
ROOT_EXPORT / "templates/attributes/conv.jinja", self.config_extension = "hpp"
name=self.name,
**self.attributes
)
list_configs.append(include_path)
return list_configs
def forward(self, list_actions:list):
list_actions.append(generate_str(
ROOT_EXPORT /"templates/graph_ctor/conv.jinja",
name=self.name,
inputs=parse_node_input(self.node.inputs()),
**self.attributes
))
return list_actions
from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@ExportSerialize.register(["ConvDepthWise1D", "ConvDepthWise2D"], ImplSpec(IOSpec(dtype.any)))
class ConvDepthWise(ExportNodeCpp):
def __init__(self, node, mem_info):
super().__init__(node, mem_info)
self.config_template = str(
ROOT_EXPORT / "templates/attributes/conv_depth_wise.jinja")
self.forward_template = str(
ROOT_EXPORT /"templates/graph_ctor/conv_depth_wise.jinja")
self.include_list = ["aidge/operator/ConvDepthWise.hpp"]
self.kernels_to_copy = []
self.config_path = "include/attributes"
self.config_extension = "hpp"
from aidge_core.aidge_export_aidge.utils import operator_register,parse_node_input from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core import ExportNode, generate_file, generate_str from aidge_core.export_utils import ExportNodeCpp
from pathlib import Path from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("FC")
class FC(ExportNode): @ExportSerialize.register("FC", ImplSpec(IOSpec(dtype.any)))
def __init__(self, node): class FC(ExportNodeCpp):
super().__init__(node) def __init__(self, node, mem_info):
super().__init__(node, mem_info)
self.config_template = str(
def export(self, export_folder:Path, list_configs:list): ROOT_EXPORT / "templates/attributes/fc.jinja")
self.forward_template = str(
ROOT_EXPORT / "templates/graph_ctor/fc.jinja")
include_path = f"attributes/{self.name}.hpp" self.include_list = ["aidge/operator/FC.hpp"]
filepath = export_folder / f"include/{include_path}" self.kernels_to_copy = []
self.config_path = "include/attributes"
self.config_extension = "hpp"
generate_file(
filepath,
ROOT_EXPORT / "templates/attributes/fc.jinja",
name=self.name,
InChannels=self.inputs_dims[1][1],
OutChannels=self.operator.out_channels(),
**self.attributes
)
list_configs.append(include_path)
return list_configs
def forward(self, list_actions:list):
list_actions.append(generate_str(
ROOT_EXPORT / "templates/graph_ctor/fc.jinja",
name=self.name,
inputs=parse_node_input(self.node.inputs()),
**self.attributes
))
return list_actions
from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_input from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core import ExportNode, generate_file, generate_str from aidge_core.export_utils import ExportNodeCpp
from pathlib import Path from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("MaxPooling") @ExportSerialize.register(["MaxPooling1D", "MaxPooling2D", "MaxPooling3D"], ImplSpec(IOSpec(dtype.any)))
class MaxPooling(ExportNode): class MaxPooling(ExportNodeCpp):
def __init__(self, node): def __init__(self, node, mem_info):
super().__init__(node) super().__init__(node, mem_info)
self.config_template = str(
ROOT_EXPORT / "templates/attributes/maxpooling.jinja")
def export(self, export_folder:Path, list_configs:list): self.forward_template = str(
include_path = f"attributes/{self.name}.hpp" ROOT_EXPORT / "templates/graph_ctor/maxpooling.jinja")
filepath = export_folder / f"include/{include_path}" self.include_list = ["aidge/operator/MaxPooling.hpp"]
self.kernels_to_copy = []
generate_file( self.config_path = "include/attributes"
filepath, self.config_extension = "hpp"
ROOT_EXPORT / "templates/attributes/maxpooling.jinja",
name=self.name,
**self.attributes
)
list_configs.append(include_path)
return list_configs
def forward(self, list_actions:list):
list_actions.append(generate_str(
ROOT_EXPORT / "templates/graph_ctor/maxpooling.jinja",
name=self.name,
inputs=parse_node_input(self.node.inputs()),
**self.attributes
))
return list_actions
from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@ExportSerialize.register(["Pad1D", "Pad2D"], ImplSpec(IOSpec(dtype.any)))
class Pad(ExportNodeCpp):
def __init__(self, node, mem_info):
super().__init__(node, mem_info)
self.config_template = str(
ROOT_EXPORT / "templates/attributes/pad.jinja")
self.forward_template = str(
ROOT_EXPORT /"templates/graph_ctor/pad.jinja")
self.include_list = ["aidge/operator/Pad.hpp"]
self.kernels_to_copy = []
self.config_path = "include/attributes"
self.config_extension = "hpp"
from aidge_core.aidge_export_aidge.utils import operator_register
from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core import dtype, ExportNode, generate_file, generate_str
import numpy as np import numpy as np
from pathlib import Path
# Convert aidge datatype to C++ type
datatype_converter = {
dtype.float64 : "double",
dtype.float32 : "float",
dtype.float16 : "half_float::half",
dtype.int8 : "int8_t",
dtype.int16 : "int16_t",
dtype.int32 : "int32_t",
dtype.int64 : "int64_t",
dtype.uint8 : "uint8_t",
dtype.uint16 : "uint16_t",
dtype.uint32 : "uint32_t",
dtype.uint64 : "uint64_t"
}
from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core.aidge_export_aidge import ROOT_EXPORT
from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("Producer") @ExportSerialize.register("Producer", ImplSpec(IOSpec(dtype.any)))
class Producer(ExportNode): class Producer(ExportNodeCpp):
""" """
If there is a standardization of the export operators If there is a standardization of the export operators
then this class should be just a inheritance of ProducerCPP then this class should be just a inheritance of ProducerCPP
""" """
def __init__(self, node): def __init__(self, node, mem_info):
super().__init__(node) super().__init__(node, mem_info)
child, in_idx = self.node.output(0)[0] child, in_idx = self.node.output(0)[0]
self.tensor_name = f"{child.name()}_{in_idx}"
self.values = np.array(self.operator.get_output(0))
def export(self, export_folder:Path, list_configs:list):
assert(len(self.node.output(0)) == 1)
include_path = f"parameters/{self.tensor_name}.hpp" self.values = np.array(self.operator.get_output(0))
filepath = export_folder / f"include/{include_path}"
aidge_tensor = self.operator.get_output(0) self.config_template = str(
aidge_type = aidge_tensor.dtype() ROOT_EXPORT / "templates/parameter.jinja")
if aidge_type in datatype_converter: self.forward_template = str(
datatype = datatype_converter[aidge_type] ROOT_EXPORT / "templates/graph_ctor/producer.jinja")
else: self.attributes["tensor_name"] = f"{child.name()}_{in_idx}"
raise RuntimeError(f"No conversion found for data type {aidge_type}.") self.attributes["values"] = str(self.operator.get_output(0))
generate_file( self.include_list = ["aidge/operator/Producer.hpp"]
filepath, self.kernels_to_copy = []
ROOT_EXPORT / "templates/parameter.jinja", self.config_path = "include/attributes"
dims = aidge_tensor.dims(), self.config_extension = "hpp"
data_t = datatype, # TODO : get data from producer
name = self.tensor_name,
values = str(aidge_tensor)
)
list_configs.append(include_path)
return list_configs
def forward(self, list_actions:list):
list_actions.append(generate_str(
ROOT_EXPORT / "templates/graph_ctor/producer.jinja",
name=self.name,
tensor_name=self.tensor_name,
**self.attributes
))
return list_actions
from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_input from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core import ExportNode, generate_str
from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core.aidge_export_aidge import ROOT_EXPORT
from pathlib import Path from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("ReLU") @ExportSerialize.register("ReLU", ImplSpec(IOSpec(dtype.any)))
class ReLU(ExportNode): class ReLU(ExportNodeCpp):
def __init__(self, node): def __init__(self, node, mem_info):
super().__init__(node) super().__init__(node, mem_info)
self.config_template = ""
def export(self, export_folder:Path, list_configs:list): self.forward_template = str(
return list_configs ROOT_EXPORT / "templates/graph_ctor/relu.jinja")
self.include_list = ["aidge/operator/ReLU.hpp"]
def forward(self, list_actions:list): self.kernels_to_copy = []
list_actions.append(generate_str(
ROOT_EXPORT / "templates/graph_ctor/relu.jinja",
name=self.name,
inputs=parse_node_input(self.node.inputs()),
**self.attributes
))
return list_actions
from aidge_core.aidge_export_aidge.utils import operator_register, parse_node_input from aidge_core.aidge_export_aidge.registry import ExportSerialize
from aidge_core import ExportNode, generate_str
from aidge_core.aidge_export_aidge import ROOT_EXPORT from aidge_core.aidge_export_aidge import ROOT_EXPORT
from pathlib import Path from aidge_core.export_utils import ExportNodeCpp
from aidge_core import ImplSpec, IOSpec, dtype
@operator_register("Sub") @ExportSerialize.register("Sub", ImplSpec(IOSpec(dtype.any)))
class Sub(ExportNode): class Sub(ExportNodeCpp):
def __init__(self, node): def __init__(self, node, mem_info):
super().__init__(node) super().__init__(node, mem_info)
self.config_template = ""
def export(self, export_folder:Path, list_configs:list): self.forward_template = str(
return list_configs ROOT_EXPORT / "templates/graph_ctor/sub.jinja")
self.include_list = ["aidge/operator/Sub.hpp"]
def forward(self, list_actions:list): self.kernels_to_copy = []
list_actions.append(generate_str(
ROOT_EXPORT / "templates/graph_ctor/sub.jinja",
name=self.name,
inputs=parse_node_input(self.node.inputs()),
**self.attributes
))
return list_actions
from aidge_core.export_utils import ExportLib
from . import ROOT_EXPORT
import aidge_core
class ExportSerialize(ExportLib):
_name="export_serialize"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment