NVIDIA / NVIDIA/cutlass

ArraySubbyte::back() returns the wrong element when N does not fill its last storage unit

Open
#3,515 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CUTLASS C++
Dominant language
C++
Stars
10.5k
Forks
2.1k
Avg merge
3d 11h
Merged PRs (30d)
7

Description

Description

ArraySubbyte::back() (include/cutlass/array_subbyte.h ~lines 451-458) returns the last storage slot's highest sub-element rather than element N-1:

reference back() {
    return reference(storage + kStorageElements - 1, kElementsPerStoredItem - 1);
}

For any N that does not fill its final storage unit exactly, that slot position is padding, so back() returns an unrelated (often uninitialized) nibble/bit while a[N-1] holds the real last element. Verified by execution:

template <int N> void probe() {
    cutlass::Array<cutlass::int4b_t, N> a;
    for (int i = 0; i < N; ++i) a[i] = cutlass::int4b_t((i % 14) - 6);
    printf("N=%d a[%d]=%d back()=%d\n", N, N - 1, int(a[N-1]), int(a.back()));
}
// N=5:  a[4]=-2  back()=0    WRONG
// N=6:  a[5]=-1  back()=-1   ok      (6 % 4 != 1 case that happens to align)
// N=9:  a[8]=2   back()=-1   WRONG
// N=3:  a[2]=-4  back()=-1   WRONG

front() is correct (at(0)), so the asymmetry is easy to miss.

Same file, two more latent breakages in code paths that fail to compile when instantiated:

  • const_iterator's ++/-- (~lines 315-373) declare iterator& return types but build a const_iterator; comparisons take iterator const&, so iterating a const array cannot compile.
  • (related family) PredicateVector::Iterator::operator- has the same construct-ConstIterator-return-Iterator shape, reported separately.
Suggested fix

Implement back() via at(N - 1) like front() does for element 0, and give const_iterator self-typed returns/comparisons so it is usable.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in include/cutlass/array_subbyte.h around ArraySubbyte::back(), front(), and the const_iterator definitions near lines 315-373. Inspect how at(N - 1) and const iterator operations are implemented, then compile focused uses covering partially filled storage and iteration over a const array. Done means back() returns element N-1 and const iteration compiles with correct self-typed returns and comparisons.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.