Skip to content

Conversation

@davorchap
Copy link

@davorchap davorchap commented Oct 6, 2025

Summary by CodeRabbit

  • New Features

    • Experimental Tenstorrent backend target recognition (opt-in).
    • Enhanced LLVM-only build path with system LLVM detection and clearer CUDA/ROCm gating.
  • Documentation

    • Comprehensive Tenstorrent backend guides, project plan, GPU vs Tenstorrent comparison, kernel authoring notes, CI documentation, and repository guidance.
  • CI

    • New Tenstorrent Backend CI with lint/format, build/test, and static analysis; improved caching for faster runs.
  • Tests

    • Added tests validating Tenstorrent target registration and basic lowering contracts.
  • Chores

    • Added mypy to development requirements.

davorchap and others added 30 commits September 30, 2025 14:11
Add Tenstorrent matmul MVP project plan
- Replace placeholder return with NotImplementedError for clearer intent
- Add target validation to ensure Tenstorrent target is used
- Add comprehensive docstring with Args, Returns, and Raises sections
- Update tests to expect NotImplementedError instead of placeholder artifact
- Add new test for target validation

This addresses PR feedback to make the stub implementation more robust
and prevent runtime errors from invalid placeholder returns.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Create dedicated CI workflow for Tenstorrent backend validation
- Run on pull requests affecting TT backend code
- Build TileLang with CUDA backend using TVM submodule
- Execute Tenstorrent target registration tests
- Include lint and type checking steps
- Use NVIDIA PyTorch container for CUDA dependencies

This ensures PR changes to the Tenstorrent backend are validated
before merging, catching build and test failures early.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Remove unused exception variable in test import
- Update docstring to clarify stub behavior (validates then raises)
- Add explicit unused parameter assignments with explanatory comment
- Clarify that Returns section indicates function never returns successfully

This addresses Copilot AI review suggestions for code clarity.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Split tilelang.utils.target imports onto separate lines
- Move TENSTORRENT_TARGET import after determine_target
- Group TT-related imports at the end

This improves code clarity and makes diffs cleaner when adding
new imports in the future.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Remove Returns section from stub docstring, clarify in Raises section
- Extract target kind extraction logic to get_target_kind() helper function
- Add exception message to pytest.skip for better error reporting
- Use helper function in both engine/lower.py and tt/lower.py

This reduces code duplication and improves error diagnostics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add Tenstorrent engine adapter stub
Black formatter requires long lines to be wrapped. Applied black formatting
to test_target_registration.py to fix CI lint failure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Set DEBIAN_FRONTEND=noninteractive and TZ=Etc/UTC to prevent
apt-get from prompting for timezone configuration during package
installation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Run format.sh to apply yapf formatting to modified files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
davorchap and others added 21 commits October 4, 2025 11:33
Cache TVM build artifacts based on the TVM submodule commit hash.
This significantly reduces CI build time for subsequent runs as long
as the TVM submodule hasn't changed.

Cache key includes:
- TVM submodule commit hash (primary factor)
- Runner OS

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use the project's standard format.sh script instead of individual
black and ruff checks. This ensures CI uses the same formatting
rules as local development (yapf, ruff, codespell, clang-format).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
CI improvements: Add TVM caching and yapf formatting
Cache pip and apt packages to speed up CI runs:
- Lint job: Cache pip packages from requirements-lint.txt
- Static analysis: Cache pip packages for mypy
- Build job: Cache apt packages and pip packages

This reduces dependency installation time on subsequent CI runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Document the CI setup including:
- Job descriptions (lint, build-and-test, static-analysis)
- Container usage rationale
- Comprehensive caching strategy
- Local testing instructions
- Performance characteristics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Create a requirements file for mypy to ensure consistent pip caching
behavior in the static-analysis CI job. This addresses Copilot feedback
about missing cache-dependency-path.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Update documentation to reflect the use of requirements-mypy.txt
for consistent pip caching in the static-analysis job.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Install test dependencies from requirements-test.txt instead of
directly installing pytest and pytest-xdist. This ensures the cache
key correctly references an existing requirements file.

Addresses Copilot feedback about missing requirements-test.txt.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Switch from NVIDIA PyTorch container to plain Ubuntu runner with LLVM
backend. This significantly reduces CI setup time since:
- We're only running CPU tests (not GPU tests)
- Don't need CUDA toolkit or PyTorch dependencies
- LLVM backend is sufficient for testing Tenstorrent integration

