-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[QualcommQnn] Add stack、split、squeeze and concat op #9185
Conversation
Thanks for your contribution! |
@@ -727,6 +797,70 @@ void NCHW2NHWCDataLayoutConverter::ConvertSplit(core::Operation* operation) { | |||
} | |||
} | |||
|
|||
void NCHW2NHWCDataLayoutConverter::ConvertStack(core::Operation* operation) { |
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.
复用了ConvertConcat的逻辑,不同点在于stack会在axis维度上堆叠,所以insert了一个维度,并将原先的perm大于axis的维度值做了变化,保证transpose的次序不变。
for (auto& perm_data : reference_permutation) {
if (perm_data >= *axis) perm_data += 1;
}
reference_permutation.insert(reference_permutation.begin() + *axis, *axis);
auto input_permutation = GetPermutation(input_operand); | ||
std::vector<int32_t> nchw_layout = {0, 1, 2, 3}; | ||
std::vector<int32_t> axes; | ||
if (axes_operand && (axes_operand->length / sizeof(int32_t)) > 0) { |
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.
squeeze的axes有两种场景:
1、当axes_operand不为空,且数据不为空,则根据axes做降维操作。
2、当axes_operand为空或数据为空,则会将input所有为1的维度做降维度
auto output_dimensions_count = output_operand->type.dimensions.count; | ||
auto axes_operand = input_operands[1]; | ||
// Recalculate the perm according to the dimorder vector of the input operand | ||
auto input_permutation = GetPermutation(input_operand); |
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.
squeeze的实现逻辑可以理解如下:例如初始 input为(1,3,1,5),初始axes为(0,2),input_permutation为(0,2,3,1),则经过input_permutation变化的axes为(0,1)
首先使用原始和经过input_permutation变化后的axes数据,分别将 Identity_permutation 和 input_permutation 对应的维度去掉,
即input_permutation从(0,2,3,1)变为(3,1),Identity_permutation从(0,1,2,3)变为(1,3)。
其次再将 input_permutation 与 Identity_permutation 做对比,若一致不做数据transpose,若不一致,例如(3,1)和(1,3)不一致,则会根据相应的关系处理得到output_permutation为(1,0)。
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
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,squeeze在axes为空时的处理逻辑有问题,再提个 PR修复下
No description provided.