Clarify stream kernel bounds assumptions

This commit is contained in:
Marek Lemańczyk committed 2025-10-22 21:41:51 +02:00
1 parent 586eb8d303
commit ea0770a84a
1 file changed
+20 -14
@@ -87,11 +87,13 @@ internal static class DivisorByDivisorKernels
byte modulus) byte modulus)
{ {
int globalIndex = index; int globalIndex = index;
int length = (int)remainders.Length; // EvenPerfectBitScanner launches this stream kernel with an extent matching the remainder span length,
if (globalIndex >= length) // so the defensive guard stays commented out to keep the kernel branch-free.
{ // int length = (int)remainders.Length;
return; // if (globalIndex >= length)
} // {
// return;
// }
int localIndex = Group.IdxX; int localIndex = Group.IdxX;
int groupSize = Group.Dimension.X; int groupSize = Group.Dimension.X;
@@ -136,11 +138,13 @@ internal static class DivisorByDivisorKernels
ArrayView<byte> mask) ArrayView<byte> mask)
{ {
int globalIndex = index; int globalIndex = index;
int length = (int)mask.Length; // EvenPerfectBitScanner launches this auto-grouped kernel with an extent matching the mask length,
if (globalIndex >= length) // so the defensive guard stays commented out to keep the kernel branch-free.
{ // int length = (int)mask.Length;
return; // if (globalIndex >= length)
} // {
// return;
// }
byte value10 = remainder10[globalIndex]; byte value10 = remainder10[globalIndex];
bool lastIsSeven = lastIsSevenFlag != 0; bool lastIsSeven = lastIsSevenFlag != 0;
@@ -164,10 +168,12 @@ internal static class DivisorByDivisorKernels
{ {
int globalIndex = index; int globalIndex = index;
int length = (int)mask.Length; int length = (int)mask.Length;
if (globalIndex >= length) // EvenPerfectBitScanner launches this stream kernel with an extent matching the mask length,
{ // so the defensive guard stays commented out to keep the kernel branch-free.
return; // if (globalIndex >= length)
} // {
// return;
// }
int localIndex = Group.IdxX; int localIndex = Group.IdxX;
int groupSize = Group.Dimension.X; int groupSize = Group.Dimension.X;