ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseFuseMatMulAdd.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Gemm.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuseFuncSignature
ParseFuseMatMulAdd
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
matmulnode
,
10
const
onnx::NodeProto
&
addnode
) {
11
ETensorType
input_type
=
ETensorType::UNDEFINED
;
12
13
// check input tye - only first input from MatMul
14
auto
input_name
=
matmulnode
.input(0);
15
if
(
parser
.IsRegisteredTensorType(
input_name
)) {
16
input_type
=
parser
.GetTensorType(
input_name
);
17
}
else
{
18
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser MatMul op has input tensor "
+
input_name
+
19
" but its type is not yet registered"
);
20
}
21
22
if
(
addnode
.input_size() != 2)
23
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser : cannot fuse MatMul if Add does not have 2 inputs"
);
24
// output of matmul should be one of the input of Add
25
std::string
nameBias
;
26
if
(
matmulnode
.output(0) ==
addnode
.input(0))
27
nameBias
=
addnode
.input(1);
28
else
if
(
matmulnode
.output(0) ==
addnode
.input(1))
29
nameBias
=
addnode
.input(0);
30
else
31
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser : cannot fuse MatMul and Add since have different inputs"
);
32
33
// we don't check input type of ADD since it is not be registered
34
std::unique_ptr<ROperator>
op
;
35
36
float
attr_alpha
= 1.0;
37
float
attr_beta
= 1.0;
38
int_t
attr_transA
= 0;
39
int_t
attr_transB
= 0;
40
41
switch
(
input_type
) {
42
case
ETensorType::FLOAT
:
43
op
.reset(
new
ROperator_Gemm<float>
(
attr_alpha
,
attr_beta
,
attr_transA
,
attr_transB
,
matmulnode
.input(0),
44
matmulnode
.input(1),
nameBias
,
addnode
.output(0)));
45
break
;
46
default
:
47
throw
std::runtime_error(
48
"TMVA::SOFIE - Unsupported - Operator for fusing MatMul and Add to Gemm does not yet support input type "
+
49
std::to_string(
static_cast<
int
>
(
input_type
)));
50
}
51
52
std::string
output_name
=
addnode
.output(0);
53
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
54
parser
.RegisterTensorType(
output_name
,
input_type
);
55
}
56
57
return
op
;
58
};
59
60
}
// namespace SOFIE
61
}
// namespace Experimental
62
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_Gemm.hxx
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:359
ROOT::Detail::TRangeCast
Definition
TCollection.h:312
TMVA::Experimental::SOFIE::RModelParser_ONNX
Definition
RModelParser_ONNX.hxx:30
TMVA::Experimental::SOFIE::onnx::NodeProto
Definition
onnx.hxx:504
TMVA::Experimental::SOFIE::ParserFuseFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &, const onnx::NodeProto &)> ParserFuseFuncSignature
Definition
RModelParser_ONNX.hxx:27
TMVA::Experimental::SOFIE::ParseFuseMatMulAdd
ParserFuseFuncSignature ParseFuseMatMulAdd
Definition
ParseFuseMatMulAdd.cxx:9
TMVA::Experimental::SOFIE::ETensorType
ETensorType
Definition
SOFIE_common.hxx:29
TMVA::Experimental::SOFIE::ETensorType::UNDEFINED
@ UNDEFINED
TMVA::Experimental::SOFIE::ETensorType::FLOAT
@ FLOAT
TMVA::Experimental::SOFIE::int_t
std::int64_t int_t
Definition
SOFIE_common.hxx:56
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseFuseMatMulAdd.cxx
ROOTmaster - Reference Guide Generated on Sun Sep 6 2026 04:47:54 (GVA Time) using Doxygen 1.10.0