Changes:
- Remove NVIDIA container, use ubuntu-latest runner
- Build TVM with LLVM instead of CUDA
- Update cache key from cuda to llvm
- Use setup-python with built-in pip caching
- Update documentation to reflect lighter setup

GPU/CUDA testing can be added later when needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace incorrect package names:
- llvm-dev → llvm
- libpolly-dev → removed (not needed)
- Add standard build dependencies: libedit-dev, libxml2-dev, zlib1g-dev

These are the same dependencies used in the original NVIDIA container setup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace heavy NVIDIA container with lightweight Ubuntu runner
TileLang's setup.py requires either CUDA_HOME or ROCM_HOME to be set,
even when building with LLVM. Set a dummy CUDA_HOME=/usr to satisfy
this check in the CI environment.

This is a workaround until setup.py is updated to support LLVM-only
builds without requiring GPU runtime environments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fix CI: Set dummy CUDA_HOME for setup.py
Configure setup.py for LLVM-only build:
- USE_LLVM=true: Enables LLVM build path in setup.py
- CUDA_HOME=/usr: Dummy value to pass initial validation check
- WITH_COMMITID=False: Skips nvcc check during version generation

This properly configures the LLVM build without requiring actual CUDA.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fix CI: Disable WITH_COMMITID to skip nvcc check
Add cache hit logging to Tenstorrent CI workflow
* Update Tenstorrent CI workflow: improve caching, update actions, add concurrency and ccache

* Add copilot-instructions.md to customize Copilot code reviews

* Fix inefficient glob pattern in ccache key

Address Copilot feedback: replace expensive `hashFiles('3rdparty/tvm/**', 'tilelang/**')`
with simpler `hashFiles('CMakeLists.txt')`.

Rationale:
- ccache handles file-level caching internally based on content
- Cache key should represent build config, not all source files
- Hashing entire directories with ** is computationally expensive
- CMakeLists.txt changes indicate build config changes that should invalidate cache
- Added -v1 suffix for manual cache invalidation when needed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix TVM cache not being saved on job failure

Split cache into separate restore/save steps to ensure TVM build
artifacts are cached even when the job fails. This prevents rebuilding
TVM from scratch on every run.

Changes:
- Use actions/cache/restore@v4 for restoring TVM cache
- Use actions/cache/save@v4 with if: always() for saving TVM cache
- Only save if cache was not hit (prevents duplicate cache errors)
- Remove redundant full build directory cache

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Update CI docs to explain cache save-on-failure strategy

* Fix Install TileLang by adding back required env vars

Restore PYPI_BUILD=true and CUDA_HOME=/usr which were accidentally
removed when adding ccache support. These are needed for pip install
to work in LLVM-only environment without nvcc.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix nvcc check to handle missing CUDA toolkit gracefully

Address Codex feedback: setup.py now checks if nvcc exists before
attempting to run it, preventing FileNotFoundError when CUDA toolkit
is not installed.

Changes:
- Add os.path.exists() check for nvcc before calling get_nvcc_cuda_version()
- If nvcc is missing, skip CUDA version detection instead of crashing
- Remove workaround env vars (PYPI_BUILD, dummy CUDA_HOME) from CI
- Simplify Install TileLang step to only set USE_LLVM=true

This allows pip install to work in LLVM-only environments without
requiring CUDA toolkit or environment variable workarounds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Update CI docs to explain nvcc check fix

* Address remaining Copilot feedback on PR #13

Fix two remaining issues identified by Copilot code review:

1. Improve ccache error handling:
   - Check if ccache is available before running it
   - Provide clear message when ccache is not found
   - Avoid hiding legitimate errors with || true

2. Fix boolean comparison in cache condition:
   - Change != 'true' to != true (without quotes)
   - GitHub Actions outputs are boolean values, not strings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Allow LLVM-only builds without CUDA/ROCM validation

Fix setup.py to skip CUDA_HOME validation when USE_LLVM=true.
The early validation at line 68-70 was requiring CUDA_HOME even for
LLVM-only builds, causing pip install to fail in CI.

Changes:
- Wrap CUDA/ROCM validation checks in `if not USE_LLVM:` condition
- Allow setup.py to proceed when only USE_LLVM=true is set
- Maintains strict validation for CUDA/ROCM builds

