Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Softmax refactor #7

Open
wants to merge 274 commits into
base: refactor
Choose a base branch
from
Open

Conversation

wentingj
Copy link

@wentingj wentingj commented Jan 9, 2018

Description

  1. refact softmax op with signature
  2. encapsulate mkldnn operation into class

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • For user-facing API changes, API doc string has been updated. For new C++ functions in header files, their functionalities and arguments are well-documented.
  • To my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

const OpReqType &req) {
// mkldnn::softmax_forward::primitive_desc
auto input_mem = in_data.GetMKLDNNData();
auto output_mem = out_data.GetMKLDNNData();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling GetMKLDNNData() will create memory for out_data with default layout. But out_data may need a specific layout which is same as in_data?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. This is a problem in my original code.


mkldnn::memory::primitive_desc data_mpd = input_mem->get_primitive_desc();
mkldnn::memory::desc data_md = data_mpd.desc();
auto cpu_engine = data_mpd.get_engine();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CpuEngine::Get()->get_engine()

bool is_train,
const NDArray &in_data,
const NDArray &out_data,
const OpReqType &req) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req is not used in this function?

~MKLDNNSoftmaxFwd() {}
void SetDataHandle(const NDArray &in_data,
const NDArray &out_data,
const OpReqType &req) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req is not used in this function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will remove this input.

const OpReqType &req) {
// mkldnn::softmax_forward::primitive_desc
auto input_mem = in_data.GetMKLDNNData();
auto output_mem = out_data.GetMKLDNNData();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. This is a problem in my original code.

if (dev_mask == mshadow::cpu::kDevMask)
// We only run MKLDNN op if it runs on CPU and the input data is MKLDNN
// format.
if (dev_mask == mshadow::cpu::kDevMask && (*in_attrs)[0] == kMKLDNNStorage)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove kMKLDNNStorage. There isn't kMKLDNNStorage any more.

MKLDNNSmSignature key(param);
key.AddSign(ctx.is_train);
key.AddSign(param.axis);
key.AddSign(in_data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add MKLDMM memory as part of a signature. We need layout info.

mkldnn::memory::primitive_desc data_mpd = input_mem->get_primitive_desc();
auto output_mem = CreateMKLDNNMem(out_data, data_mpd, req).second;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use CreateMKLDNNMem, you have to use it with CommitOutput. You can't use CreateMKLDNNMem alone.
You could use the CreateMKLDNNData method in NDArray, as batchnorm does.

@wentingj
Copy link
Author

softmax has its unittest already, and mkldnn can pass: nosetests tests/python/unittest/test_operator.py:test_new_softmax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants