Skip to content

[Cleanup] Replace root reproducers with CPU regression coverage - #2878

Merged
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
GY-Bai:cleanup/2875-root-reproducers-cpu-pytest
Aug 5, 2026
Merged

[Cleanup] Replace root reproducers with CPU regression coverage#2878
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
GY-Bai:cleanup/2875-root-reproducers-cpu-pytest

Conversation

@GY-Bai

@GY-Bai GY-Bai commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Problem

PR #2768 and PR #2770 added reproducer_vec_type.py and
reproducer_metal_address_space.py at the repository root while addressing two
failures encountered during the initial Apple M2 bring-up.

Those files do not belong at the repository root:

  • reproducer_metal_address_space.py is empty and provides no regression
    coverage.
  • reproducer_vec_type.py is a standalone executable script rather than a
    pytest test under testing/python.
  • The vector reproducer validates addition only, although PR [BugFix] Add arithmetic operators to vec_type in common.h for CPU codegen #2768 added
    vec_type support for addition, subtraction, multiplication, and division.

Issue #2875 correctly points out that regression coverage should live in the
project's test hierarchy instead of leaving standalone reproducers in the root
directory.

Root-cause trace

The CPU failure covered by reproducer_vec_type.py follows this path:

T.Parallel
    ↓
vectorized TIR
    ↓
CPU C codegen
    ↓
generated float4 arithmetic
    ↓
vec_type<T, N> operators in src/tl_templates/cpp/common.h

On arm64 targets, the generated source contains expressions such as:

*(float4*)(Add + (i * 4)) =
    (*(float4*)(A + (i * 4)) + *(float4*)(B + (i * 4)));

Before PR #2768, vec_type<T, N> did not define the required binary arithmetic
operators. The generated C++ therefore failed to compile with errors such as:

invalid operands to binary expression
('float4' (aka 'vec_type<float, 4>') and 'float4')

The implementation from PR #2768 is already present in
src/tl_templates/cpp/common.h. The remaining problem here is the location and
completeness of its regression coverage, not another implementation defect.

The Metal file is a separate case. It is empty, so deleting it removes no test
coverage. The original PR #2770 Metal workaround is being superseded by the
type-driven codegen fix and dedicated Metal tests in PR #2824.

Fix

  • Remove the empty root-level reproducer_metal_address_space.py.
  • Remove the standalone root-level reproducer_vec_type.py.
  • Add testing/python/cpu/test_tilelang_cpu_vec_type.py as the permanent CPU
    regression test for PR [BugFix] Add arithmetic operators to vec_type in common.h for CPU codegen #2768.
  • Exercise +, -, *, and / through four actual T.Parallel loops.
  • Assert that lowering reaches the vectorized float4 C-codegen path and emits
    all four binary operators between vector operands.
  • Compile the generated CPU source through TileLang's C/Cython execution path,
    execute it, and compare all four outputs with Torch references.
  • Keep division inputs away from zero so the numerical check tests codegen
    correctness rather than exceptional floating-point behavior.

This PR intentionally does not change common.h, Metal codegen, runtime code,
or public APIs. It preserves the implementation merged in PR #2768 and replaces
only the temporary root-level artifacts with repository-integrated coverage.

Relationship to the earlier PRs

The ownership is therefore disjoint:

Original problem Functional implementation Permanent regression coverage
PR #2768 CPU vec_type arithmetic src/tl_templates/cpp/common.h from PR #2768 testing/python/cpu/test_tilelang_cpu_vec_type.py in this PR
PR #2770 Metal address spaces Type-driven Metal codegen in PR #2824 testing/python/metal/test_metal_address_space.py in PR #2824

Tests

Run on a MacBook Air with Apple M2, macOS 15.6.1, arm64:

python -m pytest testing/python/cpu/test_tilelang_cpu_vec_type.py -q -ra
# 2 passed

python -m pytest testing/python/cpu -q -ra
# 24 passed

pre-commit run --all-files
# All hooks passed.

The same new test file was also run against the TileLang 0.1.12 wheel to verify
that it is sensitive to the original regression:

# 1 failed, 1 passed
# The execution test fails during C++ compilation with four
# "invalid operands to binary expression" errors, one each for +, -, *, and /.

The source-inspection test still passes on 0.1.12 because lowering already
reaches float4; it is the subsequent C++ compilation that correctly exposes
the missing operators. On the current implementation, lowering, compilation,
execution, and numerical validation all pass.

Scope

D  reproducer_metal_address_space.py
D  reproducer_vec_type.py
A  testing/python/cpu/test_tilelang_cpu_vec_type.py

Three files are changed: 87 insertions and 37 deletions. There are no Metal
codegen changes, no vec_type implementation changes, and no fallback or
compatibility path.

Summary

Closes #2875 (Issue).

…ile-ai#2875)

Remove the root-level reproducer scripts and add a proper pytest under
testing/python/cpu covering vectorized vec_type arithmetic (+ - * /) on
the CPU C target: the generated source must reach a float4 expression,
compile as C++, and execute with numerically correct results.
@github-actions

github-actions Bot commented Aug 5, 2026

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 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The standalone vector arithmetic reproducer was deleted. A CPU regression test now validates vectorized addition, subtraction, multiplication, and division through C code generation and compiled execution.

Changes

CPU vector arithmetic regression

Layer / File(s) Summary
Vector kernel and code-generation checks
testing/python/cpu/test_tilelang_cpu_vec_type.py, reproducer_vec_type.py
Adds the vec_arith kernel and checks that C lowering emits float4 operations for all four arithmetic operators. Removes the standalone reproducer.
Compiled CPU execution validation
testing/python/cpu/test_tilelang_cpu_vec_type.py
Compiles and runs the CPU kernel with nonzero divisors, then compares all outputs with PyTorch references.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR removes root-level reproducers and adds regression coverage under testing/python, satisfying issue #2875.
Out of Scope Changes check ✅ Passed The changes are limited to removing root-level reproducer code and adding related CPU regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing root-level reproducers with CPU regression test coverage.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@testing/python/cpu/test_tilelang_cpu_vec_type.py`:
- Around line 73-79: Update the tensor allocations in the vec_arith test around
a, b, add, sub, mul, and div to explicitly use dtype=torch.float32 and
device="cpu". Preserve the existing divisor offset and avoid changing PyTorch
process-wide defaults.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 391a2223-c3b8-41c6-9464-e3336a43884c

📥 Commits

Reviewing files that changed from the base of the PR and between dd9c20d and 4ded68e.

📒 Files selected for processing (3)
  • reproducer_metal_address_space.py
  • reproducer_vec_type.py
  • testing/python/cpu/test_tilelang_cpu_vec_type.py
💤 Files with no reviewable changes (1)
  • reproducer_vec_type.py

Comment thread testing/python/cpu/test_tilelang_cpu_vec_type.py Outdated
CodeRabbit review finding: torch.randn/rand/empty respected PyTorch's
process-wide default dtype/device, so another test changing
set_default_dtype/set_default_device could create float64 or non-CPU
tensors and break the float32 CPU kernel contract. Pin all six tensors
explicitly without changing process-wide defaults.
@LeiWang1999
LeiWang1999 merged commit 1d155f4 into tile-ai:main Aug 5, 2026
6 checks passed
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.

[Question] Unnecessary reproducer files are added in recent bugfix PRs

2 participants