This allows LLVM-only CI builds to complete without CUDA toolkit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Apply yapf formatting to setup.py

* Use system llvm-config when available instead of downloading LLVM

Fix pip install failure by preferring system llvm-config over downloading
LLVM 10.0.1. The downloaded LLVM requires libtinfo.so.5 which isn't
available on Ubuntu 24.04.

Changes:
- Check for system llvm-config using shutil.which()
- Use system LLVM if llvm-config is found in PATH
- Fall back to downloading LLVM if system version not available
- Prevents "libtinfo.so.5: cannot open shared object file" error

This allows pip install to work with system LLVM packages installed via apt.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix TVM cache paths to include subdirectories

Cache paths were missing subdirectories where .so files are actually built.
Updated to cache:
- build/tvm/ (contains libtvm*.so files)
- build/libtilelang*.so (tilelang shared libraries)
- build/3rdparty/ (TVM dependencies)

This fixes the "Path(s) specified in the action for caching do(es) not exist"
warning and ensures TVM artifacts are properly cached for subsequent runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Install TVM Python package before running tests

Tests were skipped because TVM module wasn't importable. The TVM C++
libraries were built but the Python bindings weren't installed.

Changes:
- Install TVM Python package from 3rdparty/tvm/python before installing TileLang
- This makes `import tvm` work in tests
- Fixes "collected 0 items / 1 skipped" test failure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Set TVM_LIBRARY_PATH for TVM Python install

TVM Python setup.py needs to find libtvm.so and libtvm_runtime.so
which are in build/tvm/ directory. Set TVM_LIBRARY_PATH environment
variable to tell TVM where to find these libraries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Set LD_LIBRARY_PATH for test runs to find TVM libraries

Tests were failing to import TVM because libtvm.so was not in the
library search path. Set LD_LIBRARY_PATH to include build/tvm directory
where the TVM libraries are located.

This fixes the RuntimeError: Cannot find libraries error during test collection.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
* Update CI documentation with implementation details

Document all the key implementation decisions and final approach:
- ccache integration for faster compilation
- System LLVM usage (avoids libtinfo.so.5 issues)
- TVM Python package installation with TVM_LIBRARY_PATH
- LD_LIBRARY_PATH setup for test runtime
- Cache split strategy (restore/save with if: always())
- Updated performance metrics based on actual runs
- Added Key Design Decisions section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Update docs/tenstorrent/CI.md

Co-authored-by: Copilot <[email protected]>

* Update docs/tenstorrent/CI.md

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Copilot <[email protected]>
This file provides comprehensive guidance to Claude Code when working
with the TileLang repository, including:

- Build commands for different backends (CUDA, ROCm, LLVM)
- Test execution instructions
- Code architecture overview focusing on Tenstorrent backend
- Development workflow and CI/CD information
- Key technical details about the grid-to-persistent mapping

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

github-actions bot commented Oct 6, 2025

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

Please remember to run bash format.sh 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
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds Tenstorrent backend scaffolding (target registration, lowering entry, exports, tests), introduces a new CI workflow (lint, build/test, static analysis), updates setup.py for LLVM-first builds, and substantially expands documentation (README and Tenstorrent guides). Includes mypy tooling and a Copilot review guide. No functional TT lowering yet; stub raises NotImplementedError.

Changes

