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
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
Cyril Moineau
aidge_core
Commits
c3b0ad25
Commit
c3b0ad25
authored
1 year ago
by
vincent lorrain
Browse files
Options
Downloads
Patches
Plain Diff
[recipies][GraphRegex] use GraphRegex in fuseMulAdd
parent
61d71c0c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/aidge/utils/Recipies.hpp
+8
-1
8 additions, 1 deletion
include/aidge/utils/Recipies.hpp
src/recipies/FuseMulAdd.cpp
+53
-25
53 additions, 25 deletions
src/recipies/FuseMulAdd.cpp
with
61 additions
and
26 deletions
include/aidge/utils/Recipies.hpp
+
8
−
1
View file @
c3b0ad25
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
#include
"aidge/graph/Node.hpp"
#include
"aidge/graph/Node.hpp"
#include
"aidge/graph/GraphView.hpp"
#include
"aidge/graph/GraphView.hpp"
#include
"aidge/graphRegex/matchFsm/MatchResult.hpp"
namespace
Aidge
{
namespace
Aidge
{
...
@@ -27,7 +29,12 @@ namespace Aidge{
...
@@ -27,7 +29,12 @@ namespace Aidge{
*
*
* @param nodes Strict set of Node to merge.
* @param nodes Strict set of Node to merge.
*/
*/
void
fuseMulAdd
(
std
::
set
<
std
::
shared_ptr
<
Node
>>
nodes
);
//void fuseMulAdd(std::set<std::shared_ptr<Node>> nodes);
void
fuseMulAdd
(
std
::
shared_ptr
<
MatchSolution
>
solution
);
void
fuseMulAdd
(
std
::
shared_ptr
<
Node
>
matmul
,
std
::
shared_ptr
<
Node
>
add
);
/**
/**
* @brief Merge ``MatMul`` and :cpp:function:`Aidge::Add` Node into a :cpp:function:`Aidge::FC` Node.
* @brief Merge ``MatMul`` and :cpp:function:`Aidge::Add` Node into a :cpp:function:`Aidge::FC` Node.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/recipies/FuseMulAdd.cpp
+
53
−
25
View file @
c3b0ad25
...
@@ -25,27 +25,17 @@
...
@@ -25,27 +25,17 @@
// Graph Regex
// Graph Regex
#include
"aidge/graphmatching/GRegex.hpp"
#include
"aidge/graphmatching/GRegex.hpp"
#include
"aidge/graphmatching/NodeRegex.hpp"
#include
"aidge/graphmatching/NodeRegex.hpp"
//Graph Regex
#include
"aidge/graphRegex/GraphRegex.hpp"
using
namespace
Aidge
;
using
namespace
Aidge
;
void
Aidge
::
fuseMulAdd
(
std
::
set
<
std
::
shared_ptr
<
Node
>>
nodes
){
void
Aidge
::
fuseMulAdd
(
std
::
shared_ptr
<
Node
>
matmul
,
std
::
shared_ptr
<
Node
>
add
){
//std::
set<std::shared_ptr<Node>> nodes){
// Fuse Mulmat & Add into FC
// Fuse Mulmat & Add into FC
// Inputs : old nodes (pointers on mul & add)
// Inputs : old nodes (pointers on mul & add)
assert
(
nodes
.
size
()
==
2
&&
"Wrong number of nodes to replace
\n
"
);
assert
((
matmul
->
type
()
==
"MatMul"
&&
add
->
type
()
==
"Add"
)
&&
"Wrong type for the nodes to replace"
);
// Too bad we lose information on the type after matching, how to keep the information after matching (not only for the type) ?
// Step 0 : Assert the nodes types are correct to be fused
std
::
shared_ptr
<
Node
>
add
;
std
::
shared_ptr
<
Node
>
matmul
;
for
(
const
auto
&
element
:
nodes
)
{
assert
((
element
->
type
()
==
"MatMul"
||
element
->
type
()
==
"Add"
)
&&
"Wrong type for the nodes to replace"
);
if
(
element
->
type
()
==
"MatMul"
){
matmul
=
element
;
}
else
if
(
element
->
type
()
==
"Add"
)
{
add
=
element
;
}
}
// Step 1 : Create FC
// Step 1 : Create FC
// Fetch the output dimension throught the bias size
// Fetch the output dimension throught the bias size
...
@@ -78,17 +68,55 @@ void Aidge::fuseMulAdd(std::set<std::shared_ptr<Node>> nodes){
...
@@ -78,17 +68,55 @@ void Aidge::fuseMulAdd(std::set<std::shared_ptr<Node>> nodes){
}
}
void
Aidge
::
fuseMulAdd
(
std
::
shared_ptr
<
MatchSolution
>
solution
){
assert
(
solution
->
at
(
"MatMul"
).
size
()
==
1
&&
"Wrong number of nodes MatMul to replace
\n
"
);
assert
(
solution
->
at
(
"Add"
).
size
()
==
1
&&
"Wrong number of nodes Add to replace
\n
"
);
for
(
const
auto
&
matmul
:
solution
->
at
(
"MatMul"
))
{
for
(
const
auto
&
add
:
solution
->
at
(
"Add"
))
{
fuseMulAdd
(
matmul
,
add
);
}
}
}
void
Aidge
::
fuseMulAdd
(
std
::
shared_ptr
<
GraphView
>
graphView
){
void
Aidge
::
fuseMulAdd
(
std
::
shared_ptr
<
GraphView
>
graphView
){
std
::
map
<
std
::
string
,
NodeRegex
*>
nodesRegex
;
// std::map<std::string,NodeRegex*> nodesRegex ;
nodesRegex
[
"MatMul"
]
=
new
NodeRegex
(
"MatMul"
);
// nodesRegex["MatMul"] = new NodeRegex("MatMul");
nodesRegex
[
"Add"
]
=
new
NodeRegex
(
"Add"
);
// nodesRegex["Add"] = new NodeRegex("Add");
std
::
vector
<
std
::
string
>
seqRegex
;
seqRegex
.
push_back
(
"MatMul -> Add;"
);
std
::
shared_ptr
<
GraphRegex
>
regex
=
std
::
make_shared
<
GraphRegex
>
();
GRegex
GReg
(
nodesRegex
,
seqRegex
);
regex
->
setNodeKey
(
"Add"
,
"getType($) =='Add'"
);
Match
matches
=
GReg
.
match
(
graphView
);
regex
->
setNodeKey
(
"MatMul"
,
"getType($) =='MatMul'"
);
std
::
vector
<
std
::
set
<
std
::
shared_ptr
<
Node
>>>
matchNodes
=
matches
.
getMatchNodes
();
regex
->
addQuery
(
"MatMul -> Add ;"
);
for
(
size_t
i
=
0
;
i
<
matches
.
getNbMatch
();
++
i
)
{
fuseMulAdd
(
matchNodes
[
i
]);
for
(
const
auto
&
solution
:
regex
->
match
(
graphView
))
{
fuseMulAdd
(
solution
);
// // solution->at("MatMul");
// // solution->at("Add");
// assert(solution->at("MatMul").size() == 1 && "Wrong number of nodes MatMul to replace\n");
// assert(solution->at("Add").size() == 1 && "Wrong number of nodes Add to replace\n");
// for (const auto& matmul : solution->at("MatMul")) {
// for (const auto& add : solution->at("Add")) {
// fuseMulAdd(matmul,add);
// }
// }
}
}
// std::vector<std::string> seqRegex;
// seqRegex.push_back("MatMul -> Add;");
// GRegex GReg(nodesRegex, seqRegex);
// Match matches = GReg.match(graphView);
// std::vector<std::set<std::shared_ptr<Node>>> matchNodes = matches.getMatchNodes();
// for (size_t i = 0; i < matches.getNbMatch(); ++i) {
// fuseMulAdd(matchNodes[i]);
// }
}
}
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