Skip to content

[Refactor] Phaseout execution_backend ctypes#1510

Merged
LeiWang1999 merged 2 commits intotile-ai:mainfrom
LeiWang1999:refactor_ctypes_1223
Dec 23, 2025
Merged

[Refactor] Phaseout execution_backend ctypes#1510
LeiWang1999 merged 2 commits intotile-ai:mainfrom
LeiWang1999:refactor_ctypes_1223

Conversation

@LeiWang1999
Copy link
Member

@LeiWang1999 LeiWang1999 commented Dec 23, 2025

as title, because execution_backend cython shared same functionality for ctypes backend.

Summary by CodeRabbit

  • Refactor

    • Removed "ctypes" as a supported execution backend across the system; corresponding public API options and the ctypes kernel adapter export were removed.
  • Tests

    • Tests updated to use the Cython backend where they previously exercised ctypes; related ctypes-specific benchmarks/assertions removed.
  • Documentation

    • Autotuning guide updated to remove ctypes from backend options and wording clarified ("avoid context mixups").

✏️ Tip: You can customize this high-level summary in your review settings.

… of supported backends across multiple files. Update related documentation and tests to reflect this change, ensuring consistency in the autotuning and JIT compilation processes.
@github-actions
Copy link

👋 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
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

Removed the "ctypes" execution backend across the codebase: type hints and public API signatures were updated to exclude "ctypes", the CtypesKernelAdapter implementation and exports were deleted, tests and docs updated to use other backends, and related kernel/cache/autotuner/JIT wiring adjusted.

Changes

Cohort / File(s) Summary
Documentation
docs/programming_guides/autotuning.md
Removed "ctypes" from execution_backend alternatives; minor wording change in CUDA multi-GPU note.
Tests
testing/python/cpu/test_tilelang_cpu_gemm.py, testing/python/jit/test_tilelang_jit_gemm_cython.py
Replaced usages of execution_backend="ctypes" with "cython" and removed ctypes-specific benchmarking/latency paths.
Autotuner
tilelang/autotuner/param.py, tilelang/autotuner/tuner.py
Removed "ctypes" from CompileArgs.execution_backend and related signatures/docstrings.
Cache
tilelang/cache/__init__.py, tilelang/cache/kernel_cache.py
Removed "ctypes" from cached() and KernelCache method/type annotations and key generation parameters.
JIT public API
tilelang/jit/__init__.py, tilelang/jit/execution_backend.py
Removed "ctypes" from ExecutionBackend alias and public function/type Literals; updated backend lists per target (CUDA/HIP/CPU/fallback).
Kernel runtime
tilelang/jit/kernel.py
Removed ctypes from constructor/signatures and removed branches that selected/used CtypesKernelAdapter.
Adapter exports
tilelang/jit/adapter/__init__.py, tilelang/jit/adapter/ctypes/__init__.py
Stopped exporting CtypesKernelAdapter from package namespaces.
Adapter implementation
tilelang/jit/adapter/ctypes/adapter.py
Deleted the entire CtypesKernelAdapter implementation and file.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: phasing out the ctypes execution backend throughout the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 85.00% which is sufficient. The required threshold is 80.00%.
✨ 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: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0f80e5 and 7cffd56.

📒 Files selected for processing (1)
  • tilelang/jit/__init__.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tilelang/jit/init.py

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tilelang/jit/__init__.py (1)

183-184: Unreachable code detected.

Line 184 (return results) is dead code. The function always returns at line 183 inside the with block, making this statement unreachable.

🔎 Suggested fix
             else:
                 results[idx] = future.result()
         return results
-    return results
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e79bbcc and f0f80e5.

📒 Files selected for processing (13)
  • docs/programming_guides/autotuning.md
  • testing/python/cpu/test_tilelang_cpu_gemm.py
  • testing/python/jit/test_tilelang_jit_gemm_cython.py
  • tilelang/autotuner/param.py
  • tilelang/autotuner/tuner.py
  • tilelang/cache/__init__.py
  • tilelang/cache/kernel_cache.py
  • tilelang/jit/__init__.py
  • tilelang/jit/adapter/__init__.py
  • tilelang/jit/adapter/ctypes/__init__.py
  • tilelang/jit/adapter/ctypes/adapter.py
  • tilelang/jit/execution_backend.py
  • tilelang/jit/kernel.py
💤 Files with no reviewable changes (4)
  • tilelang/jit/adapter/init.py
  • testing/python/jit/test_tilelang_jit_gemm_cython.py
  • tilelang/jit/adapter/ctypes/init.py
  • tilelang/jit/adapter/ctypes/adapter.py
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-14T07:56:11.098Z
Learnt from: lucifer1004
Repo: tile-ai/tilelang PR: 1256
File: testing/python/jit/test_tilelang_jit_gemm_nvrtc.py:55-115
Timestamp: 2025-11-14T07:56:11.098Z
Learning: In `testing/python/jit/test_tilelang_jit_gemm_nvrtc.py`, the global function `tilelang_callback_cuda_postproc` registered via `tvm.register_global_func(..., override=True)` is intentionally not restored after the test completes, as the persistent behavior is expected.

Applied to files:

  • testing/python/cpu/test_tilelang_cpu_gemm.py
  • tilelang/jit/execution_backend.py
