Skip to content

Commit 56aba4b

Browse files
add FLAGS_use_mkldnn check (#28147)
1 parent 86887b9 commit 56aba4b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

paddle/fluid/imperative/prepared_operator.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "paddle/fluid/imperative/infer_shape_context.h"
2121
#include "paddle/fluid/imperative/infer_var_type_context.h"
2222

23+
DECLARE_bool(use_mkldnn);
24+
2325
namespace paddle {
2426
namespace imperative {
2527

@@ -91,8 +93,10 @@ PreparedOp PrepareOpImpl(const NameVarMap<VarType>& ins,
9193
// MKLDNN variant of code reads attributes in some of GetKernelTypeForVar and
9294
// GetKernelType functions, so we need to copy the attributes there.
9395
// Const qualifier of Attrs had to be discarded to overwrite it.
94-
auto& mutable_op_attrs = const_cast<framework::AttributeMap&>(op.Attrs());
95-
mutable_op_attrs = attrs;
96+
if (FLAGS_use_mkldnn) {
97+
auto& mutable_op_attrs = const_cast<framework::AttributeMap&>(op.Attrs());
98+
mutable_op_attrs = attrs;
99+
}
96100
#endif
97101
auto expected_kernel_key =
98102
op.GetExpectedKernelType(DygraphExecutionContext<VarType>(

0 commit comments

Comments
 (0)