Cohort / File(s) Summary
CI workflow and tooling
.github/workflows/tenstorrent-ci.yml, .github/copilot-instructions.md, requirements-mypy.txt
Adds Tenstorrent CI with lint/format, build/test with caches, and mypy static analysis; introduces Copilot contribution guidance; pins mypy for type checking.
Build configuration
setup.py
Refactors to prefer LLVM path; guards CUDA/ROCM checks behind non-LLVM builds; system llvm-config detection and fallback download; logging tweaks; nvcc checks gated.
Engine: Tenstorrent integration
tilelang/engine/lower.py, tilelang/engine/__init__.py, tilelang/engine/tt/__init__.py, tilelang/engine/tt/lower.py, tilelang/utils/target.py
Adds TENSTORRENT target detection, exports, and a lowering delegation branch; introduces TT lowering stub raising NotImplementedError; new helper to get target kind; explicit backend-enabled guard in determine_target; updates available targets.
Tests
testing/python/tt/test_target_registration.py
Adds tests for TT target availability, determine_target behavior, backend gating, and lowering invocation errors.
README overhaul
README.md
Rewrites project description and plans; adds multi-phase Tenstorrent backend design, compiler/codegen pipeline notes, runtime integration, workflow, risks, and contribution guidance.
Documentation: Tenstorrent guides
CLAUDE.md, docs/tenstorrent/CI.md, docs/tenstorrent/GPU_vs_Tenstorrent.md, docs/tenstorrent/kernel_authoring_comparison.md
Adds architecture, CI, and kernel authoring comparisons between GPU and Tenstorrent; contextual development notes.
Documentation: Project plan and workstreams
docs/tenstorrent/project_1.md, docs/tenstorrent/project_1_prompt.md, docs/tenstorrent/workstream1/ws1_*
Introduces TT backend MVP project plan, prompt, and Workstream 1 docs (target registration, engine adapter, lower hook, default annotation helper).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant Engine as tilelang.engine.lower
  participant TT as tilelang.engine.tt.lower
  Note over User,Engine: Lowering entry

  User->>Engine: lower(mod, params, target, ...)
  Engine->>Engine: get_target_kind(target)
  alt target == "tenstorrent"
    Engine->>TT: lower(mod, params, target, ...)
    TT-->>Engine: NotImplementedError (stub)
    Engine-->>User: Propagate error
  else Non-TT targets
    Engine->>Engine: Standard lowering pipeline
    Engine-->>User: CompiledArtifact
  end
Loading
sequenceDiagram
  autonumber
  participant GH as GitHub
  participant Lint as Job: lint-and-format
  participant Build as Job: build-and-test
  participant SA as Job: static-analysis

  GH-->>Lint: Trigger (PR/Push paths)
  GH-->>Build: Trigger (PR/Push paths)
  GH-->>SA: Trigger (PR/Push paths)

  Note over Lint: Checkout → Setup Py 3.10 → Install lint reqs → format.sh --check
  Note over Build: Checkout → Setup Py + caches → ccache/TVM cache → CMake build (LLVM) → Install → Tests → Save cache
  Note over SA: Checkout → Setup Py → Install mypy → Type check (ignore missing imports)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • LeiWang1999
  • xysmlx
  • chengyupku

Poem

A rabbit taps the CI drum—thum-thum!
TT paths appear, yet lowering’s still yum-yum-to-come.
LLVM carrots in a cache-lined row,
Type hints sprout where mypy winds blow.
README meadows freshly mown—
Soon, kernels hop from plans well-sown. 🥕🐇

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3aecab8 and 9afe7f9.

📒 Files selected for processing (22)
  • .github/copilot-instructions.md (1 hunks)
  • .github/workflows/tenstorrent-ci.yml (1 hunks)
  • CLAUDE.md (1 hunks)
  • README.md (1 hunks)
  • docs/tenstorrent/CI.md (1 hunks)
  • docs/tenstorrent/GPU_vs_Tenstorrent.md (1 hunks)
  • docs/tenstorrent/kernel_authoring_comparison.md (1 hunks)
  • docs/tenstorrent/project_1.md (1 hunks)
  • docs/tenstorrent/project_1_prompt.md (1 hunks)
  • docs/tenstorrent/workstream1/ws1_default_annotation_helper.md (1 hunks)
  • docs/tenstorrent/workstream1/ws1_engine_adapter.md (1 hunks)
  • docs/tenstorrent/workstream1/ws1_lower_hook.md (1 hunks)
  • docs/tenstorrent/workstream1/ws1_target_registration.md (1 hunks)
  • docs/tenstorrent/workstream1/ws1_target_registration_test.md (1 hunks)
  • requirements-mypy.txt (1 hunks)
  • setup.py (3 hunks)
  • testing/python/tt/test_target_registration.py (1 hunks)
  • tilelang/engine/__init__.py (1 hunks)
  • tilelang/engine/lower.py (2 hunks)
  • tilelang/engine/tt/__init__.py (1 hunks)
  • tilelang/engine/tt/lower.py (1 hunks)
  • tilelang/utils/target.py (2 hunks)

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 and usage tips.

@davorchap davorchap closed this Oct 6, 2025
@davorchap davorchap deleted the add-claude-md branch October 6, 2025 05:05
@davorchap davorchap restored the add-claude-md branch October 6, 2025 05:07
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.

1 participant