Skip to content

[FORK][FIX][x64] Refactor avx2 binary PReLU and fix reg conflicts - #242

Merged
maxnick merged 1 commit into
v3.3_for_ie_masterfrom
mkutakov/binary_prelu_fix_v3.3
May 3, 2024
Merged

[FORK][FIX][x64] Refactor avx2 binary PReLU and fix reg conflicts#242
maxnick merged 1 commit into
v3.3_for_ie_masterfrom
mkutakov/binary_prelu_fix_v3.3

Conversation

@maxnick

@maxnick maxnick commented Apr 17, 2024

Copy link
Copy Markdown
Collaborator

Description

OpenVINO PR openvinotoolkit/openvino#24102


if (one_of(vmm_aux0, dst, lhs, rhs)) {
//let's find a vacant XMM register
int occupied_idices[] = {dst.getIdx(), lhs.getIdx(), rhs.isMEM() ? -1 : rhs.getIdx()};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

rhs should not be memory in my understanding for this template function.
std::enable_if<!(std::is_same<T, Xbyak::Zmm>::value
|| std::is_same<T, Xbyak::Address

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. Thank you

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

if (indx == 0) {
auto vmm_zero = Vmm(indx);
host_->vmovups(vmm_aux0, vmm_zero);
std::swap(vmm_aux0, vmm_zero);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems have some problem here.Assuming:
vmm_aux =vmm(4) , vmm_zero =vmm(0), lhs = vmm(0) before swapping. After swap, vmm_aux=vmm(0), vmm_zero=vmm(4), but lhs still vmm(0). Seem lhs should also be changed to vmm(4). right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Will fix it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@maxnick
maxnick force-pushed the mkutakov/binary_prelu_fix_v3.3 branch from 2da34c1 to 2d73bac Compare April 19, 2024 13:49
@maxnick
maxnick requested a review from luweizhou2016 April 19, 2024 13:51
} else {
using dnnl::impl::utils::one_of;
// in sse4 vmm_aux0 as mask it's index must be 0
Vmm vmm_aux0 = Vmm(rhs_arg_static_params_.rhs_prelu_helper_vmm_idx);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The SSE implement assume that rhs_arg_static_params_.rhs_prelu_helper_vmm_idx = 0 and seems current binary_post_ops would set rhs_prelu_helper_vmm_idx = 0. However, Can we directly use vmm_aux0 = Vmm(0) and not use this rhs_prelu_helper_vmm_idx? Or add some check rhs_prelu_helper_vmm_idx must be 0, assert would not be compiled into release version. Maybe directly use vmm_aux0 = Vmm(0) ? It would be easier to understand this piece of code.

@maxnick maxnick Apr 23, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In theory this rhs_arg_static_params_.rhs_prelu_helper_vmm_idx should be a hint that helps to avoid the search for the vacant register. Also since this is the SSE path, which is mostly supported as a legacy, I wouldn't put more effort on ironing out this part.

@luweizhou2016 luweizhou2016 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Except the minor change on the comment. The code is okay for me.

@maxnick
maxnick force-pushed the mkutakov/binary_prelu_fix_v3.3 branch from 2d73bac to cdbfd4c Compare May 2, 2024 15:14
github-merge-queue Bot pushed a commit to openvinotoolkit/openvino that referenced this pull request May 3, 2024
### Details:
Refactor binary PReLU avx2 post op in order to reduce the amount of
instructions for avx2 and fix the conflicting register indices issue for
both avx2 and sse41. This is more advanced version of the previous fix
ported only to the LTS branch
#23910. Also dedicated
SL tests were introduced.

OneDNN fork PR openvinotoolkit/oneDNN#242

### Tickets:
 - CVS-137492
@maxnick
maxnick merged commit cdbfd4c into v3.3_for_ie_master May 3, 2024
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.

2 participants