mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-28 20:11:22 +00:00
Merged PR 5918130: Add activation fusions missing in newer opsets
Related work items: #32473540
This commit is contained in:
parent
48fcddd2c5
commit
8cafd2fb2c
3 changed files with 57 additions and 0 deletions
|
|
@ -632,6 +632,12 @@ void RegisterDmlOperators(IMLOperatorRegistry* registry)
|
|||
desc.typeConstraints = typeConstraints.data();
|
||||
desc.typeConstraintCount = static_cast<uint32_t>(typeConstraints.size());
|
||||
|
||||
#if _DEBUG
|
||||
// If some version of the operator is supported for fusion, check that each registered version is also supported.
|
||||
// This ensures that table of operators and versions supporting fusion does not become stale as operator sets are added.
|
||||
FusionHelpers::AssertFusableOperatorSupportsVersionIfExists(desc.name, desc.domain, desc.minimumOperatorSetVersion);
|
||||
#endif
|
||||
|
||||
// edgeDescs will accumulate the edge descriptions across all type constraints.
|
||||
// The values of allowedTypeCount will indicate how many elements of edgeDescs
|
||||
// belong to each type constraint.
|
||||
|
|
|
|||
|
|
@ -143,12 +143,19 @@ namespace Dml
|
|||
static const OperatorInfo c_fusableOps[] =
|
||||
{
|
||||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Conv },
|
||||
OperatorInfo{ "Conv", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_Conv },
|
||||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_ConvTranspose },
|
||||
OperatorInfo{ "ConvTranspose", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_ConvTranspose },
|
||||
OperatorInfo{ "BatchNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_BatchNormalization },
|
||||
OperatorInfo{ "BatchNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_BatchNormalization },
|
||||
OperatorInfo{ "InstanceNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_InstanceNormalization },
|
||||
OperatorInfo{ "MeanVarianceNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_MeanVarianceNormalization },
|
||||
OperatorInfo{ "MeanVarianceNormalization", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_MeanVarianceNormalization },
|
||||
OperatorInfo{ "Gemm", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Gemm },
|
||||
OperatorInfo{ "Gemm", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_Gemm },
|
||||
OperatorInfo{ "Gemm", onnxruntime::kOnnxDomain, OnnxOperatorSet11::sc_sinceVer_Gemm },
|
||||
OperatorInfo{ "MatMul", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_MatMul },
|
||||
OperatorInfo{ "MatMul", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_MatMul },
|
||||
|
||||
// The filter for activation functions maps to what DML's fused op internally fuses at the shader level.
|
||||
OperatorInfo{ "Add", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Add, {"Relu", "LeakyRelu"} },
|
||||
|
|
@ -166,7 +173,9 @@ namespace Dml
|
|||
OperatorInfo{ "Relu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Relu },
|
||||
OperatorInfo{ "LeakyRelu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_LeakyRelu },
|
||||
OperatorInfo{ "PRelu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_PRelu },
|
||||
OperatorInfo{ "PRelu", onnxruntime::kOnnxDomain, OnnxOperatorSet9::sc_sinceVer_PRelu },
|
||||
OperatorInfo{ "ThresholdedRelu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_ThresholdedRelu },
|
||||
OperatorInfo{ "ThresholdedRelu", onnxruntime::kOnnxDomain, OnnxOperatorSet10::sc_sinceVer_ThresholdedRelu },
|
||||
OperatorInfo{ "Elu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Elu },
|
||||
OperatorInfo{ "Selu", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Selu },
|
||||
OperatorInfo{ "Softsign", onnxruntime::kOnnxDomain, OnnxOperatorSet7::sc_sinceVer_Softsign },
|
||||
|
|
@ -330,6 +339,41 @@ namespace Dml
|
|||
return std::string("fused_").append(name);
|
||||
}
|
||||
|
||||
#if _DEBUG
|
||||
// This asserts that an exact match for the operator exists in the tables of fusable ops, if a prior version exists
|
||||
void AssertFusableOperatorSupportsVersionIfExists(
|
||||
std::string_view type,
|
||||
std::string_view domain,
|
||||
int sinceVersion)
|
||||
{
|
||||
for (const OperatorInfo& operatorInfo : c_fusableOps)
|
||||
{
|
||||
if (operatorInfo.type == type && operatorInfo.domain == domain && operatorInfo.sinceVersion < sinceVersion)
|
||||
{
|
||||
assert(std::end(c_fusableOps) != std::find(
|
||||
std::begin(c_fusableOps),
|
||||
std::end(c_fusableOps),
|
||||
OperatorInfo{ type, domain, sinceVersion }));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const OperatorInfo& operatorInfo : c_activationOps)
|
||||
{
|
||||
if (operatorInfo.type == type && operatorInfo.domain == domain && operatorInfo.sinceVersion < sinceVersion)
|
||||
{
|
||||
assert(std::end(c_activationOps) != std::find(
|
||||
std::begin(c_activationOps),
|
||||
std::end(c_activationOps),
|
||||
OperatorInfo{ type, domain, sinceVersion }));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace FusionHelpers
|
||||
|
||||
uint32_t GetDmlAdjustedAxis(int32_t onnxAxis, const MLOperatorKernelCreationContext& kernelCreationContext, uint32_t dmlDimCount)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@ namespace Dml
|
|||
// produce the attribute for Activation in a fused Conv+Activation kernel.
|
||||
std::string GetFusedAttributeName(std::string_view name);
|
||||
|
||||
#if _DEBUG
|
||||
void AssertFusableOperatorSupportsVersionIfExists(
|
||||
std::string_view type,
|
||||
std::string_view domain,
|
||||
int sinceVersion);
|
||||
#endif
|
||||
|
||||
} // namespace FusionHelpers
|
||||
|
||||
// Given an axis in ONNX axis numbering, return the axis adjusted for DML based on how the sizes have been coerced.
|
||||
|
|
|
|||
Loading…
Reference in a new issue