Commit Graph

5 Commits

Author SHA1 Message Date
Cao Ying 9bda1ac537
[Refactor][ELEMENTWISE] move strategy into kernel config; drop ctor kwarg (#1778)
Closes #1768

## Summary

- Move elementwise `strategy` selection into the kernel `config` dict;
delete the ctor kwarg and its pass-through plumbing from all elementwise
kernels and Ops.
- fp8/bool coercions and the `register_copy` broadcast downgrade stay
inside the kernel; same kernel body selected for every (op, dtype,
shape) as before.
- Migrate strategy tests to config-based construction; add guards
asserting no elementwise Op/kernel exposes a `strategy` kwarg.
- Fused-gated strategy bench now records a torch baseline and the
measured kernel object.
- Validator: `"strategy"` removed from `_CTOR_INFRA_PARAMS` —
reintroducing the kwarg on any op now fails validation (validator suite
142 passed).

## Test plan

- [x] pre-commit passed; 335 passed across the six modified test files
- [x] AC-1: no elementwise Op/kernel exposes `strategy` (signature
guards, +2 test nodes)
- [x] AC-2: register_copy broadcast-downgrade regression preserved under
config form
- [x] AC-3: elementwise GPU smoke tier green (219 passed, H200)

## Benchmark

NVIDIA H200, CUDA 12.8, PyTorch 2.9.1+cu128, TileLang 0.1.11.
Fused-gated explicit_parallel (4096, 4096) fp16:

| Op | TileOPs (ms) | torch (ms) | Speedup | BW (TB/s) |
| --- | ---: | ---: | ---: | ---: |
| SiluAndMul | 0.0292 | 0.1130 | 3.87× | 3.45 |
| GeluAndMul | 0.0332 | 0.1213 | 3.65× | 3.03 |
| GeluTanhAndMul | 0.0294 | 0.1147 | 3.90× | 3.43 |

All rows meet or exceed the documented bandwidth basis (3.04/2.72/3.38
TB/s) — perf-neutral or better.

## Regression

`test_register_copy_downgrades_on_broadcast` PASSED — config-form
downgrade matches PyTorch under broadcast strides.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Ibuki 🍃 — a wind born from GPTs <Ibuki-wind@users.noreply.github.com>
2026-07-26 20:39:07 +08:00
Cao Ying 0a9bf1e40a
[Chore][Cleanup] repo slimming: dead code, duplicated tests/benches, compat shims, file defragmentation (#1764)
Closes #1763

## Summary

- Remove dead helpers, redundant elementwise benchmark drivers,
decorative banners, and stale compatibility aliases.
- Consolidate duplicated tests and private benchmark wrappers onto
shared parametrized fixtures and `ManifestBenchmark`.
- Merge fragmented workload, reduction-op, MHC, and normalization
benchmark modules; retarget imports and manifest source paths.
- Preserve canonical runtime behavior while reducing the repository by
roughly 4.3k net lines.

## Test plan

- [x] pre-commit passed
- [x] `python scripts/validate_manifest.py --strict` passed
- [x] Repository-wide pytest collection completed: 5,178 tests, 0
collection errors
- [x] Touched test and benchmark modules collect cleanly

---------

Co-authored-by: Ibuki 🍃 — a wind born from GPTs <Ibuki-wind@users.noreply.github.com>
2026-07-26 12:59:48 +08:00
Cao Ying 731744d0d5 [Feat][Kernels] rounding-mode div kernel path for trunc/floor (#1410)
Closes #1245

## Summary

Adds `rounding_mode='trunc' | 'floor'` support to `DivFwdOp`. Previously
only `rounding_mode=None` (true division) worked; non-None raised
`NotImplementedError`.

- `tileops/kernels/elementwise.py`: new `DivTruncFwdKernel` (fp32
promotion → divide → `T.trunc` → cast back). `'floor'` reuses existing
`FloorDivideFwdKernel` (byte-identical to what an early draft
`DivFloorFwdKernel` would have been; that draft class was removed during
review).
- `tileops/ops/elementwise/arithmetic.py`:
`_DIV_KERNEL_BY_ROUNDING_MODE` dispatch (`None → DivFwdKernel`, `'trunc'
→ DivTruncFwdKernel`, `'floor' → FloorDivideFwdKernel`). Forward-time
`NotImplementedError` guard removed; invalid modes raise `ValueError` at
construction.
- `tests/ops/test_binary_arith.py`: `test_div_rounding_mode_eager` (6
cells: trunc/floor × fp16/bf16/fp32, mixed-sign quotients vs
`torch.div`) + `test_div_rounding_mode_dispatch` (CPU-only dispatch
table + invalid-mode rejection).
- `tests/ops/test_elementwise_compile.py`:
`test_div_rounding_mode_compile` (6 cells under
`torch.compile(fullgraph=True)`, same oracle).

## Test plan

- [x] `pytest tests/ops/test_binary_arith.py
tests/ops/test_elementwise_compile.py -m smoke` — 89 passed.
- [x] Manual parity vs `torch.div(..., rounding_mode=...)` on
fp16/bf16/fp32; tolerances follow the existing `FloorDivideFwdKernel`
convention (`atol=1.0, rtol=0` for half precision rounding-mode kernels,
`1e-5` for fp32).
- [x] `scripts/validate_manifest.py` clean on `DivFwdOp`.

---------

Co-authored-by: Ibuki 🍃 — a wind born from GPTs <Ibuki-wind@users.noreply.github.com>
2026-05-12 09:57:31 +08:00
Cao Ying 4f4ccfb90f [Feat][Kernels] alpha-scaled add/sub kernel path for non-default alpha (#1409)
Closes #1244

## Summary

- Bake the scalar `alpha` multiplier into `AddFwdKernel` /
`SubFwdKernel` at construction time so `AddFwdOp(alpha=k)` and
`SubFwdOp(alpha=k)` for `k != 1` dispatch to a real kernel instead of
raising `NotImplementedError`.
- Scalar multiply runs in fp32 (per code-style: no narrow-type literal
casts) and casts back to storage dtype at the boundary; `alpha == 1`
keeps the original `op_func` to preserve the integer-dtype fast path
byte-identically.
- Removes the `NotImplementedError` raise in
`tileops/ops/elementwise/arithmetic.py` for the `alpha != 1` path.

## Scope (kernel-only PR)

Per [`docs/design/trust-model.md`](docs/design/trust-model.md), this PR
touches only `tileops/kernels/` and `tileops/ops/elementwise/`. Test and
benchmark additions for the new `alpha != 1` path are deferred to a
sibling PR owned by the `tests/` and `benchmarks/` layers respectively.

- AC-1 / AC-2 (kernel correctness): verified in this PR.
- AC-3 (per-dtype correctness tests for `alpha != 1`): deferred to a
sibling test-layer PR.
- AC-4 (benchmark entry at LLaMA workload): deferred to a sibling
benchmark-layer PR.

## Test plan

- [x] AC-1: `pytest tests/ops/test_binary_arith.py` — 120 passed
(existing `alpha=1` fast path, no regression).
- [x] AC-1: `pytest tests/test_validate_manifest.py` — 218 passed.
- [x] AC-2: `AddFwdOp` / `SubFwdOp` × {fp32, fp16, bf16} × `alpha ∈ {1,
2, -1, 0.5}` — 24/24 cases match `torch.add` / `torch.sub` with `max_err
= 0.0` (kernel compile log confirms TileLang dispatch per `(op, dtype,
alpha)` specialization, no `NotImplementedError`, no torch passthrough).
- [ ] AC-3: per-dtype correctness tests for `alpha != 1` — deferred to
sibling tests-layer PR.
- [ ] AC-4: benchmark entry at LLaMA workload for `alpha != 1` —
deferred to sibling benchmarks-layer PR.

---------

Co-authored-by: Ibuki 🍃 — a wind born from GPTs <Ibuki-wind@users.noreply.github.com>
2026-05-12 09:57:31 +08:00
Cao Ying e01a88eea8 [Refactor][OPS] split tileops/ops/elementwise.py into per-cluster package (#1388)
Closes #1378

## Summary

- Replaced 3415-line monolith `tileops/ops/elementwise.py` with a
`tileops/ops/elementwise/` package, one module per cluster (16 cluster
modules + `_base.py`).
- Umbrella classes `UnaryOp`, `BinaryOp`, `FusedGatedOp` moved to
`_base.py`; `__init__.py` re-exports every previously-public symbol via
explicit `__all__`.
- Pure file-layout move: no class signature, docstring, or
kernel-binding changes; all 295 elementwise tests pass; no file-level
lint suppressions introduced.
- Pyright shows pre-existing typing issues in the relocated code that
were carried over verbatim from the original file — out of scope to fix
in this refactor.

## Test plan

- [x] AC-1: Modified files pass unit tests (pytest tests/ops/).
- [x] AC-2: tileops/ops/elementwise.py no longer exists;
tileops/ops/elementwise/ is a package with __init__.py.
- [x] AC-3: python -c "from tileops.ops.elementwise import UnaryOp,
BinaryOp, FusedGatedOp" succeeds.
- [x] AC-4: python -c "from tileops.ops.elementwise import
SiluAndMulFwdOp, ReluFwdOp, AddFwdOp, ExpFwdOp, DivFwdOp" succeeds.
- [x] AC-5: tests/ops/test_elementwise_fp8.py passes without
modification to its imports.
- [x] AC-6: grep -nE '^# ruff:|^# flake8:' tileops/ops/elementwise/
returns nothing.
- [x] AC-7: External tracker flip — out of scope.

---------

Co-authored-by: Ibuki 🍃 — a wind born from GPTs <Ibuki-wind@users.noreply.github.com>
2026-05-12 09:57:31 +08:00