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

Fix BOF in the last channel handling logic of SSE ShuffleChannel #5735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

junwha
Copy link

@junwha junwha commented Oct 14, 2024

Fix #5734

  • apply SSE logic until size-1
  • apply linear logic for the last n elements

@tencent-adm
Copy link
Member

tencent-adm commented Oct 14, 2024

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.03%. Comparing base (1c7af00) to head (b2ee3aa).

❗ There is a different number of reports uploaded between BASE (1c7af00) and HEAD (b2ee3aa). Click for more details.

HEAD has 32 uploads less than BASE
Flag BASE (1c7af00) HEAD (b2ee3aa)
33 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5735       +/-   ##
===========================================
- Coverage   95.15%   90.03%    -5.13%     
===========================================
  Files         793      265      -528     
  Lines      270315    77624   -192691     
===========================================
- Hits       257218    69886   -187332     
+ Misses      13097     7738     -5359     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +653 to +667

for (int i = 0; i < 4; i++)
{
if (i % 2)
{
*outptr = *ptr1;
ptr1 += 1;
}
else
{
*outptr = *ptr0;
ptr0 += 1;
}
outptr += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

unroll the tail part

Suggested change
for (int i = 0; i < 4; i++)
{
if (i % 2)
{
*outptr = *ptr1;
ptr1 += 1;
}
else
{
*outptr = *ptr0;
ptr0 += 1;
}
outptr += 1;
}
{
outptr[0] = ptr0[0];
outptr[1] = ptr1[0];
outptr[2] = ptr0[1];
outptr[3] = ptr1[1];
ptr0 += 2;
ptr1 += 2;
outptr += 4;
}

ptr0 += 1;
}
outptr += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is a risk of out of range reading in some of the pack8/pack16 codes.

Comment on lines +645 to +658
for (int i = 0; i < 4; i++)
{
if (i % 2)
{
*outptr0 = *ptr1;
ptr1 += 1;
}
else
{
*outptr0 = *ptr0;
ptr0 += 1;
}
outptr0 += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

unroll this

Comment on lines +137 to +151

for (int i = 0; i < 16; i++)
{
if (i % 2)
{
*outptr = *ptr1;
ptr1 += 1;
}
else
{
*outptr = *ptr0;
ptr0 += 1;
}
outptr += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is a risk of out of range reading in some of the pack8/pack16 codes.

Comment on lines +396 to +410

for (int i = 0; i < 8; i++)
{
if (i % 2)
{
*outptr0 = *ptr1;
ptr1 += 1;
}
else
{
*outptr0 = *ptr0;
ptr0 += 1;
}
outptr0 += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is a risk of out of range reading in some of the arm pack8 codes.

Comment on lines +133 to +147

for (int i = 0; i < 4; i++)
{
if (i % 2)
{
*outptr0 = *ptr1;
ptr1 += 1;
}
else
{
*outptr0 = *ptr0;
ptr0 += 1;
}
outptr0 += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

unroll this

@junwha
Copy link
Author

junwha commented Oct 18, 2024

Hi @nihui,
Thank you for the fast response and review!
I will reflect the unrolling part.

Could I ask why do you think the out-of-bound risk does not exist in pack8/16 codes?
As far as I think, it also accesses (start of the channel) + (size-1)*(element size) + (element size)/2 in the same manner, which is beyond the size of the channel.

Thank you for your effort on this issue!

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

Successfully merging this pull request may close these issues.

The last channel handling logic in the SSE version of ShuffleChannel cause buffer-overflow
4 participants