diff --git a/paddle/fluid/framework/data_layout_transform.h b/paddle/fluid/framework/data_layout_transform.h index fb4e97900fadae0514bb84679871914633700b6a..90bb206ec6b698bc23ad1a5c9609a25186ec6de8 100644 --- a/paddle/fluid/framework/data_layout_transform.h +++ b/paddle/fluid/framework/data_layout_transform.h @@ -62,18 +62,6 @@ inline MKLDNNDataType ToMKLDNNDataType(const std::type_index type) { return MKLDNNDataType::data_undef; } -inline std::type_index MKLDNNToTypeIndex(const MKLDNNDataType data_type) { - static const std::map dict{ - {MKLDNNDataType::f32, std::type_index(typeid(float))}, // NOLINT - {MKLDNNDataType::s8, std::type_index(typeid(char))}, // NOLINT - {MKLDNNDataType::u8, std::type_index(typeid(unsigned char))}, - {MKLDNNDataType::s16, std::type_index(typeid(int16_t))}, - {MKLDNNDataType::s32, std::type_index(typeid(int32_t))}}; - auto iter = dict.find(data_type); - if (iter != dict.end()) return iter->second; - return std::type_index(typeid(float)); -} - #endif void TransDataLayoutFromMKLDNN(const OpKernelType& kernel_type_for_var, diff --git a/paddle/fluid/framework/tensor.h b/paddle/fluid/framework/tensor.h index 4285f7f05689bca234d54e336e2d94b8869fcfd4..f1d268548578fea12082e2edb213a3749eccbfaf 100644 --- a/paddle/fluid/framework/tensor.h +++ b/paddle/fluid/framework/tensor.h @@ -39,15 +39,9 @@ class Tensor { public: inline mkldnn::memory::format format() const { return format_; } - inline mkldnn::memory::data_type data_type() const { return data_type_; } - inline void set_format(const mkldnn::memory::format format) { format_ = format; } - - inline void set_data_type(const mkldnn::memory::data_type data_type) { - data_type_ = data_type; - } protected: /** @@ -60,8 +54,6 @@ class Tensor { */ mkldnn::memory::format format_ = mkldnn::memory::format::format_undef; - - mkldnn::memory::data_type data_type_ = mkldnn::memory::data_type::f32; #endif public: diff --git a/paddle/fluid/operators/conv_mkldnn_op.cc b/paddle/fluid/operators/conv_mkldnn_op.cc index 4b0edb11276b1af1216428c177b62c8238ea62e0..bd9376bd6cb9c5c1584215101fd46e387d862b54 100644 --- a/paddle/fluid/operators/conv_mkldnn_op.cc +++ b/paddle/fluid/operators/conv_mkldnn_op.cc @@ -14,7 +14,6 @@ #include "paddle/fluid/operators/conv_op.h" #include "paddle/fluid/platform/mkldnn_helper.h" -#include "paddle/fluid/framework/data_layout_transform.h" namespace paddle { namespace operators { @@ -322,7 +321,6 @@ std::cout<<"this is conv kernel op....................."<("fuse_relu"); bool fuse_residual_conn = ctx.Attr("fuse_residual_connection"); int groups = ctx.Attr("groups"); - std::cout<<"fuse_relu = "<(), chosen_memory_format); - //memory::data_type dst_dt = memory::data_type::f32; - //auto dst_dt = std::type_index(typeid(float)); if(is_INT8){ src_md = platform::MKLDNNMemDesc( src_tz, memory::data_type::u8, chosen_memory_format); weights_md = platform::MKLDNNMemDesc( weights_tz, memory::data_type::s8, (g == 1) ? chosen_memory_format : mkldnn::memory::format::goihw); - //dst_dt = fuse_relu?memory::data_type::u8:memory::data_type::s8; - //dst_dt = fuse_relu? std::type_index(typeid(unsigned char)) : std::type_index(typeid(char)); dst_md = platform::MKLDNNMemDesc( dst_tz, - fuse_relu? paddle::framework::ToMKLDNNDataType(std::type_index(typeid(unsigned char))) : - paddle::framework::ToMKLDNNDataType(std::type_index(typeid(char))), + fuse_relu?memory::data_type::u8:memory::data_type::s8, chosen_memory_format); } @@ -509,7 +502,7 @@ std::cout<<"log3....."< dst_memory_p; if(is_INT8){ - //T* output_data = nullptr; + int8_t* output_data = nullptr; if (fuse_residual_conn) { auto residual_param = ctx.Input("ResidualData"); PADDLE_ENFORCE_EQ(output->dims(), residual_param->dims(), @@ -517,28 +510,15 @@ std::cout<<"log3....."<ShareDataWith(*residual_param); - if(fuse_relu){ - uint8_t* output_data = output->mutable_data(ctx.GetPlace()); - dst_memory_p = - handler.AcquireDstMemoryFromPrimitive(to_void_cast(output_data)); - } else{ - int8_t* output_data = output->mutable_data(ctx.GetPlace()); - dst_memory_p = - handler.AcquireDstMemoryFromPrimitive(to_void_cast(output_data)); - } + output_data = output->mutable_data(ctx.GetPlace()); } else { std::cout<<"conv log 1 ....................."<mutable_data(ctx.GetPlace(), handler.GetDstMemorySize()); - dst_memory_p = - handler.AcquireDstMemoryFromPrimitive(to_void_cast(output_data)); - } else{ - int8_t* output_data = output->mutable_data(ctx.GetPlace(), handler.GetDstMemorySize()); - dst_memory_p = - handler.AcquireDstMemoryFromPrimitive(to_void_cast(output_data)); - } + output_data = + output->mutable_data(ctx.GetPlace(), handler.GetDstMemorySize()); std::cout<<"conv log 2 //////////////////////"<(output_data)); std::cout<<"input fmt = "<format()<<" output fmt = "<format()<<" dst fmt = "<get_primitive_desc().desc().data.format<data(); - float* output_data = output->mutable_data(ctx.GetPlace()); + T* output_data = output->mutable_data(ctx.GetPlace()); //T scale_data = *(scale->data()); - std::vector scale_data = {*(scale->data())}; + std::vector scale_data = {*(scale->data())}; std::vector pipeline; std::vector src_tz = paddle::framework::vectorize2int(input->dims()); @@ -69,7 +69,7 @@ std::cout<<"this is dequant op ***********"<(output_data)); + auto dst_memory = mkldnn::memory(dst_pd, to_void_cast(output_data)); auto reorder_pd = std::shared_ptr( new reorder::primitive_desc(dst_pd, src_pd, attri)); @@ -112,5 +112,5 @@ namespace ops = paddle::operators; REGISTER_OPERATOR(dequantize, ops::DeQuantOp, ops::DeQuantOpMaker, paddle::framework::DefaultGradOpDescMaker); -REGISTER_OP_KERNEL(dequantize, MKLDNN, ::paddle::platform::CPUPlace, ops::DeQuantOpKernel); +REGISTER_OP_KERNEL(dequantize, MKLDNN, ::paddle::platform::CPUPlace, ops::DeQuantOpKernel); diff --git a/paddle/fluid/operators/pool_mkldnn_op.cc b/paddle/fluid/operators/pool_mkldnn_op.cc index fd27b42a7fac71f75aadbc50f4293506b2c63a2c..56cef91e29cc7da27384c27a7ec63e90cfadfc3b 100644 --- a/paddle/fluid/operators/pool_mkldnn_op.cc +++ b/paddle/fluid/operators/pool_mkldnn_op.cc @@ -14,7 +14,6 @@ limitations under the License. */ #include "paddle/fluid/operators/pool_op.h" #include "paddle/fluid/platform/mkldnn_helper.h" -#include "paddle/fluid/framework/data_layout_transform.h" namespace paddle { namespace operators { @@ -72,7 +71,7 @@ class PoolMKLDNNOpKernel : public paddle::framework::OpKernel { void Compute(const paddle::framework::ExecutionContext& ctx) const override { PADDLE_ENFORCE(paddle::platform::is_cpu_place(ctx.GetPlace()), "It must use CPUPlace."); -std::cout<<"this is pool op"<(); const auto& mkldnn_engine = dev_ctx.GetEngine(); @@ -130,16 +129,14 @@ std::cout<<"this is pool op"<type()); - std::cout<<"input type = "<(), input_format); /* create memory descriptor for pooling without specified format * ('any') which lets a primitive (pooling in this case) choose * the memory format preferred for best performance */ - auto dst_md = platform::MKLDNNMemDesc(dst_tz, dt, + auto dst_md = platform::MKLDNNMemDesc(dst_tz, mkldnn::memory::f32, mkldnn::memory::format::any); std::shared_ptr pool_pd = @@ -402,9 +399,6 @@ class PoolMKLDNNGradOpKernel : public paddle::framework::OpKernel { namespace ops = paddle::operators; REGISTER_OP_KERNEL(pool2d, MKLDNN, ::paddle::platform::CPUPlace, - ops::PoolMKLDNNOpKernel, - ops::PoolMKLDNNOpKernel, - ops::PoolMKLDNNOpKernel); - + ops::PoolMKLDNNOpKernel); REGISTER_OP_KERNEL(pool2d_grad, MKLDNN, ::paddle::platform::CPUPlace, ops::PoolMKLDNNGradOpKernel);