Skip to content

Commit

Permalink
Optimized offset calculator in indexing ops
Browse files Browse the repository at this point in the history
Signed-off-by: majing <[email protected]>
  • Loading branch information
majing921201 committed Sep 19, 2024
1 parent da7692e commit 94937b0
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/comm/TensorInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ struct IndexToOffset {
return linearId;
}

#pragma unroll
for (int dim = XPU_MAX_TENSORINFO_DIMS - 1; dim >= 0; --dim) {
if (dim < info.dims) {
auto divider = at::detail::IntDivider<IndexType>(info.sizes[dim]);
auto divmod = divider.divmod(linearId);
linearId = divmod.div;
offset += divmod.mod * info.strides[dim];
}
for (int dim = info.dims - 1; dim > 0; --dim) {
IndexType curDimIndex = linearId % info.sizes[dim];
IndexType curDimOffset = curDimIndex * info.strides[dim];
offset += curDimOffset;
linearId /= info.sizes[dim];
}
return offset;
return offset + linearId * info.strides[0];
}
};

Expand Down

0 comments on commit 94937b0

Please sign in to comment.