From 827e349ac8eb769a873fe9b3aa961af8b8b20a96 Mon Sep 17 00:00:00 2001 From: jameswu2014 <545426914@qq.com> Date: Sat, 7 Mar 2020 20:59:22 +0800 Subject: [PATCH] reshape2-format-modify --- .../kernel/fpga/V1/.fetch_kernel.cpp.swp | Bin 16384 -> 0 bytes .../operators/kernel/fpga/V1/fetch_kernel.cpp | 2 +- .../kernel/fpga/V1/reshape2_kernel.cpp | 106 +++++++++--------- 3 files changed, 53 insertions(+), 55 deletions(-) delete mode 100644 mobile/src/operators/kernel/fpga/V1/.fetch_kernel.cpp.swp diff --git a/mobile/src/operators/kernel/fpga/V1/.fetch_kernel.cpp.swp b/mobile/src/operators/kernel/fpga/V1/.fetch_kernel.cpp.swp deleted file mode 100644 index a49df219da80b5418ef845304c9d3619a269a5f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeHNO^h5z6)qb{0wG|9L?EPym$gJ@*0VGFV;O6ICQN46-XZJR)$ZDhahz6fcg=Q( zp6;f*#^a6SfDji1621~p6d`fo0vzBHM9eLUgajNT4k!W+AdoyX8PyVdsW|i_0z9wclt`_5`Ch6mf<+X*fU>tp8d{J^W+m>VJz_E&3hkdYJ zxxtg;WnT=u#_;+5Mr^xoz^4LV@WzHdUz6wkXx9&TBTbw}6!XLuQIa-3%af1?jb6NG zH?GVydR#c3rEk`qI6mH@d1@Fi3@8Q$qBnK^AvQNVGcB)APdrW^dib&-$1q?RFbo(5 z3GHFkl$?KVm?{C)wxG-ji9I{p|n5q5pSf*B{CLpF8wCyEK1>0mFb{z%XDK zFbo(53GHFkl!k47>vwuwBO9i+a5wU-5~OvF`z20-gi5fi2)7@Br|$_cQiG;3XgiR)Dj>G;k7l>p{kT0(>8M z1-JtQKo^(>9tKVTzkVNMzXDzZUI0D=)PO&u0j~mI0A2t-1$2Oq0>6KNu^$6p100|V zoC5xFKV!cH?gDoJ2WSDG1ZIE+@Ya2deH{=$7pMX!fH&U5*tdX}fo}qLfK}iW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XxX9z2a19 zc6#PK=}qP{Q=ZX2UX`las`}kgDU~eOU$TirR_P;0 zmLShRW#w|PGMYzJ%49aHoO?rtFDuaAIml%dw_r)rsP6o)@_RC$dGtVqRiaO&MwO%R nArHREz6h4Snv^_S`ogFZJNNpMS3CG_3VUOdez)Jr`Ne+$0ks{z diff --git a/mobile/src/operators/kernel/fpga/V1/fetch_kernel.cpp b/mobile/src/operators/kernel/fpga/V1/fetch_kernel.cpp index 89cfe8f263..4309146afd 100644 --- a/mobile/src/operators/kernel/fpga/V1/fetch_kernel.cpp +++ b/mobile/src/operators/kernel/fpga/V1/fetch_kernel.cpp @@ -80,7 +80,7 @@ void FetchKernel::Compute(const FetchParam ¶m) { auto output = ¶m.Out()->at(col); if (input->type() == type_id()) { output->ShareDataWith(*input); - // output dims equal to input dim + // output dims == input dim output->Resize(input->dims()); return; } diff --git a/mobile/src/operators/kernel/fpga/V1/reshape2_kernel.cpp b/mobile/src/operators/kernel/fpga/V1/reshape2_kernel.cpp index e41061d4d1..8697739b0a 100644 --- a/mobile/src/operators/kernel/fpga/V1/reshape2_kernel.cpp +++ b/mobile/src/operators/kernel/fpga/V1/reshape2_kernel.cpp @@ -92,69 +92,67 @@ void reshape(LoDTensor *input, LoDTensor *output) { fpga::fpga_flush(output_ptr, Hr * WCr_align * sizeof(half)); } -static inline bool reshape2_judge(const framework::DDim input_dims,const framework::DDim output_dims){ - int input_dims_size = input_dims.size(); - int output_dims_size = output_dims.size(); - bool dims_flag2 = true; - auto temp_dims = input_dims_size > output_dims_size ? input_dims : output_dims; - int short_dims = input_dims_size > output_dims_size ? output_dims_size : input_dims_size; - for(int i = 0; i < temp_dims.size(); ++i){ - if(i < short_dims){ - if(input_dims[i] != output_dims[i]){ - dims_flag2 = false; - break; - } - } - else{ - if(temp_dims[i] != 1){ - dims_flag2 = false; - break; - } - } - } - return dims_flag2; - - +static inline bool reshape2_judge(const framework::DDim input_dims, + const framework::DDim output_dims) { + int input_dims_size = input_dims.size(); + int output_dims_size = output_dims.size(); + bool dims_flag2 = true; + auto temp_dims = input_dims_size > output_dims_size ? + input_dims : output_dims; + int short_dims = input_dims_size > output_dims_size ? + output_dims_size : input_dims_size; + for (int i = 0; i < temp_dims.size(); ++i) { + if (i < short_dims) { + if (input_dims[i] != output_dims[i]) { + dims_flag2 = false; + break; + } + } else { + if (temp_dims[i] != 1) { + dims_flag2 = false; + break; + } + } + } + return dims_flag2; } template <> void Reshape2Kernel::Compute(const Reshape2Param ¶m) { - auto input = const_cast(param.InputX()); - auto output = param.Out(); - auto shape = param.Shape(); - - auto num_in = framework::product(input->dims()); - auto num_shape = framework::product(framework::make_ddim(shape)); - PADDLE_MOBILE_ENFORCE(num_shape != 0, "0 index is not supported"); - - for (int i = 0; i < shape.size(); i++) { - if (shape[i] == -1) { - shape[i] = static_cast(-num_in / num_shape); - break; + auto input = const_cast(param.InputX()); + auto output = param.Out(); + auto shape = param.Shape(); + + auto num_in = framework::product(input->dims()); + auto num_shape = framework::product(framework::make_ddim(shape)); + PADDLE_MOBILE_ENFORCE(num_shape != 0, "0 index is not supported"); + + for (int i = 0; i < shape.size(); i++) { + if (shape[i] == -1) { + shape[i] = static_cast(-num_in / num_shape); + break; + } } - } - output->Resize(framework::make_ddim(shape)); + output->Resize(framework::make_ddim(shape)); - auto input_dims = input->dims(); - auto output_dims = output->dims(); + auto input_dims = input->dims(); + auto output_dims = output->dims(); - bool dims_flags = input_dims == output_dims; - bool dims_flag2 = true; + bool dims_flags = input_dims == output_dims; + bool dims_flag2 = true; - if(!dims_flags){ - dims_flag2 = reshape2_judge(input_dims, output_dims); - } - - - if (dims_flags || dims_flag2 ) { - DLOG << "No need to reshape"; - output->ShareDataWith(*input); - framework::LoD lod = input->lod(); - output->set_lod(lod); - return; - } + if (!dims_flags) { + dims_flag2 = reshape2_judge(input_dims, output_dims); + } + if (dims_flags || dims_flag2) { + DLOG << "No need to reshape"; + output->ShareDataWith(*input); + framework::LoD lod = input->lod(); + output->set_lod(lod); + return; + } - reshape(input, output); + reshape(input, output); // } -- GitLab