Skip to content

Commit e4c2a85

Browse files
authored
[oneDNN] Disable caching of Reorder operation (PaddlePaddle#35664)
* - REorder disabling caching * - compilation fix * - another compilation fix * - another compilation fix * - compilation fix * - Fix * - yet another compilation fix * - suppresingly another compilation fix * - lint * - fix after review * - fix
1 parent d411a03 commit e4c2a85

File tree

13 files changed

+54
-152
lines changed

13 files changed

+54
-152
lines changed

log

2.75 KB
Binary file not shown.

paddle/fluid/framework/data_layout_transform.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ void innerTransDataLayoutFromMKLDNN(DataLayout in_layout, DataLayout out_layout,
179179

180180
if ((in_format != out_format) || always_copy) {
181181
void* in_data = GetDataFromTensor(in, in_type);
182-
std::string key =
183-
platform::CreateKey(*dev_ctx, in_tz, in_format, out_format, in_type);
184182

185-
platform::ReorderMKLDNNHandler handler(in_tz, in.type(), in_type, *dev_ctx,
186-
cpu_engine, key);
183+
platform::ReorderMKLDNNHandler handler(in_tz, in.type(), in_type,
184+
cpu_engine);
187185

188186
auto reorder_src_memory_p = handler.AcquireSrcMemory(in_format, in_data);
189187
auto reorder_dst_memory_p =

paddle/fluid/operators/elementwise/mkldnn/elementwise_add_mkldnn_op.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ class EltwiseAddMKLDNNGradKernel : public ElemwiseGradKernel<T> {
4343

4444
auto tz = paddle::framework::vectorize<int64_t>(dout->dims());
4545
memory::data_type dout_type = framework::ToMKLDNNDataType(dout->type());
46-
std::string key = platform::CreateKey(dev_ctx, tz, dout->format(),
47-
dout->format(), dout_type);
48-
platform::ReorderMKLDNNHandler handler(tz, dout->type(), dout_type, dev_ctx,
49-
onednn_engine, key);
46+
platform::ReorderMKLDNNHandler handler(tz, dout->type(), dout_type,
47+
onednn_engine);
5048

5149
auto& astream = platform::MKLDNNDeviceContext::tls().get_stream();
5250
auto reorder_src_memory_p = handler.AcquireSrcMemory(

paddle/fluid/operators/mkldnn/cast_mkldnn_op.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ class CastMKLDNNKernel : public framework::OpKernel<T> {
4343

4444
auto x_tz = framework::vectorize(x->dims());
4545

46-
std::string key =
47-
platform::CreateKey(dev_ctx, x_tz, x->format(), x->format(), x_type);
48-
platform::ReorderMKLDNNHandler reorder_handler(
49-
x_tz, x_paddle_type, x_type, out_paddle_type, out_type, dev_ctx,
50-
dev_ctx.GetEngine(), key);
46+
platform::ReorderMKLDNNHandler reorder_handler(x_tz, x_paddle_type, x_type,
47+
out_paddle_type, out_type,
48+
dev_ctx.GetEngine());
5149

5250
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
5351
x->format(), platform::to_void_cast(x->data<T>()));

paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,8 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
11251125
mkldnn::memory::format_tag out_format =
11261126
weights_tz.size() == 6 ? mkldnn::memory::format_tag::goidhw
11271127
: mkldnn::memory::format_tag::goihw;
1128-
std::string key = platform::CreateKey(dev_ctx, weights_tz, filter_fmt,
1129-
out_format, in_type);
1130-
key = platform::ExtendKeyWithThreadInfoIfNeeded(dev_ctx, key);
1131-
1132-
platform::ReorderMKLDNNHandler handler(
1133-
weights_tz, filter->type(), in_type, dev_ctx, mkldnn_engine, key);
1128+
platform::ReorderMKLDNNHandler handler(weights_tz, filter->type(),
1129+
in_type, mkldnn_engine);
11341130
auto reorder_dst_memory_p =
11351131
handler.AcquireDstMemory(filter_grad, out_format, ctx.GetPlace());
11361132

paddle/fluid/operators/mkldnn/expand_v2_mkldnn_op.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ class ExpandGradMKLDNNKernel : public paddle::framework::OpKernel<T> {
114114
if (dout_vec_dims == dx_vec_dims) {
115115
mkldnn::memory::data_type dout_type =
116116
paddle::framework::ToMKLDNNDataType(dout->type());
117-
std::string key = paddle::platform::CreateKey(
118-
dev_ctx, dout_vec_dims, dout->format(), dout->format(), dout_type);
119117
paddle::platform::ReorderMKLDNNHandler reorder_handler(
120-
dout_vec_dims, dout->type(), dout_type, dev_ctx, onednn_engine, key);
118+
dout_vec_dims, dout->type(), dout_type, onednn_engine);
121119

122120
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
123121
dout->format(), paddle::platform::to_void_cast(dout->data<T>()));

paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ static Tensor FoldFirstAndLastDims(const MKLDNNDeviceContext& dev_ctx,
5858

5959
memory::data_type input_type =
6060
paddle::framework::ToMKLDNNDataType(input->type());
61-
std::string key = paddle::platform::CreateKey(
62-
dev_ctx, input_dims, input->format(), input->format(), input_type);
6361
paddle::platform::ReorderMKLDNNHandler reorder_handler(
64-
output_dims, input->type(), input_type, dev_ctx, dev_ctx.GetEngine(),
65-
key);
62+
output_dims, input->type(), input_type, dev_ctx.GetEngine());
6663

6764
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
6865
memory::format_tag::abc,

paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ class ReshapeMKLDNNKernel : public framework::OpKernel<T> {
9393
}
9494

9595
mkldnn::memory::data_type x_type = framework::ToMKLDNNDataType(x->type());
96-
std::string key =
97-
platform::CreateKey(dev_ctx, x_vec_dims, x->format(), x_type);
98-
platform::ReorderMKLDNNHandler reorder_handler(
99-
x_vec_dims, x->type(), x_type, dev_ctx, onednn_engine, key);
96+
platform::ReorderMKLDNNHandler reorder_handler(x_vec_dims, x->type(),
97+
x_type, onednn_engine);
10098

10199
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
102100
x->format(), platform::to_void_cast(x->data<T>()));
@@ -253,11 +251,8 @@ class ReshapeGradMKLDNNKernel : public ReshapeMKLDNNKernel<T> {
253251

254252
mkldnn::memory::data_type dout_type =
255253
framework::ToMKLDNNDataType(dout->type());
256-
std::string key =
257-
platform::CreateKey(dev_ctx, dout_vec_dims, this->getPlainFormatTag(dx),
258-
dx->format(), dout_type);
259-
platform::ReorderMKLDNNHandler reorder_handler(
260-
dout_vec_dims, dout->type(), dout_type, dev_ctx, onednn_engine, key);
254+
platform::ReorderMKLDNNHandler reorder_handler(dout_vec_dims, dout->type(),
255+
dout_type, onednn_engine);
261256

262257
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
263258
dout->format(), platform::to_void_cast(dout->data<T>()));

paddle/fluid/operators/mkldnn/slice_mkldnn_op.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,16 @@ class SliceMKLDNNKernel : public framework::OpKernel<T> {
9898
out->Resize(framework::make_ddim(slice_dims));
9999

100100
mkldnn::memory::data_type x_type = framework::ToMKLDNNDataType(x->type());
101-
auto key = platform::CreateKey(dev_ctx, x_vec_dims, axes, starts, ends,
102-
x->format(), x_type);
103101

104-
platform::ReorderMKLDNNHandler reorder_handler(
105-
x_vec_dims, x->type(), x_type, dev_ctx, onednn_engine, key);
102+
platform::ReorderMKLDNNHandler reorder_handler(x_vec_dims, x->type(),
103+
x_type, onednn_engine);
106104

107105
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
108106
x->format(), platform::to_void_cast(x->data<T>()));
109107
auto slice_mem_p = reorder_handler.AcquireSubmemory(slice_dims, offsets,
110108
reorder_src_memory_p);
111109
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
112-
out, slice_dims, 0, get_plain_format_tag(x), ctx.GetPlace());
110+
out, slice_dims, get_plain_format_tag(x), ctx.GetPlace());
113111

114112
auto reorder_p =
115113
reorder_handler.AcquireReorder(reorder_dst_memory_p, slice_mem_p);
@@ -201,16 +199,13 @@ class SliceGradMKLDNNKernel : public framework::OpKernel<T> {
201199
mkldnn::memory::format_tag reorder_format_tag =
202200
platform::GetMKLDNNFormat(md.reshape(slice_dims));
203201

204-
auto key = platform::CreateKey(dev_ctx, dout_vec_dims, axes, starts, ends,
205-
reorder_format_tag, dout_type);
206-
207-
platform::ReorderMKLDNNHandler reorder_handler(
208-
slice_dims, dout->type(), dout_type, dev_ctx, onednn_engine, key);
202+
platform::ReorderMKLDNNHandler reorder_handler(slice_dims, dout->type(),
203+
dout_type, onednn_engine);
209204

210205
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
211206
reorder_format_tag, platform::to_void_cast(dout->data<T>()));
212207
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
213-
dx, dx_vec_dims, 0, reorder_format_tag, ctx.GetPlace());
208+
dx, dx_vec_dims, reorder_format_tag, ctx.GetPlace());
214209
memset(dx->data<T>(), 0, reorder_dst_memory_p->get_desc().get_size());
215210

