ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseFuseGemmRelu.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
ParseFuseGemmRelu
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
gemmnode
,
10
const
onnx::NodeProto
&
relunode
) -> std::unique_ptr<ROperator> {
11
ETensorType
input_type
=
ETensorType::UNDEFINED
;
12
// check input type - only first input from Gemm
13
auto
input_name
=
gemmnode
.input(0);
14
if
(
parser
.IsRegisteredTensorType(
input_name
)) {
15
input_type
=
parser
.GetTensorType(
input_name
);
16
}
else
{
17
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser MatMul op has input tensor "
+
input_name
+
18
" but its type is not yet registered"
);
19
}
20
21
// we don't check input type of ADD since it is not be registered
22
std::unique_ptr<ROperator>
op
;
23
24
float
attr_alpha
= 1.0;
25
float
attr_beta
= 1.0;
26
int_t
attr_transA
= 0;
27
int_t
attr_transB
= 0;
28
29
for
(
int
i = 0; i <
gemmnode
.attribute_size(); i++) {
30
std::string
attribute_name
=
gemmnode
.attribute(i).name();
31
if
(
attribute_name
==
"alpha"
) {
32
attr_alpha
=
gemmnode
.attribute(i).f();
33
}
else
if
(
attribute_name
==
"beta"
) {
34
attr_beta
=
gemmnode
.attribute(i).f();
35
}
else
if
(
attribute_name
==
"transA"
) {
36
attr_transA
=
gemmnode
.attribute(i).i();
37
if
(
attr_transA
!= 0 &&
attr_transA
!= 1)
38
throw
std::runtime_error(
"TMVA::SOFIE Error - Model Loading - attribute transA in Operator Gemm not 0/1"
);
39
}
else
if
(
attribute_name
==
"transB"
) {
40
attr_transB
=
gemmnode
.attribute(i).i();
41
if
(
attr_transB
!= 0 &&
attr_transB
!= 1)
42
throw
std::runtime_error(
"TMVA::SOFIE Error - Model Loading - attribute transB in Operator Gemm not 0/1"
);
43
}
else
{
44
std::cout <<
"TMVA::SOFIE Warning - Model Loading - Attribute "
<<
attribute_name
<<
" in OperatorNode "
45
<<
gemmnode
.name() <<
" is not defined in ONNX IR and not applied!\n"
;
46
}
47
}
48
switch
(
input_type
) {
49
case
ETensorType::FLOAT
:
50
if
(
gemmnode
.input_size() == 2) {
51
op
.reset(
new
ROperator_Gemm<float>
(
attr_alpha
,
attr_beta
,
attr_transA
,
attr_transB
,
gemmnode
.input(0),
52
gemmnode
.input(1),
relunode
.output(0),
EActivationType::RELU
));
53
}
else
{
54
op
.reset(
new
ROperator_Gemm<float>
(
attr_alpha
,
attr_beta
,
attr_transA
,
attr_transB
,
gemmnode
.input(0),
55
gemmnode
.input(1),
gemmnode
.input(2),
relunode
.output(0),
EActivationType::RELU
));
56
}
57
break
;
58
default
:
59
throw
std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Gemm does not yet support input type "
+
60
std::to_string(
static_cast<
int
>
(
input_type
)));
61
}
62
63
std::string
output_name
=
relunode
.output(0);
64
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
65
parser
.RegisterTensorType(
output_name
,
input_type
);
66
}
67
68
return
op
;
69
};
70
71
}
// namespace SOFIE
72
}
// namespace Experimental
73
}
// 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::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::Experimental::SOFIE::EActivationType::RELU
@ RELU
TMVA::Experimental::SOFIE::ParseFuseGemmRelu
ParserFuseFuncSignature ParseFuseGemmRelu
Definition
ParseFuseGemmRelu.cxx:9
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseFuseGemmRelu.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0