-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: refactor
Are you sure you want to change the base?
Conversation
This commit may add some overhead of managing NDArray for each fallback.
Conflicts: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
2. Add memory into signature; 3. Try to split BatchNorm into .h file and .cc file. Will finish it after backward code is refactored.
Caching primitive for BatchNorm forward computation
const OpReqType &req) { | ||
// mkldnn::softmax_forward::primitive_desc | ||
auto input_mem = in_data.GetMKLDNNData(); | ||
auto output_mem = out_data.GetMKLDNNData(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…em; 3.cpu engine use encapsulated func
const OpReqType &req) { | ||
// mkldnn::softmax_forward::primitive_desc | ||
auto input_mem = in_data.GetMKLDNNData(); | ||
auto output_mem = out_data.GetMKLDNNData(); |
There was a problem hiding this comment.
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.
src/operator/nn/softmax.cc
Outdated
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
softmax has its unittest already, and mkldnn can pass: nosetests tests/python/unittest/test_operator.py:test_new_softmax |
ba474be
to
5cb7ca0
Compare
Description
Checklist
Essentials
make lint
)Changes
Comments