未验证 提交 1ba592d6 编写于 作者: H HongyuJia 提交者: GitHub

opt mkldnn selection judgement (#47217)

上级 ac666538
...@@ -1388,14 +1388,12 @@ bool OperatorWithKernel::SupportsKernelType( ...@@ -1388,14 +1388,12 @@ bool OperatorWithKernel::SupportsKernelType(
#endif #endif
// NOTE(jiahongyu): If MKLDNN can be used, the function SupportsKernelType needs // NOTE(jiahongyu): If MKLDNN can be used, the function SupportsKernelType needs
// to check whether current op supports MKLDNN kernel. There are three // to check whether current op supports MKLDNN kernel. There are two statements
// statements in if condition: The first statement checks whether library_type_ // in if condition:
// are changed by other high priority backends; the second checks whether this // 1. Whether this op has specific implementation;
// op has specific implementation; the third checks whether mkldnn kernel can be // 2. Whether mkldnn kernel can be used.
// used.
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (kernel_type.library_type_ == framework::LibraryType::kPlain && if (!paddle::platform::in_mkldnn_white_list(type_) &&
!paddle::platform::in_mkldnn_white_list(type_) &&
this->CanMKLDNNBeUsed(exe_ctx, kernel_type.data_type_)) { this->CanMKLDNNBeUsed(exe_ctx, kernel_type.data_type_)) {
auto tmp_kernel_type = kernel_type; auto tmp_kernel_type = kernel_type;
tmp_kernel_type.library_type_ = framework::LibraryType::kMKLDNN; tmp_kernel_type.library_type_ = framework::LibraryType::kMKLDNN;
...@@ -1571,13 +1569,11 @@ void OperatorWithKernel::RunImpl(const Scope& scope, ...@@ -1571,13 +1569,11 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
// NOTE(jiahongyu): The registered MKLDNN kernel have library_type = // NOTE(jiahongyu): The registered MKLDNN kernel have library_type =
// LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default // LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default
// values are kPlain, so we need to modify the library_type and data_layout_ // values are kPlain, so we need to modify the library_type and data_layout_
// here. There are three statements in if condition: The first statement checks // here. There are two statements in if condition:
// whether library_type_ are changed by other high priority backends; the second // 1. Whether this op has specific implementation;
// checks whether this op has specific implementation; the third checks whether // 2. Whether mkldnn kernel can be used.
// mkldnn kernel can be used.
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (kernel_type_->library_type_ == framework::LibraryType::kPlain && if (!paddle::platform::in_mkldnn_white_list(type_) &&
!paddle::platform::in_mkldnn_white_list(type_) &&
this->CanMKLDNNBeUsed(exe_ctx, kernel_type_->data_type_)) { this->CanMKLDNNBeUsed(exe_ctx, kernel_type_->data_type_)) {
kernel_type_->library_type_ = framework::LibraryType::kMKLDNN; kernel_type_->library_type_ = framework::LibraryType::kMKLDNN;
kernel_type_->data_layout_ = framework::DataLayout::kMKLDNN; kernel_type_->data_layout_ = framework::DataLayout::kMKLDNN;
...@@ -1814,14 +1810,12 @@ OpKernelType OperatorWithKernel::InnerGetExpectedKernelType( ...@@ -1814,14 +1810,12 @@ OpKernelType OperatorWithKernel::InnerGetExpectedKernelType(
// NOTE(jiahongyu): PADDLE_WITH_MKLDNN codes are moved outside function // NOTE(jiahongyu): PADDLE_WITH_MKLDNN codes are moved outside function
// GetExpectedKernelType, so that if MKLDNN can be used, the library_type_ and // GetExpectedKernelType, so that if MKLDNN can be used, the library_type_ and
// data_layout_ of expected_kernel_key need to be adjusted. There are three // data_layout_ of expected_kernel_key need to be adjusted. There are two
// statements in if condition: The first statement checks whether library_type_ // statements in if condition:
// are changed by other high priority backends; the second checks whether this // 1. Whether this op has specific implementation;
// op has specific implementation; the third checks whether mkldnn kernel can be // 2. Whether mkldnn kernel can be used.
// used.
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (expected_kernel_key.library_type_ == framework::LibraryType::kPlain && if (!paddle::platform::in_mkldnn_white_list(type_) &&
!paddle::platform::in_mkldnn_white_list(type_) &&
this->CanMKLDNNBeUsed(ctx, expected_kernel_key.data_type_)) { this->CanMKLDNNBeUsed(ctx, expected_kernel_key.data_type_)) {
expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN; expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN;
expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN; expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN;
......
...@@ -192,13 +192,11 @@ PreparedOp PrepareImpl( ...@@ -192,13 +192,11 @@ PreparedOp PrepareImpl(
// NOTE(jiahongyu): The registered MKLDNN kernel have library_type = // NOTE(jiahongyu): The registered MKLDNN kernel have library_type =
// LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default // LibraryType::kMKLDNN and data_layout_ = DataLayout::kMKLDNN. But the default
// values are kPlain, so we need to modify the library_type and data_layout_ // values are kPlain, so we need to modify the library_type and data_layout_
// here. There are three statements in if condition: The first statement checks // here. There are two statements in if condition:
// whether library_type_ are changed by other high priority backends; the second // 1. Whether this op has specific implementation;
// checks whether this op has specific implementation; the third checks whether // 2. Whether mkldnn kernel can be used.
// mkldnn kernel can be used.
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (expected_kernel_key.library_type_ == framework::LibraryType::kPlain && if (!paddle::platform::in_mkldnn_white_list(op.Type()) &&
!paddle::platform::in_mkldnn_white_list(op.Type()) &&
op.CanMKLDNNBeUsed(dygraph_exe_ctx, expected_kernel_key.data_type_)) { op.CanMKLDNNBeUsed(dygraph_exe_ctx, expected_kernel_key.data_type_)) {
expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN; expected_kernel_key.library_type_ = framework::LibraryType::kMKLDNN;
expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN; expected_kernel_key.data_layout_ = framework::DataLayout::kMKLDNN;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册