Skip to content

Commit 16940cc

Browse files
committed
[TLE][AMD] Tighten backend-specific lowering checks
Use FlagTree backend identity helpers in the shared cumsum tests and derive the warp size from the active target. Reject unsupported TLE and accidental NVVM operations during AMD LLVM conversion.
1 parent cf2a001 commit 16940cc

2 files changed

Lines changed: 13 additions & 34 deletions

File tree

python/test/tle/unit/test_tle_cumsum.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import triton
1111
import triton.language as tl
1212
import triton.experimental.tle.language as tle
13+
from triton._flagtree_backend import FLAGTREE_BACKEND
14+
from triton._internal_testing import get_current_target, is_cuda, is_hip
1315

1416

1517
def _is_enflame_backend():
@@ -18,32 +20,15 @@ def _is_enflame_backend():
1820

1921

2022
def _is_hcu_backend():
21-
try:
22-
driver = triton.runtime.driver.active
23-
return type(driver).__module__.startswith("triton.backends.hcu")
24-
except Exception:
25-
return False
23+
return FLAGTREE_BACKEND == "hcu"
2624

2725

2826
_nv_mma_shared_layout = tl.constexpr(False if _is_hcu_backend() else True)
29-
threads_per_warp = 64 if _is_hcu_backend() else 32
30-
31-
32-
def _is_nvidia_cuda_backend():
33-
try:
34-
driver = triton.runtime.driver.active
35-
target = driver.get_current_target()
36-
return (target.backend == "cuda" and type(driver).__module__.startswith("triton.backends.nvidia"))
37-
except Exception:
38-
return False
27+
threads_per_warp = get_current_target().warp_size
3928

4029

4130
def _is_amd_hip_backend():
42-
try:
43-
driver = triton.runtime.driver.active
44-
return type(driver).__module__.startswith("triton.backends.amd")
45-
except Exception:
46-
return False
31+
return is_hip() and not FLAGTREE_BACKEND
4732

4833

4934
def _require_cuda():
@@ -223,7 +208,7 @@ def test_tle_cumsum_exclusive_and_total(dtype, n, block, reverse, num_warps):
223208

224209

225210
@pytest.mark.skipif(
226-
not _is_nvidia_cuda_backend(),
211+
not is_cuda(),
227212
reason="PTX-specific regression guard requires NVIDIA CUDA backend",
228213
)
229214
def test_tle_cumsum_ptx_fastpath_regression_guard():

third_party/amd/lib/TritonAMDGPUToLLVM/TritonGPUToLLVM.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,13 @@ class TritonLLVMConversionTarget : public ConversionTarget {
7070
};
7171

7272
#ifdef __TLE__
73-
// Conversion target for the dedicated TLE-to-LLVM partial conversion. Only
74-
// the tile-level extension ops that have AMD lowering patterns are illegal
75-
// (must be converted); every other op (including unsupported TLE ops) stays
76-
// legal and is reported later by the make_llir residual-op guard.
73+
// Reject unsupported TLE operations and accidental CUDA lowering in the
74+
// dedicated AMD TLE-to-LLVM partial conversion.
7775
class TleLLVMConversionTarget : public ConversionTarget {
7876
public:
7977
explicit TleLLVMConversionTarget(MLIRContext &ctx) : ConversionTarget(ctx) {
80-
addLegalDialect<LLVM::LLVMDialect, ROCDL::ROCDLDialect,
81-
NVVM::NVVMDialect>();
82-
addIllegalOp<mlir::triton::tle::ExtractTileOp,
83-
mlir::triton::tle::InsertTileOp,
84-
mlir::triton::tle::ExclusiveCumsumOp>();
78+
addLegalDialect<LLVM::LLVMDialect, ROCDL::ROCDLDialect>();
79+
addIllegalDialect<NVVM::NVVMDialect, mlir::triton::tle::TleDialect>();
8580
addLegalOp<mlir::UnrealizedConversionCastOp>();
8681
markUnknownOpDynamicallyLegal([](Operation *) -> bool { return true; });
8782
}
@@ -204,10 +199,9 @@ struct ConvertTritonAMDGPUToLLVM
204199

205200
#ifdef __TLE__
206201
// Lower the supported tile-level extension (TLE) ops (extract_tile /
207-
// insert_tile / exclusive_cumsum) to LLVM via the backend-agnostic
208-
// conversion patterns, in a dedicated partial conversion (mirrors the
209-
// NVIDIA / HCU path). Unsupported TLE ops remain legal in this focused
210-
// conversion.
202+
// insert_tile / exclusive_cumsum) via the backend-agnostic conversion
203+
// patterns. The dedicated partial conversion rejects unsupported TLE ops
204+
// and accidental NVVM emission.
211205
{
212206
TleLLVMConversionTarget tleTarget(*context);
213207
RewritePatternSet tlePatterns(context);

0 commit comments

Comments
 (0)