Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions onnxruntime/core/optimizer/conv_activation_fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ bool HasElementDataType(const NodeArg& node_arg, int32_t data_type) {
return data_type == actual_data_type;
}

bool ConvFusionDataTypeCheck(const Node& conv_node) {
// TODO: The CPU and CUDA EP only support float type for the Conv+Activation
// and the Conv+Add+Relu fusions.
// Assess the support level for the other compatible EPs and if they also
// only support float, remove the EP check altogether
const std::string_view node_ep = conv_node.GetExecutionProviderType();
if (node_ep == kCudaExecutionProvider || node_ep == kCpuExecutionProvider) {
if (!HasElementDataType(*conv_node.InputDefs()[0], ONNX_NAMESPACE::TensorProto_DataType_FLOAT)) {
return false;
}
}

return true;
}

class ConvActivation : public NodeSelector {
public:
ConvActivation() = default;
Expand Down Expand Up @@ -74,12 +89,12 @@ class ConvActivation : public NodeSelector {
return false;
};

if (!ConvFusionDataTypeCheck(node)) {
return std::nullopt;
}

// check EP type and activation
if (node_ep == kCudaExecutionProvider) {
if (!HasElementDataType(*node.InputDefs()[0], ONNX_NAMESPACE::TensorProto_DataType_FLOAT)) {
Comment thread
hariharans29 marked this conversation as resolved.
return std::nullopt;
}

if (!graph_utils::IsSupportedOptypeVersionAndDomain(*next_node, "Relu", {6, 13, 14})) {
return std::nullopt;
}
Expand Down Expand Up @@ -112,6 +127,10 @@ class ConvAddRelu : public NodeSelector {
return std::nullopt;
}

if (!ConvFusionDataTypeCheck(node)) {
Comment thread
hariharans29 marked this conversation as resolved.
return std::nullopt;
}

const auto* add_node = GetLoneConsumerNode(graph_viewer, node);
if (!add_node ||
!graph_utils::IsSupportedOptypeVersionAndDomain(*add_node, "Add", {6, 7, 13, 14}) ||
Expand Down