Skip to content
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

Merged
merged 5 commits into from
Jul 6, 2022

Conversation

shentanyue
Copy link
Collaborator

No description provided.

@paddle-bot-old
Copy link

Thanks for your contribution!

@@ -727,6 +797,70 @@ void NCHW2NHWCDataLayoutConverter::ConvertSplit(core::Operation* operation) {
}
}

void NCHW2NHWCDataLayoutConverter::ConvertStack(core::Operation* operation) {
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

@shentanyue shentanyue Jul 4, 2022

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)。

zhupengyang
zhupengyang previously approved these changes Jul 5, 2022
Copy link
Collaborator

@zhupengyang zhupengyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@hong19860320 hong19860320 left a 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修复下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants