提交 f1cebfef 编写于 作者: J Jacek Czaja

- more fixes

上级 d7652d5f
......@@ -1205,8 +1205,8 @@ std::ostream& operator<<(std::ostream& os, const phi::DenseTensor& t) {
<< "\n";
#ifdef PADDLE_WITH_MKLDNN
os << " - format: "
<< dnnl_fmt_tag2str(static_cast<dnnl_format_tag_t>(t.format())) << "\n";
os << " - memory desc: "
<< (t.mem_desc()) << "\n";
#endif
DenseTensor tensor;
......
......@@ -203,15 +203,15 @@ class MulPrimitiveFactory {
const ExecutionContext &ctx) {
Tensor x_tmp;
Tensor data_matrix;
MKLDNNMemoryFormat src_fmt = data->format();
MKLDNNMemoryFormat dst_fmt;
auto src_mdesc = CreateMemDescriptor<T>(data, src_fmt);
if ((data->dims().size() == 4 &&
src_fmt != (dst_fmt = MKLDNNMemoryFormat::nchw)) ||
(data->dims().size() == 5 &&
src_fmt != (dst_fmt = MKLDNNMemoryFormat::ncdhw))) {
auto dst_mdesc = CreateMemDescriptor<T>(data, dst_fmt);
// This code is enforcing plain (non-blocked) memory arrangement
// in order to flatten (reduce dimensionality) of Tensor later
auto src_mdesc = data->mem_desc();
auto dst_mdesc = data->dims().size() >= 4 ? (data->dims().size() == 5 ?
CreateMemDescriptor(data, MKLDNNMemoryFormat::ncdhw) :
CreateMemDescriptor(data, MKLDNNMemoryFormat::nchw) ) : src_mdesc;
if (src_mdesc != dst_mdesc) {
x_tmp.mutable_data<T>(ctx.GetPlace(), data->memory_size());
Reorder(src_mdesc,
......
......@@ -85,15 +85,13 @@ class ReQuantOpKernel : public framework::OpKernel<T> {
const T* input_data = input->data<T>();
if (reorder_p == nullptr) {
auto dst_tz = phi::vectorize(output->dims());
auto src_dt = framework::ToMKLDNNDataType(
framework::TransToProtoVarType(input->dtype()));
auto dst_dt = with_shift ? framework::MKLDNNDataType::u8 : src_dt;
auto src_md = platform::MKLDNNMemDesc({src_tz}, src_dt, input->format());
src_memory = std::make_shared<dnnl::memory>(
src_md, engine, to_void_cast<T>(input_data));
auto dst_md = platform::MKLDNNMemDesc({dst_tz}, dst_dt, input->format());
input->mem_desc(), engine, to_void_cast<T>(input_data));
auto dst_md = platform::MKLDNNMemDesc({src_tz}, dst_dt, input->mem_desc().strides);
dnnl::primitive_attr attri;
int mask = 0;
......
......@@ -83,7 +83,7 @@ class ReshapeMKLDNNKernel : public framework::OpKernel<T> {
onednn_engine);
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
x->format(), platform::to_void_cast(x->data<T>()));
x->mem_desc(), platform::to_void_cast(x->data<T>()));
out->Resize(x_dims); // to match x numel, format is changed later
// reorder is done into a plain tag to allow usage with blocked formats
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
......@@ -356,7 +356,7 @@ class ReshapeGradMKLDNNKernel : public ReshapeMKLDNNKernel<T, op_name> {
onednn_engine);
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
dout->format(), platform::to_void_cast(dout->data<T>()));
dout->mem_desc(), platform::to_void_cast(dout->data<T>()));
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
dx, this->getPlainFormatTag(dout), ctx.GetPlace());
auto reorder_p = reorder_handler.AcquireReorder(reorder_dst_memory_p,
......
......@@ -161,11 +161,7 @@ class SliceOp : public framework::OperatorWithKernel {
// reorders, because if blocked dimension is not divisible by 8 or
// 16(depending on which blocking format is used) submemory cannot be
// created, so in that scenario a fallback is needed
auto tmp_md = dnnl::memory::desc(
phi::vectorize(ctx.Input<phi::DenseTensor>("Input")->dims()),
dnnl::memory::data_type::f32,
ctx.Input<phi::DenseTensor>("Input")->format());
if (tmp_md.data.format_desc.blocking.inner_nblks == 0)
if (ctx.Input<phi::DenseTensor>("Input")->mem_desc().data.format_desc.blocking.inner_nblks == 0)
return framework::OpKernelType(input_data_type,
ctx.GetPlace(),
framework::DataLayout::kMKLDNN,
......@@ -336,13 +332,7 @@ class SliceOpGrad : public framework::OperatorWithKernel {
// reorders, because if blocked dimension is not divisible by 8 or
// 16(depending on which blocking format is used) submemory cannot be
// created, so in that scenario a fallback is needed
auto tmp_md = dnnl::memory::desc(
phi::vectorize(
ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"))
->dims()),
dnnl::memory::data_type::f32,
ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"))->format());
if (tmp_md.data.format_desc.blocking.inner_nblks == 0)
if (ctx.Input<phi::DenseTensor>(framework::GradVarName("Out"))->mem_desc().data.format_desc.blocking.inner_nblks == 0)
return framework::OpKernelType(input_data_type,
ctx.GetPlace(),
framework::DataLayout::kMKLDNN,
......
......@@ -56,7 +56,6 @@ DenseTensor::DenseTensor(const DenseTensor& other) : meta_(other.meta()) {
inplace_version_counter_ = other.inplace_version_counter_;
#ifdef PADDLE_WITH_MKLDNN
format_ = other.format_;
mem_desc_ = other.mem_desc_;
#endif
}
......@@ -66,7 +65,6 @@ DenseTensor& DenseTensor::operator=(const DenseTensor& other) {
holder_ = other.holder_;
inplace_version_counter_ = other.inplace_version_counter_;
#ifdef PADDLE_WITH_MKLDNN
format_ = other.format_;
mem_desc_ = other.mem_desc_;
#endif
return *this;
......@@ -77,7 +75,6 @@ DenseTensor& DenseTensor::operator=(DenseTensor&& other) {
std::swap(holder_, other.holder_);
std::swap(inplace_version_counter_, other.inplace_version_counter_);
#ifdef PADDLE_WITH_MKLDNN
format_ = other.format_;
mem_desc_ = other.mem_desc_;
#endif
return *this;
......
......@@ -227,16 +227,6 @@ In the final state, we should come up with a MKLDNN_Tensor and move the
following codes there.
*/
#ifdef PADDLE_WITH_MKLDNN
/**
* @brief the detail format of memory block which have layout as kMKLDNN
*
* @note MKLDNN lib support various memory format like nchw, nhwc, nChw8C,
* nChw16c, etc. For a MKLDNN memory block, layout will be set as
* DataLayout::kMKLDNN meanwhile detail memory format will be kept in
* this field.
*/
dnnl::memory::format_tag format_ = dnnl::memory::format_tag::undef;
/// \brief memory descriptor of tensor which have layout set as kMKLDNN
dnnl::memory::desc mem_desc_;
#endif
......
......@@ -365,7 +365,6 @@ DenseTensor& DenseTensor::ShareDataWith(const DenseTensor& src) {
meta_.layout = src.meta_.layout;
meta_.offset = src.meta_.offset;
#ifdef PADDLE_WITH_MKLDNN
format_ = src.format_;
mem_desc_ = src.mem_desc_;
#endif
return *this;
......
......@@ -49,7 +49,7 @@ void SplitKernel(const Context& dev_ctx,
out_vec_dims, offset, reorder_src_memory_p);
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
out[i], out_vec_dims, x.format(), dev_ctx.GetPlace());
out[i], slice_mem_p->get_desc(), dev_ctx.GetPlace());
auto reorder_p =
reorder_handler.AcquireReorder(reorder_dst_memory_p, slice_mem_p);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册