Skip to content

Commit d792765

Browse files
authored
[Backend] Pass GPUTarget to make_ir (#7689)
This allows us avoid duplicating target parsing logic in different places, e.g., when in Gluon we don't need to parse it again from backend options.
1 parent 43625fc commit d792765

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

python/test/unit/runtime/test_bindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def walk_fn(op):
7777
triton._C.libtriton.ir.load_dialects(context)
7878
backend.load_dialects(context)
7979

80-
ttir_module = src.make_ir(options, codegen_fns, module_map, context)
80+
ttir_module = src.make_ir(target, options, codegen_fns, module_map, context)
8181
ttir_module.walk(walk_fn)
8282

8383

python/triton/_filecheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_parser(kernel_fn):
6868
options = stub_backend.parse_options(options)
6969
codegen_fns = stub_backend.get_codegen_implementation(options)
7070
module_map = stub_backend.get_module_map()
71-
module = src.make_ir(options, codegen_fns, module_map, context)
71+
module = src.make_ir(stub_target, options, codegen_fns, module_map, context)
7272
assert module.verify()
7373
return module
7474

python/triton/compiler/compiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def hash(self):
7777
key = f"{self.fn.cache_key}-{str(self.attrs)}-{sorted_sig}-{constants_key}"
7878
return hashlib.sha256(key.encode("utf-8")).hexdigest()
7979

80-
def make_ir(self, options, codegen_fns, module_map, context):
80+
def make_ir(self, target: GPUTarget, options, codegen_fns, module_map, context):
8181
from .code_generator import ast_to_ttir
8282
return ast_to_ttir(self.fn, self, context=context, options=options, codegen_fns=codegen_fns,
8383
module_map=module_map)
@@ -116,7 +116,7 @@ def __init__(self, path, context, backend):
116116
def hash(self):
117117
return hashlib.sha256(self.src.encode("utf-8")).hexdigest()
118118

119-
def make_ir(self, options, codegen_fns, module_map, context):
119+
def make_ir(self, target: GPUTarget, options, codegen_fns, module_map, context):
120120
self.module.context = context
121121
return self.module
122122

@@ -299,7 +299,7 @@ def compile(src, target=None, options=None, _env_vars=None):
299299
codegen_fns = backend.get_codegen_implementation(options)
300300
module_map = backend.get_module_map()
301301
try:
302-
module = src.make_ir(options, codegen_fns, module_map, context)
302+
module = src.make_ir(target, options, codegen_fns, module_map, context)
303303
except Exception as e:
304304
filter_traceback(e)
305305
raise

python/triton/experimental/gluon/_runtime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import annotations
2-
import triton
32
from triton.compiler.compiler import ASTSource
43
from triton.backends.compiler import Language
54
from triton.runtime.jit import JITFunction
@@ -16,15 +15,14 @@ def __init__(self, fn, signature, constexprs=None, attrs=None) -> None:
1615
self.language = Language.GLUON
1716
self.ext = "ttgir"
1817

19-
def make_ir(self, options, codegen_fns, module_map, context):
18+
def make_ir(self, target, options, codegen_fns, module_map, context):
2019
from triton.compiler.compiler import make_backend
2120
from triton.compiler.code_generator import ast_to_ttir
2221

2322
builder = ir.builder(context)
2423
module = builder.create_module()
2524

2625
# Assign module attributes eagerly, as they are needed to verify layouts
27-
target = triton.runtime.driver.active.get_current_target()
2826
backend = make_backend(target)
2927
target = backend.get_target_name(options)
3028

0 commit comments

Comments
 (0)