Skip to content

Commit

Permalink
WIP: Generic Reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
antonvor committed Oct 12, 2023
1 parent 749ed9d commit 5dcc4f7
Show file tree
Hide file tree
Showing 12 changed files with 675 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/plugins/intel_cpu/src/dnnl_extension_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ uint8_t DnnlExtensionUtils::sizeOfDataType(dnnl::memory::data_type dataType) {
return 2;
case dnnl::memory::data_type::undef:
return 0;
// todo:
case dnnl::memory::data_type::f64:
return 8;
default:
IE_THROW() << "Unsupported data type.";
}
Expand All @@ -60,6 +63,8 @@ memory::data_type DnnlExtensionUtils::IEPrecisionToDataType(const InferenceEngin
return memory::data_type::f16;
case InferenceEngine::Precision::UNSPECIFIED:
return memory::data_type::undef;
case InferenceEngine::Precision::FP64:
return memory::data_type::f64;
default: {
IE_THROW() << "The plugin does not support " << prec.name();
}
Expand All @@ -84,6 +89,9 @@ InferenceEngine::Precision DnnlExtensionUtils::DataTypeToIEPrecision(memory::dat
return InferenceEngine::Precision::FP16;
case memory::data_type::undef:
return InferenceEngine::Precision::UNSPECIFIED;
// todo: needed for graph dumping, remove later
case memory::data_type::f64:
return InferenceEngine::Precision::FP64;
default: {
IE_THROW() << "Unsupported data type.";
}
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/intel_cpu/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ void Graph::InitDescriptors() {
DEBUG_LOG("Init supported primitive descriptors for node: ", node->getName());
node->initSupportedPrimitiveDescriptors();

OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, node->profiling.filterSupportedPrimitiveDescriptors);
DEBUG_LOG("Filter supported primitive descriptors for node: ", node->getName());
node->filterSupportedPrimitiveDescriptors();
// OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, node->profiling.filterSupportedPrimitiveDescriptors);
// DEBUG_LOG("Filter supported primitive descriptors for node: ", node->getName());
// node->filterSupportedPrimitiveDescriptors();

#ifdef CPU_DEBUG_CAPS
const auto& SPDs = node->getSupportedPrimitiveDescriptors();
Expand Down Expand Up @@ -599,6 +599,11 @@ void Graph::InitEdges() {
auto reorderStatus = graphEdges[i]->needReorder();
DEBUG_LOG(graphEdges[i]->name(), " reorderStatus = ", reorderStatus);
if (reorderStatus == Edge::ReorderStatus::Regular) {
if (edge->getParent()->getName() == "TRANSPOSE_1") {
insertReorder(edge, false);
updateEdge(i);
continue;
}
Edge::ReorderStatus reorderStatusInternal = Edge::ReorderStatus::Regular;
// Check if there is a reorder that needs the precision conversion
if (edge->getInputDesc().getPrecision() != edge->getOutputDesc().getPrecision() &&
Expand Down
25 changes: 23 additions & 2 deletions src/plugins/intel_cpu/src/graph_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ void GraphOptimizer::ApplyCommonGraphOptimizations(Graph &graph) {
FuseFCAndTransposeOnWeights(graph);
graph.RemoveDroppedNodes();

OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "RemoveConvert");
RemoveConvert(graph);
graph.RemoveDroppedNodes();

OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "FuseDeconvolutionAndSimpleOperation");
FuseDeconvolutionAndSimpleOperation(graph);
graph.RemoveDroppedNodes();
Expand Down Expand Up @@ -193,8 +197,8 @@ void GraphOptimizer::ApplyImplSpecificGraphOptimizations(Graph &graph) {
DropDoubleReorders(graph);
graph.RemoveDroppedNodes();

MergeTransposeAndReorder(graph);
graph.RemoveDroppedNodes();
// MergeTransposeAndReorder(graph);
// graph.RemoveDroppedNodes();

graph.RemoveDroppedEdges();
}
Expand Down Expand Up @@ -848,6 +852,23 @@ void GraphOptimizer::FuseFCAndConvertOnWeights(Graph& graph) {
}
}

void GraphOptimizer::RemoveConvert(Graph& graph) {
auto& graphNodes = graph.GetNodes();

auto isSuitablePattern = [](NodePtr parent) {
bool res = true && parent->getType() == Type::Convert
&& parent->getParentEdgeAt(0)->getParent()->getName() == "TRANSPOSE_1";
return res;
};

for (auto parent : graphNodes) {
if (isSuitablePattern(parent)) {
CPU_GRAPH_OPTIMIZER_SCOPE(RemoveConvert);
graph.DropNode(parent);
}
}
}

void GraphOptimizer::FuseFCAndTransposeOnWeights(Graph& graph) {
// This optimization allows us to avoid transposing the weights in Transpose node and do it directly along with reordering in FC node
auto& graphNodes = graph.GetNodes();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/src/graph_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class GraphOptimizer {
void FuseMultiplyAndAdd(Graph &graph);
void MergeConvertAndScaleShift(Graph& graph);
void FuseFCAndConvertOnWeights(Graph& graph);
void RemoveConvert(Graph &graph);
void FuseFCAndTransposeOnWeights(Graph& graph);
void FuseFullyConnectedAndSimpleOperation(Graph &graph);
void FuseMatMulAndSimpleOperation(Graph &graph);
Expand Down
Loading

0 comments on commit 5dcc4f7

Please sign in to comment.