-
Notifications
You must be signed in to change notification settings - Fork 179
[luci] Support more dtypes in ForwardTransposeOp #16373
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
Merged
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,10 +153,11 @@ uint32_t cal_offset(const std::vector<uint32_t> &shape, const std::vector<uint32 | |
| return offset; | ||
| } | ||
|
|
||
| // Return reverse-transpose of 'node' | ||
| // i.e., Transpose(return value) = node | ||
| CircleConst *reverse_transposed(CircleConst *node, std::vector<uint32_t> &t) | ||
| template <loco::DataType DT> | ||
| CircleConst *reverse_transposed_t(CircleConst *node, std::vector<uint32_t> &t) | ||
| { | ||
| using T = typename loco::DataTypeImpl<DT>::Type; | ||
|
|
||
| assert(node->rank() == t.size()); // FIX_CALLER_UNLESS | ||
| assert(node->rank() == 4); // FIX_CALLER_UNLESS | ||
|
|
||
|
|
@@ -190,8 +191,8 @@ CircleConst *reverse_transposed(CircleConst *node, std::vector<uint32_t> &t) | |
| std::vector<uint32_t> orig_indices{new_indices[t[0]], new_indices[t[1]], | ||
| new_indices[t[2]], new_indices[t[3]]}; | ||
|
|
||
| const auto data = node->at<loco::DataType::FLOAT32>(cal_offset(orig_shape, orig_indices)); | ||
| clone_const->at<loco::DataType::FLOAT32>(cal_offset(new_shape, new_indices)) = data; | ||
| const auto v = node->at<DT>(cal_offset(orig_shape, orig_indices)); | ||
| clone_const->at<DT>(cal_offset(new_shape, new_indices)) = static_cast<T>(v); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -200,28 +201,72 @@ CircleConst *reverse_transposed(CircleConst *node, std::vector<uint32_t> &t) | |
| return clone_const; | ||
| } | ||
|
|
||
| bool check_rank_four(const CircleConst *c) { return c->rank() == 4; } | ||
|
|
||
| bool has_single_element(const luci::CircleConst *node) | ||
| // Return reverse-transpose of 'node' | ||
| // i.e., Transpose(return value) = node | ||
| CircleConst *reverse_transposed(CircleConst *node, std::vector<uint32_t> &t) | ||
| { | ||
| bool has_single_elem = false; | ||
| switch (node->dtype()) | ||
| { | ||
| case loco::DataType::FLOAT32: | ||
| has_single_elem = node->size<loco::DataType::FLOAT32>() == 1; | ||
| break; | ||
| return reverse_transposed_t<loco::DataType::FLOAT32>(node, t); | ||
| case loco::DataType::FLOAT16: | ||
| return reverse_transposed_t<loco::DataType::FLOAT16>(node, t); | ||
|
|
||
| case loco::DataType::S32: | ||
| return reverse_transposed_t<loco::DataType::S32>(node, t); | ||
| case loco::DataType::S16: | ||
| return reverse_transposed_t<loco::DataType::S16>(node, t); | ||
| case loco::DataType::S8: | ||
| return reverse_transposed_t<loco::DataType::S8>(node, t); | ||
| case loco::DataType::U8: | ||
| return reverse_transposed_t<loco::DataType::U8>(node, t); | ||
|
|
||
| default: | ||
| // NYI | ||
| break; | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| bool check_rank_four(const CircleConst *c) { return c->rank() == 4; } | ||
|
|
||
| if (has_single_elem) | ||
| template <loco::DataType DT> bool has_single_element_t(const luci::CircleConst *node) | ||
| { | ||
| if (node->size<DT>() != 1) | ||
| { | ||
| for (uint32_t i = 0; i < node->rank(); i++) | ||
| assert(node->dim(i).value() == 1); // FIX_ME_UNLESS | ||
| return false; | ||
| } | ||
| for (uint32_t i = 0; i < node->rank(); i++) | ||
| { | ||
| assert(node->dim(i).value() == 1); // FIX_ME_UNLESS | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| bool has_single_element(const luci::CircleConst *node) | ||
| { | ||
| switch (node->dtype()) | ||
| { | ||
| case loco::DataType::FLOAT32: | ||
| return has_single_element_t<loco::DataType::FLOAT32>(node); | ||
| case loco::DataType::FLOAT16: | ||
| return has_single_element_t<loco::DataType::FLOAT16>(node); | ||
|
|
||
|
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. ditto. |
||
| case loco::DataType::S64: | ||
| return has_single_element_t<loco::DataType::S64>(node); | ||
| case loco::DataType::S32: | ||
| return has_single_element_t<loco::DataType::S32>(node); | ||
| case loco::DataType::S16: | ||
| return has_single_element_t<loco::DataType::S16>(node); | ||
| case loco::DataType::S8: | ||
| return has_single_element_t<loco::DataType::S8>(node); | ||
| case loco::DataType::U8: | ||
| return has_single_element_t<loco::DataType::U8>(node); | ||
|
|
||
| return has_single_elem; | ||
| case loco::DataType::BOOL: | ||
| return has_single_element_t<loco::DataType::BOOL>(node); | ||
|
|
||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // Elementwise Binary Operator with const | ||
|
|
||
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.
Is it inteded line break?
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.
Ah, right. I just split it according to the float vs. int. It's just a preference.