Skip to content

Commit f140c15

Browse files
authored
[Iluvatar][TLE] Sync iluvatar backend and extend TLE primitives support (#880)
* [Iluvatar] Update iluvatar backend to commit d10a6779d9a. * [Iluvatar][TLE] Update for more tle support. - Support async copy && tle.load, memory_space, cumsum and pipeline. - Support tle.gpu.warp_specialize && tle.pipe only for ivcore11. - Opt 01-fft && 03-topk. * [CI/CD] Update iluvatar3.6 ci runner.
1 parent a787fec commit f140c15

139 files changed

Lines changed: 17807 additions & 1498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/iluvatar3.6-build-and-test.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
8585
pip3 install "pytest==9.1.1"
8686
87-
for pkg in hypothesis absl-py scipy pytest-forked; do
87+
for pkg in hypothesis absl-py scipy pytest-forked expecttest; do
8888
pip3 list "$pkg" | grep "$pkg" || pip3 install "$pkg"
8989
done
9090
@@ -95,16 +95,77 @@ jobs:
9595
fi
9696
fi
9797
98-
# triton unit test
98+
# triton language unit test
9999
UMD_CUDAMODULELOADING=0 pytest -v third_party/iluvatar/python/test/unit/language/test_core.py
100+
pytest -v third_party/iluvatar/python/test/unit/language/test_annotations.py
101+
pytest -v third_party/iluvatar/python/test/unit/language/test_block_pointer.py
102+
pytest -v third_party/iluvatar/python/test/unit/language/test_compile_errors.py
103+
pytest -v third_party/iluvatar/python/test/unit/language/test_conversions.py
104+
pytest -v third_party/iluvatar/python/test/unit/language/test_decorator.py
105+
pytest -v third_party/iluvatar/python/test/unit/language/test_frontend.py
106+
pytest -v third_party/iluvatar/python/test/unit/language/test_libdevice.py
107+
pytest -v third_party/iluvatar/python/test/unit/language/test_iluvatar_math_fp16_bf16.py
108+
pytest -v third_party/iluvatar/python/test/unit/language/test_iluvatar_int8_upcast_dot_pipeline.py
109+
pytest -v third_party/iluvatar/python/test/unit/language/test_matmul.py
110+
pytest -v third_party/iluvatar/python/test/unit/language/test_mxfp.py
111+
pytest -v third_party/iluvatar/python/test/unit/language/test_pipeliner.py
112+
pytest -v third_party/iluvatar/python/test/unit/language/test_random.py
113+
pytest -v third_party/iluvatar/python/test/unit/language/test_reproducer.py
114+
pytest -v third_party/iluvatar/python/test/unit/language/test_standard.py
100115
pytest -v third_party/iluvatar/python/test/unit/language/test_subprocess.py
116+
UMD_CUDAMODULELOADING=0 pytest -v third_party/iluvatar/python/test/unit/language/test_tensor_descriptor.py
117+
pytest -v third_party/iluvatar/python/test/unit/language/test_tuple.py
118+
pytest -v third_party/iluvatar/python/test/unit/language/test_warp_specialization.py
119+
120+
# triton operators unit test
101121
pytest -v third_party/iluvatar/python/test/unit/operators/test_blocksparse.py
102122
pytest -v third_party/iluvatar/python/test/unit/operators/test_cross_entropy.py
103123
pytest -v third_party/iluvatar/python/test/unit/operators/test_dot_trans.py
104124
pytest -v third_party/iluvatar/python/test/unit/operators/test_flash_attention.py
105125
pytest -v third_party/iluvatar/python/test/unit/operators/test_inductor.py
106126
pytest -v third_party/iluvatar/python/test/unit/operators/test_matmul.py
127+
pytest -v third_party/iluvatar/python/test/unit/operators/test_sme.py
128+
129+
# triton runtime unit test
130+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_autotuner.py
131+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_bindings.py
132+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_build.py
133+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_cache.py
134+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_compilation_listener.py
135+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_driver.py
136+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_launch.py
137+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_specialize.py
138+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_subproc.py
139+
pytest -v third_party/iluvatar/python/test/unit/runtime/test_iluvatar_loop_unroll_warning.py
140+
141+
# triton instrumentation unit test
142+
pytest -v third_party/iluvatar/python/test/unit/instrumentation/test_gpuhello.py
143+
144+
# triton tools unit test
145+
pytest -v third_party/iluvatar/python/test/unit/tools/test_irsource.py
146+
pytest -v third_party/iluvatar/python/test/unit/tools/test_linear_layout.py
147+
148+
# triton misc unit test
149+
pytest -v third_party/iluvatar/python/test/unit/test_debug_dump.py
107150
pytest -v third_party/iluvatar/python/test/unit/test_debug.py
151+
pytest -v third_party/iluvatar/python/test/unit/test_debuginfo.py
152+
pytest -v third_party/iluvatar/python/test/unit/test_filecheck.py
153+
pytest -v third_party/iluvatar/python/test/unit/test_knobs.py
154+
UMD_CUDAMODULELOADING=0 pytest -v third_party/iluvatar/python/test/unit/test_link.py
155+
pytest -v third_party/iluvatar/python/test/unit/test_perf_warning.py
156+
157+
# triton regression test
158+
pytest -v third_party/iluvatar/python/test/regression/test_cast_matmul.py
159+
pytest -v third_party/iluvatar/python/test/regression/test_functional_regressions.py
160+
161+
# triton integrations unit test
162+
pytest -v third_party/iluvatar/python/test/unit/integrations/vllm/chunk_o/test_chunk_fwd_kernel_o.py
163+
pytest -v third_party/iluvatar/python/test/unit/integrations/vllm/wy_fast/test_recompute_w_u.py
164+
pytest -v third_party/iluvatar/python/test/unit/integrations/fbgemm/test_jagged_flash_attention_bwd_basic_min.py
165+
PUNICA_TEST_LEVEL=quick pytest -v third_party/iluvatar/python/test/unit/integrations/vllm/punica_lora/test_punica_ops.py
166+
pytest -v third_party/iluvatar/python/test/unit/integrations/sglang/flash_mla/test_flash_mla_ut.py
167+
pytest -v third_party/iluvatar/python/test/unit/integrations/inductor/test_bucketize_matmul.py
168+
pytest -v third_party/iluvatar/python/test/unit/integrations/inductor/test_swfw3103_flex_attention_precision.py
108169
109170
# TLE unit test
110171
pytest -v python/test/tle/integration/test_tle_local_store.py
@@ -113,6 +174,16 @@ jobs:
113174
pytest -v python/test/tle/unit/test_extract_tile_dynamic_index.py
114175
pytest -v python/test/tle/unit/test_insert_tile_static_index.py
115176
pytest -v python/test/tle/unit/test_insert_tile_dynamic_index.py
177+
pytest -v python/test/tle/unit/test_tle.py
178+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_copy.py
179+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_async_load.py
180+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_memory_space.py
181+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_cumsum.py
182+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_pipeline.py
183+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_pipeline_e2e.py
184+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_warp_specialize.py
185+
pytest -v third_party/iluvatar/python/test/unit/tle/test_tle_pipe.py
116186
117187
# TLE tutorials unit tests
118-
python3 python/tutorials/tle/01-fft.py --only_unit_test
188+
python3 third_party/iluvatar/python/tutorials/tle/01-fft.py --only_unit_test
189+
python3 third_party/iluvatar/python/tutorials/tle/03-topk.py --only_unit_test

python/setup_tools/setup_helper.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ def uninstall_triton():
563563

564564
handle_flagtree_backend()
565565

566+
register_backend_cache()
567+
566568
# iluvatar
567569
cache.store(
568570
file="iluvatar-llvm22-x86_64",
@@ -572,13 +574,6 @@ def uninstall_triton():
572574
post_hook=set_llvm_env,
573575
)
574576

575-
cache.store(
576-
file="iluvatarTritonPlugin.so", condition=("iluvatar" == flagtree_backend) and (not configs.flagtree_plugin), url=
577-
"https://baai-cp-web.ks3-cn-beijing.ksyuncs.com/trans/iluvatarTritonPlugin-cpython3.10-glibc2.30-glibcxx3.4.28-cxxabi1.3.12-ubuntu-x86_64_v0.3.0.tar.gz",
578-
copy_dst_path=f"third_party/{flagtree_backend}", md5_digest="015b9af8")
579-
580-
register_backend_cache()
581-
582577
# mthreads
583578
cache.store(
584579
file="mthreads-llvm22",

python/triton/experimental/tle/language/gpu/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,16 @@ def normcopy(
954954

955955
try:
956956
if direction == CopyDirection.GM_TO_LOCAL:
957-
# None fills the FlagTree hints slot; TLE copy has no hints to pass.
958-
load_extra_args = () if (mthreads_enabled or iluvatar_enabled) else (None, )
959-
tt_load = _semantic.load(src, mask, other, boundary_check, padding_option, cache_modifier,
960-
eviction_policy, volatile, *load_extra_args)
957+
if iluvatar_enabled:
958+
# Iluvatar's semantic.load carries an extra `stride` (SME) slot
959+
# right after `other`; TLE copy never uses the SME path.
960+
tt_load = _semantic.load(src, mask, other, None, boundary_check, padding_option, cache_modifier,
961+
eviction_policy, volatile)
962+
else:
963+
# None fills the FlagTree hints slot; TLE copy has no hints to pass.
964+
load_extra_args = () if mthreads_enabled else (None, )
965+
tt_load = _semantic.load(src, mask, other, boundary_check, padding_option, cache_modifier,
966+
eviction_policy, volatile, *load_extra_args)
961967
local_ptrs = local_ptr(dst, _make_full_indices(dst, _semantic), _semantic=_semantic)
962968
_semantic.store(local_ptrs, tt_load, mask, boundary_check, cache_modifier, eviction_policy)
963969
else:

third_party/iluvatar/backend/compiler.py

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
from pathlib import Path
1717

1818

19+
def has_tle_pass(pass_name: Optional[str] = None) -> bool:
20+
tle_passes = getattr(iluvatar.passes, "tle", None)
21+
if tle_passes is None:
22+
return False
23+
if pass_name is None:
24+
return True
25+
return hasattr(tle_passes, pass_name)
26+
27+
1928
def min_dot_size(target: GPUTarget):
2029

2130
def check_dot_compatibility(lhs_type, rhs_type) -> Tuple[int, int, int]: # [m, n, k]
@@ -106,7 +115,7 @@ def sm_arch_from_capability(capability: int):
106115

107116

108117
@dataclass(frozen=True)
109-
class CUDAOptions:
118+
class CorexOptions:
110119
num_warps: int = 4
111120
num_ctas: int = 1
112121
num_stages: int = 3
@@ -121,7 +130,9 @@ class CUDAOptions:
121130
enable_reflect_ftz: bool = True # ftz in libdevice
122131
launch_cooperative_grid: bool = False
123132
launch_pdl: bool = False
124-
supported_fp8_dtypes: Tuple[str] = ("fp8e5", "fp8e4b15")
133+
# OCP only: fp8e5 always; fp8e4nv added for sm71 (ivcore11 SW) / sm89+.
134+
# fp8e4b15 is NVIDIA PTX-asm software format — not supported on Iluvatar.
135+
supported_fp8_dtypes: Tuple[str] = ("fp8e5", )
125136
deprecated_fp8_dot_operand_dtypes: Tuple[str] = ()
126137
default_dot_input_precision: str = "tf32"
127138
allowed_dot_input_precisions: Tuple[str] = ("tf32", "tf32x3", "ieee", 'bf16x3', 'bf16x6')
@@ -152,12 +163,12 @@ def hash(self):
152163
return hashlib.sha256(key.encode("utf-8")).hexdigest()
153164

154165

155-
class CUDABackend(BaseBackend):
166+
class CorexBackend(BaseBackend):
156167
instrumentation = None
157168

158169
@staticmethod
159170
def supports_target(target: GPUTarget):
160-
return target.backend == 'corex'
171+
return target.backend in ('corex', 'cuda')
161172

162173
def _parse_arch(self, arch):
163174
pattern = r"^sm(\d+)$"
@@ -171,6 +182,8 @@ def get_target_name(self, options) -> str:
171182
return f"cuda:{capability}"
172183

173184
def __init__(self, target: GPUTarget) -> None:
185+
if target.backend == 'cuda':
186+
target = GPUTarget('corex', target.arch, target.warp_size)
174187
super().__init__(target)
175188
self.binary_ext = "cubin"
176189

@@ -180,7 +193,7 @@ def parse_options(self, opts) -> Any:
180193
opts["debug"] = True
181194

182195
args = {'arch': knobs.runtime.override_arch or f"sm{self.target.arch}"}
183-
args.update({k: opts[k] for k in CUDAOptions.__dataclass_fields__.keys() if k in opts if opts[k] is not None})
196+
args.update({k: opts[k] for k in CorexOptions.__dataclass_fields__.keys() if k in opts if opts[k] is not None})
184197
capability = int(self._parse_arch(args["arch"]))
185198

186199
if args.get("num_ctas", 1) > 1 and capability < 90:
@@ -189,21 +202,18 @@ def parse_options(self, opts) -> Any:
189202
f"Please set num_ctas=1 or target an SM90+ GPU."))
190203

191204
if "supported_fp8_dtypes" not in args:
192-
supported_fp8_dtypes = set(CUDAOptions.supported_fp8_dtypes)
193-
if capability >= 89:
205+
supported_fp8_dtypes = set(CorexOptions.supported_fp8_dtypes)
206+
# ivcore11 (sm71): software FP8; ivcore30 will use native HW when mapped.
207+
if capability >= 89 or capability == 71:
194208
supported_fp8_dtypes.add("fp8e4nv")
195209
args["supported_fp8_dtypes"] = tuple(sorted(supported_fp8_dtypes))
196210

197-
if "deprecated_fp8_dot_operand_dtypes" not in args:
198-
if capability >= 90:
199-
args["deprecated_fp8_dot_operand_dtypes"] = ("fp8e4b15", )
200-
201211
if "enable_fp_fusion" not in args:
202212
args["enable_fp_fusion"] = knobs.language.default_fp_fusion
203213

204214
args["max_num_imprecise_acc_default"] = 2**30 if capability == 90 else 0
205215

206-
return CUDAOptions(**args)
216+
return CorexOptions(**args)
207217

208218
def pack_metadata(self, metadata):
209219
return (
@@ -228,8 +238,8 @@ def get_module_map(self) -> Dict[str, ModuleType]:
228238

229239
def load_dialects(self, ctx):
230240
iluvatar.load_dialects(ctx)
231-
if CUDABackend.instrumentation:
232-
CUDABackend.instrumentation.load_dialects(ctx)
241+
if CorexBackend.instrumentation:
242+
CorexBackend.instrumentation.load_dialects(ctx)
233243

234244
@staticmethod
235245
def make_ttir(mod, metadata, opt, capability):
@@ -263,15 +273,26 @@ def make_ttgir(mod, metadata, opt, capability):
263273
passes.ttgpuir.add_f32_dot_tc(pm, emuTF32)
264274
passes.ttgpuir.add_remove_layout_conversions(pm)
265275
passes.ttgpuir.add_optimize_thread_locality(pm)
266-
if hasattr(iluvatar.passes, "tle"):
276+
if has_tle_pass():
277+
if has_tle_pass("add_optimize_local_pointer_async_stores"):
278+
iluvatar.passes.tle.add_optimize_local_pointer_async_stores(pm)
279+
if has_tle_pass("add_early_assign_memory_space"):
280+
iluvatar.passes.tle.add_early_assign_memory_space(pm)
281+
if has_tle_pass("add_optimize_exclusive_cumsum_layouts"):
282+
iluvatar.passes.tle.add_optimize_exclusive_cumsum_layouts(pm)
283+
if has_tle_pass("add_lower_exclusive_cumsum"):
284+
iluvatar.passes.tle.add_lower_exclusive_cumsum(pm)
267285
iluvatar.passes.tle.add_insert_local_pointer_barriers(pm)
268286
iluvatar.passes.tle.add_optimize_local_pointer_loads(pm)
269287
iluvatar.passes.tle.add_optimize_local_pointer_stores(pm)
288+
if has_tle_pass("add_lower_pipe_to_barriers"):
289+
iluvatar.passes.tle.add_lower_pipe_to_barriers(pm)
270290
iluvatar.passes.ttgpuir.add_accelerate_matmul(pm, opt.use_sme)
271291
passes.ttgpuir.add_remove_layout_conversions(pm)
272292
iluvatar.passes.ttgpuir.add_mma_reduce_thread_locality(pm)
273293
iluvatar.passes.ttgpuir.add_optimize_epilogue(pm)
274294
passes.ttgpuir.add_optimize_dot_operands(pm, capability >= 71)
295+
iluvatar.passes.ttgpuir.add_matmul_smeload(pm, capability)
275296
passes.ttir.add_loop_aware_cse(pm)
276297
if capability // 10 in [7, 8, 9]:
277298
passes.ttgpuir.add_fuse_nested_loops(pm)
@@ -281,6 +302,7 @@ def make_ttgir(mod, metadata, opt, capability):
281302
passes.ttgpuir.add_combine_tensor_select_and_if(pm)
282303
passes.ttgpuir.add_assign_latencies(pm, opt.num_stages)
283304
passes.ttgpuir.add_schedule_loops(pm)
305+
passes.ttgpuir.add_pipeline(pm, opt.num_stages, dump_enabled)
284306
elif capability // 10 >= 10:
285307
passes.ttgpuir.add_fuse_nested_loops(pm)
286308
passes.common.add_canonicalizer(pm)
@@ -299,10 +321,11 @@ def make_ttgir(mod, metadata, opt, capability):
299321
passes.ttir.add_triton_licm(pm)
300322
passes.common.add_canonicalizer(pm)
301323
passes.ttir.add_loop_aware_cse(pm)
302-
iluvatar.passes.ttgpuir.add_matmul_smeload(pm, capability)
303324
passes.ttgpuir.add_remove_layout_conversions(pm)
304325
passes.ttgpuir.add_prefetch(pm)
305326
passes.ttgpuir.add_optimize_dot_operands(pm, capability >= 71)
327+
if has_tle_pass("add_lower_async_load"):
328+
iluvatar.passes.tle.add_lower_async_load(pm)
306329
passes.ttgpuir.add_coalesce_async_copy(pm)
307330
passes.ttgpuir.add_remove_layout_conversions(pm)
308331
passes.ttgpuir.add_reduce_data_duplication(pm)
@@ -350,12 +373,15 @@ def make_llir(self, src, metadata, options, capability):
350373
# Call ConcurrencySanitizerPass here, before allocating global scratch memory but after allocating tensor and shared
351374
passes.ttgpuir.add_concurrency_sanitizer(pm)
352375
passes.ttgpuir.add_allocate_global_scratch_memory(pm)
353-
if CUDABackend.instrumentation:
354-
CUDABackend.instrumentation.patch("ttgpuir_to_llvmir", pm, mod.context)
376+
if CorexBackend.instrumentation:
377+
CorexBackend.instrumentation.patch("ttgpuir_to_llvmir", pm, mod.context)
355378
proc = sm_arch_from_capability(capability)
356379
iluvatar.passes.ttgpuir.add_to_llvmir(pm, proc, options.enable_reflect_ftz)
357380
passes.common.add_canonicalizer(pm)
358381
passes.common.add_cse(pm)
382+
# [WA] On ivcore11 this relies on a shared-memory software barrier
383+
# because the architecture lacks hardware named barriers and setmaxnreg.
384+
iluvatar.passes.ttgpuir.add_warp_specialize_to_llvm(pm, proc)
359385
passes.common.add_canonicalizer(pm)
360386
passes.common.add_cse(pm)
361387
passes.common.add_symbol_dce(pm)
@@ -364,8 +390,8 @@ def make_llir(self, src, metadata, options, capability):
364390
if not knobs.compilation.disable_line_info and not knobs.compilation.dump_ir_extract_di_local_variables:
365391
passes.llvmir.add_di_scope(pm)
366392

367-
if CUDABackend.instrumentation:
368-
CUDABackend.instrumentation.patch("llvmir_to_llvm", pm, mod.context)
393+
if CorexBackend.instrumentation:
394+
CorexBackend.instrumentation.patch("llvmir_to_llvm", pm, mod.context)
369395

370396
pm.run(mod, 'make_llir')
371397

third_party/iluvatar/backend/driver.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def library_dirs():
5151
# ------------------------
5252

5353

54-
class CudaUtils(object):
54+
class CorexUtils(object):
5555

5656
def __new__(cls):
5757
if not hasattr(cls, "instance"):
58-
cls.instance = super(CudaUtils, cls).__new__(cls)
58+
cls.instance = super(CorexUtils, cls).__new__(cls)
5959
return cls.instance
6060

6161
def __init__(self):
@@ -674,7 +674,7 @@ def inner(*args):
674674
return inner
675675

676676

677-
class CudaLauncher(object):
677+
class CorexLauncher(object):
678678

679679
def __init__(self, src, metadata):
680680
constants = src.constants if hasattr(src, "constants") else dict()
@@ -717,11 +717,11 @@ def allocate_scratch(size, align, allocator):
717717
global_scratch, profile_scratch, *args)
718718

719719

720-
class CudaDriver(GPUDriver):
720+
class CorexDriver(GPUDriver):
721721

722722
def __init__(self):
723-
self.utils = CudaUtils() # TODO: make static
724-
self.launcher_cls = CudaLauncher
723+
self.utils = CorexUtils() # TODO: make static
724+
self.launcher_cls = CorexLauncher
725725
super().__init__()
726726

727727
def get_current_target(self):

0 commit comments

Comments
 (0)