Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_core
Commits
959c1655
Commit
959c1655
authored
11 months ago
by
Olivier BICHLER
Browse files
Options
Downloads
Patches
Plain Diff
Added constantFolding recipe
parent
fbad49a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!105
version 0.2.0
,
!94
Improved scheduling
Pipeline
#41786
passed
11 months ago
Stage: static_analysis
Stage: build
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/aidge/recipes/Recipes.hpp
+2
-0
2 additions, 0 deletions
include/aidge/recipes/Recipes.hpp
src/recipes/ConstantFolding.cpp
+86
-0
86 additions, 0 deletions
src/recipes/ConstantFolding.cpp
with
88 additions
and
0 deletions
include/aidge/recipes/Recipes.hpp
+
2
−
0
View file @
959c1655
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
namespace
Aidge
{
namespace
Aidge
{
void
constantFolding
(
std
::
shared_ptr
<
GraphView
>
graph
);
// FUSE MATMUL + ADD -> FC
// FUSE MATMUL + ADD -> FC
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/recipes/ConstantFolding.cpp
0 → 100644
+
86
−
0
View file @
959c1655
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#include
<cassert>
#include
<memory>
#include
<set>
#include
<string>
#include
"aidge/data/Tensor.hpp"
#include
"aidge/graph/GraphView.hpp"
#include
"aidge/graph/Node.hpp"
#include
"aidge/operator/Producer.hpp"
#include
"aidge/recipes/Recipes.hpp"
#include
"aidge/utils/ErrorHandling.hpp"
#include
"aidge/utils/Types.h"
void
Aidge
::
constantFolding
(
std
::
shared_ptr
<
GraphView
>
graph
)
{
bool
folded
;
do
{
folded
=
false
;
std
::
set
<
std
::
shared_ptr
<
Node
>>
candidates
;
for
(
const
std
::
shared_ptr
<
Node
>&
nodePtr
:
graph
->
getNodes
())
{
if
(
nodePtr
->
type
()
==
Producer_Op
::
Type
)
{
const
auto
&
childs
=
nodePtr
->
getChildren
();
candidates
.
insert
(
childs
.
begin
(),
childs
.
end
());
}
}
for
(
const
auto
&
node
:
candidates
)
{
bool
foldable
=
true
;
auto
replaceGraph
=
std
::
make_shared
<
GraphView
>
();
for
(
const
auto
&
input
:
node
->
inputs
())
{
if
(
input
.
first
)
{
if
(
input
.
first
->
type
()
!=
Producer_Op
::
Type
)
{
foldable
=
false
;
break
;
}
const
auto
&
producer
=
std
::
static_pointer_cast
<
Producer_Op
>
(
input
.
first
->
getOperator
());
if
(
!
producer
->
getAttr
<
bool
>
(
"Constant"
))
{
Log
::
info
(
"Node {} (of type {}) not foldable because Producer input {} not Constant"
,
node
->
name
(),
node
->
type
(),
input
.
first
->
name
());
foldable
=
false
;
break
;
}
replaceGraph
->
add
(
input
.
first
,
false
);
}
}
if
(
foldable
)
{
Log
::
info
(
"Folding node {} (of type {})"
,
node
->
name
(),
node
->
type
());
replaceGraph
->
add
(
node
,
false
);
node
->
forward
();
auto
prodGraph
=
std
::
make_shared
<
GraphView
>
();
const
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
node
->
getOperator
());
for
(
IOIndex_t
output
=
0
;
output
<
node
->
nbOutputs
();
++
output
)
{
const
auto
computedOutput
=
std
::
make_shared
<
Tensor
>
(
op
->
getOutput
(
output
)
->
clone
());
const
auto
newProd
=
Producer
(
computedOutput
,
node
->
name
()
+
"_"
+
std
::
to_string
(
output
),
true
);
// Add output in right order
prodGraph
->
add
(
newProd
);
}
if
(
GraphView
::
replace
(
replaceGraph
,
prodGraph
))
{
folded
=
true
;
}
else
{
Log
::
warn
(
"Error with replace when folding node {} (of type {})"
,
node
->
name
(),
node
->
type
());
}
}
}
}
while
(
folded
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment