Skip to content

[Refactor] Move backend stubs out of codegen#2164

Merged
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
LeiWang1999:refactor/backend-stubs-layout
May 7, 2026
Merged

[Refactor] Move backend stubs out of codegen#2164
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
LeiWang1999:refactor/backend-stubs-layout

Conversation

@LeiWang1999
Copy link
Copy Markdown
Member

@LeiWang1999 LeiWang1999 commented May 7, 2026

Summary

  • Move CUDA and ROCm stub libraries out of backend codegen directories into backend-level stubs directories.
  • Keep stub sources separate from code generation sources while preserving build and link behavior.

Changes

  • Relocated CUDA stubs to src/backend/cuda/stubs and ROCm stubs to src/backend/rocm/stubs.
  • Updated CMake targets and CUDA include paths to use the new locations.
  • Refreshed stub documentation and ROCm test comments to point at the current paths.

Validation

  • ./format.sh
  • cmake --build build -j$(nproc)

Notes

  • The local build configuration has USE_ROCM=OFF, so HIP stub targets were not compiled during local validation.

Summary by CodeRabbit

  • Documentation

    • Updated documentation to reflect current backend library organization.
  • Chores

    • Reorganized internal stub library structure across CUDA and AMD backends.
    • Expanded test coverage for AMD HIP kernel code generation scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c626c110-08fc-4e15-bd21-bcbd9cdc503d

📥 Commits

Reviewing files that changed from the base of the PR and between 3898336 and eed61f5.

📒 Files selected for processing (17)
  • docs/runtime_internals/stubs.md
  • src/backend/cuda/CMakeLists.txt
  • src/backend/cuda/stubs/cuda.cc
  • src/backend/cuda/stubs/cuda.h
  • src/backend/cuda/stubs/cudart.cc
  • src/backend/cuda/stubs/dynlib.h
  • src/backend/cuda/stubs/nvrtc.cc
  • src/backend/cuda/stubs/vendor/cuda.h
  • src/backend/rocm/CMakeLists.txt
  • src/backend/rocm/stubs/hip.cc
  • src/backend/rocm/stubs/hip.h
  • src/backend/rocm/stubs/hiprtc.cc
  • src/backend/rocm/stubs/vendor/hip_runtime.h
  • src/op/builtin.cc
  • src/op/utils.h
  • src/runtime/runtime.cc
  • testing/python/amd/test_tilelang_hip_codegen.py

📝 Walkthrough

Walkthrough

This PR relocates CUDA and ROCm stub implementation files from codegen/stubs/ subdirectories to top-level stubs/ directories within their respective backends, updates all CMake build configurations and include paths throughout the codebase accordingly, and extends HIP codegen test coverage.

Changes

Stub Source Relocation and Integration

Layer / File(s) Summary
CUDA Stub Build Configuration
src/backend/cuda/CMakeLists.txt
cuda_stub, cudart_stub, and nvrtc_stub targets now compile from src/backend/cuda/stubs/{cuda,cudart,nvrtc}.cc instead of src/backend/cuda/codegen/stubs/.
ROCm Stub Build Configuration
src/backend/rocm/CMakeLists.txt
hip_stub and hiprtc_stub targets now compile from src/backend/rocm/stubs/{hip,hiprtc}.cc instead of src/backend/rocm/codegen/stubs/.
CUDA Stub Header Updates
src/backend/cuda/stubs/{cuda.h,vendor/cuda.h}
Include guard error messages and usage documentation are updated to reference backend/cuda/stubs/cuda.h instead of target/stubs/cuda.h.
ROCm Stub Header Updates
src/backend/rocm/stubs/{hip.h,hiprtc.cc,vendor/hip_runtime.h}
File comments and include guard messages updated to reference backend/rocm/stubs/hip.h and clarified vendor header documentation stating it is to be included only via the main stub header.
Source File Include Path Updates
src/op/{builtin.cc,utils.h}, src/runtime/runtime.cc
Include directives switched from backend/cuda/codegen/stubs/cuda.h to backend/cuda/stubs/cuda.h.
Documentation Updates
docs/runtime_internals/stubs.md
Implementation section updated to state CUDA stubs are in src/backend/cuda/stubs/ and ROCm stubs in src/backend/rocm/stubs/.
HIP Codegen Tests
testing/python/amd/test_tilelang_hip_codegen.py
Test documentation header and assertions updated to reference new ROCm backend stub locations and validate T.sync_grid() cooperative-groups synchronization code generation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • tile-ai/tilelang#2114: Directly related; both touch backend CMake stub wiring and source path configurations for CUDA/ROCm stub targets.
  • tile-ai/tilelang#1867: Directly related; both modify CUDA/ROCm HIP stub implementations and build targets with CMake and include path updates.
  • tile-ai/tilelang#2121: Related; both refactor CUDA/ROCm stub locations and update build/include paths for backend configurations.

Suggested labels

enhancement

Suggested reviewers

  • oraluben
  • XuehaiPan

🐰 Stubs once lived in shadows deep,
In codegen dark, where paths would creep,
But now they're home, where backends dwell,
In organized stubs, arranged quite well!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Microsoft Presidio Analyzer (2.2.362)
src/backend/cuda/stubs/vendor/cuda.h

Microsoft Presidio Analyzer failed to scan this file


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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

👋 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! 🚀

@LeiWang1999 LeiWang1999 changed the title [tilelang] Move backend stubs out of codegen [Refactor] Move backend stubs out of codegen May 7, 2026
@LeiWang1999 LeiWang1999 merged commit 0fdd0f8 into tile-ai:main May 7, 2026
4 of 6 checks passed
Calaweh pushed a commit to Calaweh/tilelang that referenced this pull request May 20, 2026
* Move backend stubs out of codegen

* lint fix
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