Skip to content

Commit effec86

Browse files
authored
Merge pull request #15913 from liangan1/func_coverage
Enable function coverage for U8/S8 ConvMKLDNNOpKernel
2 parents 15de2df + 4acc522 commit effec86

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

cmake/operators.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ function(op_library TARGET)
168168
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(relu, MKLDNN);\n")
169169
elseif(${MKLDNN_FILE} STREQUAL "conv_mkldnn_op")
170170
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN, FP32);\n")
171+
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN, S8);\n")
172+
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN, U8);\n")
173+
171174
else()
172175
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(${TARGET}, MKLDNN);\n")
173176
endif()

paddle/fluid/framework/op_registry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ struct OpKernelRegistrarFunctorEx<PlaceType, false, I,
290290
"USE_OP_DEVICE_KERNEL must be in global namespace"); \
291291
extern int \
292292
TouchOpKernelRegistrar_##op_type##_##LIBRARY_TYPE##_##customized_name(); \
293-
UNUSED static int use_op_kernel_##op_type##_##LIBRARY_TYPE##_##DEFAULT_TYPE##_ = /* NOLINT */ \
293+
UNUSED static int use_op_kernel_##op_type##_##LIBRARY_TYPE##_##customized_name##_ = /* NOLINT */ \
294294
TouchOpKernelRegistrar_##op_type##_##LIBRARY_TYPE##_##customized_name()
295295

296296
#define USE_OP_DEVICE_KERNEL(op_type, LIBRARY_TYPE) \

paddle/fluid/operators/conv_op.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ framework::OpKernelType ConvOp::GetExpectedKernelType(
8181
framework::OpKernelType::kDefaultCustomizedTypeValue;
8282
framework::LibraryType library{framework::LibraryType::kPlain};
8383
// TODO(pzelazko-intel): enable MKLDNN layout when it's ready
84+
auto input_data_type = ctx.Input<Tensor>("Input")->type();
8485
std::string data_format = ctx.Attr<std::string>("data_format");
8586
framework::DataLayout layout = framework::StringToDataLayout(data_format);
8687

@@ -94,11 +95,14 @@ framework::OpKernelType ConvOp::GetExpectedKernelType(
9495
platform::CanMKLDNNBeUsed(ctx)) {
9596
library = framework::LibraryType::kMKLDNN;
9697
layout = framework::DataLayout::kMKLDNN;
97-
customized_type_value = kConvMKLDNNFP32;
98+
customized_type_value =
99+
(input_data_type == framework::DataTypeTrait<int8_t>::DataType ||
100+
input_data_type == framework::DataTypeTrait<uint8_t>::DataType)
101+
? kConvMKLDNNINT8
102+
: kConvMKLDNNFP32;
98103
}
99104
#endif
100105

101-
auto input_data_type = ctx.Input<Tensor>("Input")->type();
102106
if (input_data_type != framework::proto::VarType::INT8 &&
103107
input_data_type != framework::proto::VarType::UINT8) {
104108
auto filter_data_type = ctx.Input<Tensor>("Filter")->type();

paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,12 @@ REGISTER_OP_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN,
991991

992992
REGISTER_OP_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN,
993993
::paddle::platform::CPUPlace, U8,
994-
ops::kConvMKLDNNFP32,
994+
ops::kConvMKLDNNINT8,
995995
ops::ConvMKLDNNOpKernel<uint8_t, float>);
996996

997997
REGISTER_OP_KERNEL_WITH_CUSTOM_TYPE(conv2d, MKLDNN,
998998
::paddle::platform::CPUPlace, S8,
999-
ops::kConvMKLDNNFP32,
999+
ops::kConvMKLDNNINT8,
10001000
ops::ConvMKLDNNOpKernel<int8_t, float>);
10011001

10021002
REGISTER_OP_KERNEL_WITH_CUSTOM_TYPE(conv2d_grad, MKLDNN,

0 commit comments

Comments
 (0)