PredicateVector::is_zero ignores the last storage word when kBytes is a multiple of sizeof(Storage)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.5k
- Forks
- 2.1k
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 7
Description
Description
PredicateVector::is_zero() (include/cutlass/predicate_vector.h ~line 515) masks the last storage word with computeLastWordMask(), which returns 0 whenever the byte count is an exact multiple of sizeof(Storage):
constexpr Storage computeLastWordMask() {
Storage mask(0);
for (int byte = 0; byte < kBytes % sizeof(Storage); ++byte)
mask |= (kByteMask << (byte * 8));
return mask;
}
For PredicateVector<32> (kPredicatesPerByte=4): kBytes == 8, sizeof(Storage) == 4, so kBytes % sizeof(Storage) == 0 and last_word_mask == 0 - the entire second storage word is excluded from is_zero(). Bits 16..31 can be set and is_zero() still reports true:
kBytes=8 kWordCount=2 sizeof(Storage)=4
is_zero with bits 16..31 set: 1 (expected 0)
The same configuration is reachable for any kPredicates where ceil(kPredicates/4) is a nonzero multiple of 4 (e.g. 16, 32, 48, 64 predicates with default parameters).
Related latent defect in the same header: Iterator::operator- (~line 278) constructs a ConstIterator ret(*this); ... return ret; but declares the return type Iterator, which does not compile if instantiated; and computeLastWordMask()'s loop bound also means configurations where the last word holds fewer than four predicate bytes are handled correctly only by that mask path.
Suggested fix
When kBytes % sizeof(Storage) == 0, the last word should use the full-word mask (computeWordMask()), i.e. select the mask based on whether the last word is partially occupied, for example:
constexpr Storage last_word_mask =
(kBytes % sizeof(Storage) != 0) ? computeLastWordMask() : computeWordMask();
result |= (storage(kWordCount - 1) & last_word_mask);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in include/cutlass/predicate_vector.h around PredicateVector::is_zero() and computeLastWordMask(), then reproduce the PredicateVector<32> case described in the issue with bits 16..31 set. Done means is_zero() reports false for nonzero words, including exact storage-word multiples; also check the mentioned Iterator::operator- return type if addressing that related defect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100