Skip to content

Commit

Permalink
lgc: fix wrong thread id when group size Y/Z is 1
Browse files Browse the repository at this point in the history
tidigCompCnt is set to 0 when y and z are 1 and 1 when z is 1. In the
random failed case, the group size is 1x1x1, so the y and z ids are just
random values.
  • Loading branch information
xazhangAMD committed Nov 9, 2023
1 parent 82ef966 commit b0bc114
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lgc/patch/PatchEntryPointMutate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,14 @@ void PatchEntryPointMutate::lowerGroupMemcpy(GroupMemcpyOp &groupMemcpyOp) {

// LocalInvocationIndex is
// (LocalInvocationId.Z * WorkgroupSize.Y + LocalInvocationId.Y) * WorkGroupSize.X + LocalInvocationId.X
threadIndex = builder.CreateMul(threadIdComp[2], builder.getInt32(workgroupSize[1]));
threadIndex = builder.CreateAdd(threadIndex, threadIdComp[1]);
threadIndex = builder.CreateMul(threadIndex, builder.getInt32(workgroupSize[0]));
// tidigCompCnt is not always 3 if groupSizeY and/or groupSizeZ are 1. See RegisterMetadataBuilder.cpp.
threadIndex = builder.getInt32(0);
if (workgroupSize[2] > 1)
threadIndex = builder.CreateMul(threadIdComp[2], builder.getInt32(workgroupSize[1]));
if (workgroupSize[1] > 1) {
threadIndex = builder.CreateAdd(threadIndex, threadIdComp[1]);
threadIndex = builder.CreateMul(threadIndex, builder.getInt32(workgroupSize[0]));
}
threadIndex = builder.CreateAdd(threadIndex, threadIdComp[0]);
}
} else {
Expand Down

0 comments on commit b0bc114

Please sign in to comment.