-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Small fixes to improve TensorIterator overhead for the common case of inputs and outputs of the same type #27457
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
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
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 |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ | |
| // (See https://github.com/pytorch/pytorch/issues/9515) | ||
| // | ||
| // Note that TensorIterator currently supports type conversions on 0-dim | ||
| // tensors and arithmetic operators. Other type conversions will raise an | ||
| // tensors and arithmetic operators. Other type conversions will raise an | ||
| // exception. | ||
|
|
||
| namespace at { | ||
|
|
@@ -71,6 +71,7 @@ struct DimCounter { | |
| }; | ||
|
|
||
| struct CAFFE2_API OperandInfo { | ||
| using StrideVector = SmallVector<int64_t, 6>; | ||
| OperandInfo() {} | ||
| explicit OperandInfo(const Tensor& t) : tensor(t) { | ||
| if (t.defined()) { | ||
|
|
@@ -85,7 +86,7 @@ struct CAFFE2_API OperandInfo { | |
| } | ||
|
|
||
| /// Stride after broadcasting. The stride is in bytes, not number of elements. | ||
| DimVector stride_bytes; | ||
| StrideVector stride_bytes; | ||
|
|
||
| /// The tensor operand. Note that the strides, data pointer, and | ||
| /// other attributes may differ due to dimension reordering and | ||
|
|
@@ -134,6 +135,7 @@ enum class CommonDTypeStrategy : uint8_t { | |
| struct CAFFE2_API TensorIterator { | ||
| using DimMask = std::bitset<64>; | ||
| using PtrVector = SmallVector<char*, 4>; | ||
| using StrideVector = SmallVector<int64_t, 6>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: maybe move this magical numbers into constant with good name |
||
|
|
||
| TensorIterator() {} | ||
|
|
||
|
|
@@ -254,16 +256,16 @@ struct CAFFE2_API TensorIterator { | |
| /// Create a strides array for a Tensor with shape of this iterator. The | ||
| /// parameter `element_size` specifies the size of Tensor's data type in | ||
| /// bytes (e.g. `4` for `float`) | ||
| DimVector compatible_stride(int element_size) const; | ||
| StrideVector compatible_stride(int element_size) const; | ||
|
|
||
| /// Inverts the re-ordering done by reorder_dimensions. This can only be | ||
| /// called *before* coalesce_dimensions() is called. | ||
| DimVector invert_perm(IntArrayRef input) const; | ||
|
|
||
| /// Helper functions for CPU iteration | ||
| DimVector get_dim_strides(int dim) const; | ||
| DimVector get_strides() const; | ||
| DimVector get_inner_strides() const { return get_dim_strides(0); } | ||
| StrideVector get_dim_strides(int dim) const; | ||
| StrideVector get_strides() const; | ||
| StrideVector get_inner_strides() const { return get_dim_strides(0); } | ||
| PtrVector get_data_ptrs(ArrayRef<char*> base, IntArrayRef counter) const; | ||
| PtrVector get_base_ptrs() const; | ||
|
|
||
|
|
@@ -328,7 +330,7 @@ struct CAFFE2_API TensorIterator { | |
| void reorder_dimensions(); | ||
| void permute_dimensions(IntArrayRef perm); | ||
| void compute_types(); | ||
| std::tuple<Device, ScalarType> compute_common_type(); | ||
| std::tuple<Device, ScalarType, bool> compute_common_type(); | ||
| void allocate_outputs(); | ||
| #ifdef BUILD_NAMEDTENSOR | ||
| void compute_names(); | ||
|
|
||
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
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.
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.
indentation