Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] Remove gpu_cpu_reshape2_matmul_fuse_pass in EnableMkldnn #43750

Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion paddle/fluid/inference/api/paddle_pass_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <miopen/miopen.h>
#endif
#include <glog/logging.h>
#include <algorithm>
#include <sstream>

namespace paddle {
Expand Down Expand Up @@ -60,6 +61,12 @@ void PaddlePassBuilder::DeletePass(const std::string &pass_type) {
}
}

size_t PaddlePassBuilder::GetPassIndex(const std::string &pass_type) {
auto iter = std::find(std::begin(passes_), std::end(passes_), pass_type);
if (iter == std::end(passes_)) return -1;
return std::distance(std::begin(passes_), iter);
}

void PaddlePassBuilder::InsertPass(size_t idx, const std::string &pass_type) {
passes_.insert(std::begin(passes_) + idx, pass_type);
}
Expand Down Expand Up @@ -266,7 +273,11 @@ void CpuPassStrategy::EnableMKLDNN() {
#ifdef PADDLE_WITH_MKLDNN
if (!use_mkldnn_) {
passes_.insert(passes_.begin(), "mkldnn_placement_pass");

int id = GetPassIndex("gpu_cpu_reshape2_matmul_fuse_pass");
// this pass slows down FC mkldnn int8 operator
if (id != -1) {
passes_.erase(passes_.begin() + id);
}
for (auto &pass : std::vector<std::string>({
"depthwise_conv_mkldnn_pass", //
"conv_bn_fuse_pass", // Execute BN passes again to
Expand Down
4 changes: 4 additions & 0 deletions paddle/fluid/inference/api/paddle_pass_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class PD_INFER_DECL PaddlePassBuilder {
/// \param[in] pass_type the certain pass type to be deleted.
void DeletePass(const std::string &pass_type);

/// \brief Get the certain position of a pass.
// \param[in] pass_type the type of insert pass.
size_t GetPassIndex(const std::string &pass_type);

/// \brief Delete all the passes.
void ClearPasses();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _optimize_fp32_graph(self, graph):
graph = self._apply_pass(graph, 'multi_gru_seq_fuse_pass')
graph = self._apply_pass(graph, 'seq_concat_fc_fuse_pass')
graph = self._apply_pass(graph, 'gpu_cpu_squeeze2_matmul_fuse_pass')
graph = self._apply_pass(graph, 'gpu_cpu_reshape2_matmul_fuse_pass')
#graph = self._apply_pass(graph, 'gpu_cpu_reshape2_matmul_fuse_pass')
graph = self._apply_pass(graph, 'gpu_cpu_flatten2_matmul_fuse_pass')
graph = self._apply_pass(graph, 'matmul_v2_scale_fuse_pass')
graph = self._apply_pass(graph, 'squared_mat_sub_fuse_pass')
Expand Down