Skip to content

[Language] Unify contiguous stride construction using a single implem… - #3016

Open
jjppp wants to merge 1 commit into
tile-ai:mainfrom
jjppp:remove-construct-strides
Open

[Language] Unify contiguous stride construction using a single implem…#3016
jjppp wants to merge 1 commit into
tile-ai:mainfrom
jjppp:remove-construct-strides

Conversation

@jjppp

@jjppp jjppp commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

The Python frontend had 3 independent implementations of the same row-major stride computation, yet only tilelang/language/proxy.py:TensorProxy._construct_strides returns (1,) when tensor with a rank-0 shape is passed in.

This patch unifies the three python implementation of construct_strides. The single source of truth now accepts any Sequence and iterates via reversed(shape), so it can also handle, e.g., FFI arrays returned by buffer.shape. allow_prim_expr is kept as-is.
The rest two delegate to construct_strides, using a function-local import.
This matches the existing lazy-import convention already used elsewhere in proxy.py.

Fixes #3015

Summary

  • Unified row-major stride construction in construct_strides.
  • Added support for any Sequence, including FFI-backed shapes.
  • Preserved allow_prim_expr behavior and rank-0 empty strides.
  • Updated TensorProxy and retrieve_stride to use the shared implementation.
  • Fixed scalar T.Tensor((), dtype) handling and valid S[()] stores.
  • Added tests for static, symbolic, empty, restricted-PrimExpr, and rank-0 tensor cases.
  • Added CUDA coverage for rank-0 tensor compilation and runtime execution.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d9448c55-29e5-4974-9014-5f5f63890fa1

📥 Commits

Reviewing files that changed from the base of the PR and between ddc2c54 and f905406.

📒 Files selected for processing (4)
  • testing/python/language/test_tilelang_language_construct_strides.py
  • tilelang/language/eager/utils.py
  • tilelang/language/proxy.py
  • tilelang/utils/language.py

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

construct_strides now accepts general sequences and preserves rank for empty and symbolic shapes. TensorProxy and retrieve_stride use the shared utility. Tests cover stride consistency and rank-0 CUDA tensor execution.

Changes

Stride construction consistency

Layer / File(s) Summary
Generalized stride construction
tilelang/language/eager/utils.py
construct_strides accepts sequence-shaped inputs and documents contiguous row-major and rank-0 behavior.
Shared stride consumers
tilelang/language/proxy.py, tilelang/utils/language.py
TensorProxy.__call__ and retrieve_stride delegate stride calculation to construct_strides.
Stride and rank validation
testing/python/language/test_tilelang_language_construct_strides.py
Tests cover static, symbolic, empty, restricted-PrimExpr, cross-consumer, rank-0, and CUDA execution behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to f9054

This change centralizes stride construction without any identified current-head correctness or production risk; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: leiwang1999, oraluben

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: unifying contiguous stride construction.
Linked Issues check ✅ Passed The changes unify stride construction, preserve rank-0 empty strides, and add compilation and runtime tests for issue #3015.
Out of Scope Changes check ✅ Passed The implementation and tests remain focused on shared stride construction and rank-0 tensor support described in issue #3015.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Fuzzer][ice-on-valid-code] Rank-0 T.Tensor((), dtype) crashes FlattenBuffer instead of compiling like T.Buffer((), dtype)

1 participant