NVIDIA / NVIDIA/cutlass

TensorNHWC::inverse device path diverges from host path when strides are not w-multiples

Open Beginner friendly
#3,519 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

TensorNHWC::inverse(LongIndex) (include/cutlass/layout/tensor.h ~lines 158-188) computes different results on device and host whenever stride_h or stride_n is not a multiple of stride_w.

The device branch computes

c = int(index % static_cast<int>(stride_[0]));   // provisional, before any division
...
fast_divmod(n, tmp, index, stride_[2], hw_mul, hw_shr);
fast_divmod(h, w, tmp,  stride_[1], w_mul, w_shr);
fast_divmod(w, tmp, w,  stride_[0], c_mul, c_shr);   // final remainder -> tmp, discarded

The channel coordinate is taken from the pre-division remainder expression and never updated; the actual post-divide residual lands in tmp and is thrown away. The host branch derives c = residual % stride_[0] from the final residual, which is the correct inverse of the packed/strided forward mapping.

Simulating the verbatim device branch with cutlass's own find_divisor/fast_divmod for strides (6, 15, 45) and index = 15 gives (n=0, h=1, w=0, c=3) where the host path returns (n=0, h=1, w=0, c=0). The only in-tree caller (test/unit/layout/tensor_nhwc.cu) uses packed strides where both paths agree, so the divergence has gone unnoticed. Minor adjacent note: find_divisor also assumes positive strides.

Suggested fix

Set c from the final fast_divmod remainder (the value currently discarded into tmp), matching the host branch.

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/layout/tensor.h around TensorNHWC::inverse(LongIndex), then inspect test/unit/layout/tensor_nhwc.cu. Add coverage for non-packed strides such as (6, 15, 45), verify host and device inverses return the same coordinates, and run the tensor NHWC layout tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.