-
Notifications
You must be signed in to change notification settings - Fork 26.3k
implement transpose operator for MKLDNN #19955
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3cecba3
implement transpose operator for MKLDNN
gujinghui 9112f87
remove extra parenthesis in transpose_op_test.py
gujinghui b86a758
Merge remote-tracking branch 'origin/master' into HEAD
6646151
Merge remote-tracking branch 'origin/master' into transpose_op
bddppq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <caffe2/ideep/ideep_utils.h> | ||
|
|
||
| using namespace caffe2; | ||
|
|
||
| namespace { | ||
|
|
||
| class IDEEPTransposeOp final : public IDEEPOperator { | ||
| public: | ||
| USE_IDEEP_DEF_ALIASES(); | ||
| USE_IDEEP_OPERATOR_FUNCTIONS(); | ||
|
|
||
| IDEEPTransposeOp(const OperatorDef& operator_def, Workspace* ws) | ||
| : IDEEPOperator(operator_def, ws), | ||
| axes_(this->template GetRepeatedArgument<int>("axes")){ } | ||
| ~IDEEPTransposeOp() override {} | ||
|
|
||
| bool RunOnDevice() override { | ||
| const auto& X = Input(INPUT); | ||
| auto* Y = Output(OUTPUT); | ||
|
|
||
| Y->transpose_from(X, axes_); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private: | ||
| std::vector<int> axes_; | ||
|
|
||
| INPUT_TAGS(INPUT); | ||
| OUTPUT_TAGS(OUTPUT); | ||
| }; | ||
|
|
||
| REGISTER_IDEEP_OPERATOR(Transpose, IDEEPTransposeOp); | ||
|
|
||
| } // namespace | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
| from __future__ import unicode_literals | ||
|
|
||
| import unittest | ||
| import hypothesis.strategies as st | ||
| from hypothesis import given | ||
| import numpy as np | ||
| from caffe2.proto import caffe2_pb2 | ||
| from caffe2.python import core, workspace | ||
| import caffe2.python.hypothesis_test_util as hu | ||
| import caffe2.python.ideep_test_util as mu | ||
|
|
||
| @unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.") | ||
| class TransposeTest(hu.HypothesisTestCase): | ||
| @given( | ||
| X=hu.tensor(min_dim=1, max_dim=5, dtype=np.float32), use_axes=st.booleans(), **mu.gcs) | ||
| def test_transpose(self, X, use_axes, gc, dc): | ||
| ndim = len(X.shape) | ||
| axes = np.arange(ndim) | ||
| np.random.shuffle(axes) | ||
|
|
||
| if use_axes: | ||
| op = core.CreateOperator( | ||
| "Transpose", ["X"], ["Y"], axes=axes, device_option=gc) | ||
| else: | ||
| op = core.CreateOperator( | ||
| "Transpose", ["X"], ["Y"], device_option=gc) | ||
|
|
||
| def transpose_ref(X): | ||
| if use_axes: | ||
| return [np.transpose(X, axes=axes)] | ||
| else: | ||
| return [np.transpose(X)] | ||
|
|
||
| self.assertReferenceChecks(gc, op, [X], transpose_ref) | ||
| self.assertDeviceChecks(dc, op, [X], [0]) | ||
| self.assertGradientChecks(gc, op, [X], 0, [0]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.