📚 Learning: 2025-12-18T04:50:00.512Z
Learnt from: silentCoder-dev
Repo: tile-ai/tilelang PR: 1464
File: testing/python/language/test_tilelang_language_rand.py:14-14
Timestamp: 2025-12-18T04:50:00.512Z
Learning: In `testing/python/language/test_tilelang_language_rand.py`, the TileLang kernel uses `blk_M = M` (single block) and calls `rng_rand()` four times per element to align results with the Triton implementation, which uses `blk_M = 128` (multiple blocks) and calls the RNG once per element. These differences compensate for internal RNG behavior differences between TileLang and Triton.

Applied to files:

  • testing/python/cpu/test_tilelang_cpu_gemm.py
🧬 Code graph analysis (2)
testing/python/cpu/test_tilelang_cpu_gemm.py (1)
tilelang/jit/__init__.py (2)
  • compile (49-115)
  • compile (347-373)
tilelang/jit/kernel.py (6)
tilelang/jit/adapter/nvrtc/adapter.py (1)
  • get_kernel_source (179-190)
tilelang/jit/adapter/cutedsl/adapter.py (1)
  • get_kernel_source (206-214)
tilelang/jit/adapter/tvm_ffi.py (2)
  • get_kernel_source (304-309)
  • get_host_source (292-296)
tilelang/jit/adapter/base.py (1)
  • get_kernel_source (89-93)
tilelang/jit/adapter/cython/adapter.py (1)
  • get_kernel_source (380-387)
tilelang/jit/param.py (1)
  • get_kernel_source (27-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
  • GitHub Check: Test for Python 3.12 with Nightly-ROCm-7.1 (on self-hosted-amd)
🔇 Additional comments (15)
tilelang/autotuner/tuner.py (1)

147-147: LGTM! Execution backend type narrowed consistently.

The removal of "ctypes" from the execution_backend Literal type in both the method signature (line 147) and the docstring (line 728) is consistent with the PR objective to phase out the ctypes backend.

Also applies to: 728-728

docs/programming_guides/autotuning.md (1)

296-296: LGTM! Documentation updated correctly.

The documentation correctly reflects the removal of the ctypes backend option from the execution_backend choices.

tilelang/jit/execution_backend.py (1)

38-47: LGTM! Backend lists updated consistently.

The removal of "ctypes" from all allowed backend lists (CUDA, HIP, CPU, and fallback) is complete and consistent. The NVRTC availability check logic remains unchanged, preserving the same runtime filtering behavior.

tilelang/cache/__init__.py (1)

22-22: LGTM! Cache interface updated correctly.

The execution_backend type annotation correctly excludes "ctypes", aligning with the broader removal across the codebase.

tilelang/autotuner/param.py (1)

52-52: LGTM! Autotuner parameter types updated correctly.

Both CompileArgs.execution_backend and _load_kernel_from_disk parameter types have been correctly updated to exclude "ctypes" while maintaining valid default values.

Also applies to: 268-268

tilelang/jit/kernel.py (1)

66-66: LGTM! JITKernel backend types and checks updated thoroughly.

All execution_backend type annotations and backend checks have been correctly updated to exclude "ctypes":

  • Constructor and from_database signatures updated (lines 66, 159)
  • Documentation updated (line 83)
  • Source retrieval methods updated (lines 447, 455)

The changes are comprehensive and consistent with the removal of the ctypes adapter.

Also applies to: 83-83, 159-159, 447-447, 455-455

tilelang/cache/kernel_cache.py (1)

51-51: LGTM! Kernel cache backend types updated consistently.

All execution_backend type annotations in KernelCache have been correctly updated to exclude "ctypes":

  • Class attribute (line 51)
  • _generate_key parameter (line 80)
  • cached parameter (line 126)
  • _load_kernel_from_disk parameter (line 392)

The changes maintain valid default values and are consistent throughout the class.

Also applies to: 80-80, 126-126, 392-392

testing/python/cpu/test_tilelang_cpu_gemm.py (1)

104-104: Cython backend is correctly configured for CPU target.

The change to use execution_backend="cython" is valid. The execution_backend.py module explicitly allows ["cython", "tvm_ffi"] for the "c" (CPU) target at lines 43-44, and cython is widely used throughout the codebase for CPU compilation.

tilelang/jit/__init__.py (7)

49-58: LGTM!

The execution_backend parameter correctly removes ctypes from the allowed backends. The remaining options are consistent with the PR objectives.


67-69: LGTM!

Docstring accurately reflects the updated execution_backend options.


118-129: LGTM!

The execution_backend parameter and docstring correctly updated to remove ctypes.


258-259: LGTM!

The execution_backend field type correctly updated to remove ctypes.


427-427: LGTM!

The ExecutionBackend type alias correctly updated. All decorator overloads that reference this alias will automatically reflect the change.


476-478: LGTM!

Docstring accurately reflects the updated execution_backend options.


519-567: LGTM!

The lazy_jit decorator correctly uses the ExecutionBackend type alias, which already reflects the ctypes removal.

@LeiWang1999
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LeiWang1999 LeiWang1999 merged commit 11f122e into tile-ai:main Dec 23, 2025
5 of 6 checks passed
@LeiWang1999 LeiWang1999 mentioned this pull request Dec 23, 2025
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