Skip to content

Fix mkldnn related irpasses being added triple times#16175

Closed
LeoZhao-Intel wants to merge 3 commits intoPaddlePaddle:developfrom
LeoZhao-Intel:leo_mkldnn_irpass
Closed

Fix mkldnn related irpasses being added triple times#16175
LeoZhao-Intel wants to merge 3 commits intoPaddlePaddle:developfrom
LeoZhao-Intel:leo_mkldnn_irpass

Conversation

@LeoZhao-Intel
Copy link
Contributor

test=develop

resolve #16174

@CLAassistant
Copy link

CLAassistant commented Mar 13, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@LeoZhao-Intel
Copy link
Contributor Author

start review @kbinias @Superjomn

@luotao1 luotao1 added the Intel label Mar 13, 2019
@luotao1
Copy link
Contributor

luotao1 commented Mar 13, 2019

Since #16174 (comment), how about fix "The rootcause is CpuPassStrategy uses copy constructor to re-initialize PassStrategy by update() function, the passes in previous instance is still kept"?

@LeoZhao-Intel
Copy link
Contributor Author

LeoZhao-Intel commented Mar 13, 2019

Since #16174 (comment), how about fix "The rootcause is CpuPassStrategy uses copy constructor to re-initialize PassStrategy by update() function, the passes in previous instance is still kept"?

In AnalysisConfig::Update(), pass_builder_ will be reset like this:

 } else {
    if (use_gpu()) {
      pass_builder_.reset(new GpuPassStrategy(
          *static_cast<GpuPassStrategy *>(pass_builder_.get())));

    } else {
      **pass_builder_.reset(new CpuPassStrategy(
          *static_cast<CpuPassStrategy *>(pass_builder_.get())));
    }**
 }

it uses copy constructor to reconstruct passstrategy, and passes_ is kept like

class CpuPassStrategy : public PassStrategy {
 public:
  CpuPassStrategy();

  explicit CpuPassStrategy(const CpuPassStrategy &other)
      : PassStrategy(**other.AllPasses()**) {}

so when call EnableMKLDNN(), the mkldnn irpassed are inserted into old passes vector instead of null vector, my patch will check if head has already include mkldnn irpass, if not, it will do insertion.

Not sure for the original purpose of CpuPassStrategy copy constructor, if not use copy constructor, the change may be big and not sure if impact other cases

@LeoZhao-Intel
Copy link
Contributor Author

LeoZhao-Intel commented Mar 13, 2019

void AnalysisConfig::EnableMKLDNN() {
#ifdef PADDLE_WITH_MKLDNN
  pass_builder()->EnableMKLDNN();
  use_mkldnn_ = true;
#else
  LOG(ERROR) << "Please compile with MKLDNN first to use MKLDNN";
  use_mkldnn_ = false;
#endif

  Update();
}

pass_builder()->EnableMKLDNN() is called again in Update() after pass_builder reset

@luotao1
Copy link
Contributor

luotao1 commented Mar 13, 2019

Not sure for the original purpose of CpuPassStrategy copy constructor, if not use copy constructor, the change may be big and not sure if impact other cases

@Superjomn Could you help see #16175 (comment)?

@luotao1 luotao1 requested a review from tensor-tang March 14, 2019 04:27
@luotao1
Copy link
Contributor

luotao1 commented Mar 15, 2019

Thanks for your contribution, we will consider to solve it in general.

@luotao1 luotao1 mentioned this pull request Mar 15, 2019
@sfraczek
Copy link

I was thinking that the copy constructor could copy use_mkldnn_ flag and it would also be enough. I ran into this error to and I was wondering if it is on purpose that the copy constructor does a copy of the passes only.

@LeoZhao-Intel
Copy link
Contributor Author

I was thinking that the copy constructor could copy use_mkldnn_ flag and it would also be enough. I ran into this error to and I was wondering if it is on purpose that the copy constructor does a copy of the passes only.

Yes, but unfortunately this copy constructor just copies passes_

@luotao1
Copy link
Contributor

luotao1 commented Mar 15, 2019

@LeoZhao-Intel @sfraczek Could you help see #16225? I fix it in another way.

@LeoZhao-Intel
Copy link
Contributor Author

@LeoZhao-Intel @sfraczek Could you help see #16225? I fix it in another way.

seems not working, pass_builder_ will be reset to new instance with just passes_ kept, "use_mkldnn_" value will be lost in new PassStrategy, PassStrategy copy constructor just copies passes_.

If do change like #16225, PassStrategy copy constructor need do more.

@wojtuss
Copy link

wojtuss commented Mar 20, 2019

@LeoZhao-Intel @sfraczek Could you help see #16225? I fix it in another way.

seems not working, pass_builder_ will be reset to new instance with just passes_ kept, "use_mkldnn_" value will be lost in new PassStrategy, PassStrategy copy constructor just copies passes_.

As @sfraczek sugested (#16175 (comment)) you could make the copy constructor copy also the use_mkldnn_ value.

@luotao1
Copy link
Contributor

luotao1 commented Apr 4, 2019

close due to #16606

@luotao1 luotao1 closed this Apr 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mkldnn related irpasses are added triple times when mkldnn is enabled in AnaylsisPredictor

5 participants