216211
auto slice_mem_p = reorder_handler.AcquireSubmemory(slice_dims, offsets,

paddle/fluid/operators/mkldnn/split_mkldnn_op.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,25 @@ class SplitMKLDNNKernel : public framework::OpKernel<T> {
9191
auto x_vec_dims = framework::vectorize(x_dims);
9292

9393
mkldnn::memory::data_type x_type = framework::ToMKLDNNDataType(x->type());
94-
auto key = platform::CreateKey(dev_ctx, x_vec_dims, axis, num, sections,
95-
x->format(), x_type);
9694

9795
auto& astream = platform::MKLDNNDeviceContext::tls().get_stream();
9896

9997
std::vector<int64_t> offset(x_vec_dims.size(), 0);
10098

101-
platform::ReorderMKLDNNHandler reorder_handler(
102-
x_vec_dims, x->type(), x_type, dev_ctx, onednn_engine, key);
99+
platform::ReorderMKLDNNHandler reorder_handler(x_vec_dims, x->type(),
100+
x_type, onednn_engine);
103101
auto reorder_src_memory_p = reorder_handler.AcquireSrcMemory(
104102
x->format(), platform::to_void_cast(x->data<T>()));
105103

106104
for (size_t i = 0; i < outs_number; ++i) {
107105
auto out_vec_dims = framework::vectorize(outs[i]->dims());
108-
auto slice_mem_p = reorder_handler.AcquireSubmemory(
109-
out_vec_dims, offset, reorder_src_memory_p, i);
106+
auto slice_mem_p = reorder_handler.AcquireSubmemory(out_vec_dims, offset,
107+
reorder_src_memory_p);
110108

111109
auto reorder_dst_memory_p = reorder_handler.AcquireDstMemory(
112-
outs[i], out_vec_dims, i, x->format(), ctx.GetPlace());
110+
outs[i], out_vec_dims, x->format(), ctx.GetPlace());
113111
auto reorder_p =
114-
reorder_handler.AcquireReorder(reorder_dst_memory_p, slice_mem_p, i);
112+
reorder_handler.AcquireReorder(reorder_dst_memory_p, slice_mem_p);
115113

116114
reorder_p->execute(astream, *slice_mem_p, *reorder_dst_memory_p);
117115

0 commit comments

Comments
 (0)