-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-365] handle inplace in mkldnn FallBackCompute #10591
[MXNET-365] handle inplace in mkldnn FallBackCompute #10591
Conversation
if (req[i] == kWriteTo) | ||
// ensure output does not use mkldnn mem. | ||
// for inplace, we already converted & copied input above. | ||
if ((req[i] == kWriteTo) || (req[i] == kWriteInplace)) | ||
const_cast<NDArray &>(outputs[i]).InvalidateMKLDNNData(); |
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.
Actually, we need to handle kAddTo properly here as well. If it's kAddTo, we can convert the layout of the output array to the default format directly. since it's output array, we expect its memory will be written.
ba9de4d
to
4a25536
Compare
// for inplace, we already converted & copied input above. | ||
if ((req[i] == kWriteTo) || (req[i] == kWriteInplace)) | ||
const_cast<NDArray &>(output).InvalidateMKLDNNData(); | ||
if (req[i] == kAddTo) |
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.
could you make this "else if"?
4a25536
to
3c792b9
Compare
@zheng-da added your feedback comments, @piiswrong can you please merge if ok. thanks. |
can you add a test for this? |
3c792b9
to
7a4c26d
Compare
@zheng-da added unittest for this, please accept review if ok , thanks |
7d16a4b
to
8f8b792
Compare
8f8b792
to
0a8ce05
Compare
@piiswrong can you please merge, thanks. |
@piiswrong ping... |
@marcoabreu is this something you can merge. thanks. |
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.
MKL tests are currently not run. Please remove --build from https://github.com/apache/incubator-mxnet/blob/master/Jenkinsfile#L112
Why do MKL tests not run? We need to enable them to test MKLDNN-specific scripts, right? |
There is a mistake in our launch command |
36f0367
to
fdc17d4
Compare
@marcoabreu made requested changes, can we please merge |
tests/python/mkl/test_mkldnn.py
Outdated
# output should have 0.3376348 | ||
assert_almost_equal(y[0, 0, 0, 0], 0.3376348) | ||
assert_almost_equal(y[0, 0, 0, 0], 0.016711406) |
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.
could you remind me what this is? why do you need to change it?
BTW, you need to update the comment as well.
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.
it just computes with fixed 1s as input, and this is the value i see as a result with GPU or cpu (non-mkldnn mode).
2511534
to
bd9d4e1
Compare
bd9d4e1
to
e2ac42f
Compare
@marcoabreu this one is ready for merge too, made changes suggested by you. thanks. |
Let me just retrigger CI |
// ensure output does not use mkldnn mem. | ||
// for inplace, we already converted & copied input above. | ||
if ((req[i] == kWriteTo) || (req[i] == kWriteInplace)) | ||
const_cast<NDArray &>(output).InvalidateMKLDNNData(); |
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.
Is this threadsafe? What happens if multiple threads try to read/write or they call it in sequence?
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.
called in sequence, this PR only adds kWriteInplace
option to existing kWriteTo
handling.
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.
What I mean is whether this operation does have any side effects that could cause problems if they are called from multiple threads in parallel or multiple times in sequence.
We have seen quite a few regressions in terms of race conditions related to MKLDNN and I would like to highlight threadsafety a bit more in our reviews
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.
These are output arrays. If the dependency works correctly in the execution engine, no other threads will read or modify them when this function runs. InvalidateMKLDNNData has a side effect. so is writing data to the output arrays.
I guess you refer to the bug I reported in my other PR. As I said, the race condition isn't MKLDNN-specific. It's just MKLDNN that makes it noticeable. A lot of our tests just run the computation and don't verify the correctness of the 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.
LGTM, but please assess the thread safety before merging
@marcoabreu we now have CI running though these test with |
Could you please change the name of the tests? Thanks |
e2ac42f
to
4b19536
Compare
4b19536
to
df08174
Compare
@zheng-da updated PR to use testname, @marcoabreu can you merge now, thanks. |
* handle inplace in mkldnn FallBackCompute * add comments * handle kAddTo in mkldnn FallBackCompute * add PR feedback * add unittest for mkldnn inplace sum with cpu data * add back mkldnn engine threading unittest * separate mkldnn install test and fix pylint issue * remove --build from mkldnn jenkins test * update mkldnn unittests * update comments for mkldnn test * remove python test doc string so unittest name is used
* handle inplace in mkldnn FallBackCompute * add comments * handle kAddTo in mkldnn FallBackCompute * add PR feedback * add unittest for mkldnn inplace sum with cpu data * add back mkldnn engine threading unittest * separate mkldnn install test and fix pylint issue * remove --build from mkldnn jenkins test * update mkldnn unittests * update comments for mkldnn test * remove python test doc string so unittest name is used
* handle inplace in mkldnn FallBackCompute * add comments * handle kAddTo in mkldnn FallBackCompute * add PR feedback * add unittest for mkldnn inplace sum with cpu data * add back mkldnn engine threading unittest * separate mkldnn install test and fix pylint issue * remove --build from mkldnn jenkins test * update mkldnn unittests * update comments for mkldnn test * remove python test doc string so unittest name is used
* handle inplace in mkldnn FallBackCompute * add comments * handle kAddTo in mkldnn FallBackCompute * add PR feedback * add unittest for mkldnn inplace sum with cpu data * add back mkldnn engine threading unittest * separate mkldnn install test and fix pylint issue * remove --build from mkldnn jenkins test * update mkldnn unittests * update comments for mkldnn test * remove python test doc string so unittest name is used
* handle inplace in mkldnn FallBackCompute * add comments * handle kAddTo in mkldnn FallBackCompute * add PR feedback * add unittest for mkldnn inplace sum with cpu data * add back mkldnn engine threading unittest * separate mkldnn install test and fix pylint issue * remove --build from mkldnn jenkins test * update mkldnn unittests * update comments for mkldnn test * remove python test doc string so unittest name is used
Description
handle inplace in mkldnn FallBackCompute. This bug is noticed in mkldnn sum, if one of the inputs is cpu layout
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments