Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/test/unit/tools/test_irsource.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pathlib
import triton
from triton.compiler import IRSource
from triton.compiler import IRSource, make_backend
from triton._C.libtriton import ir

target = triton.runtime.driver.active.get_current_target()
backend = make_backend(target)


def test_mlir_attribute_parsing(tmp_path: pathlib.Path) -> None:
Expand Down Expand Up @@ -40,7 +41,7 @@ def test_mlir_attribute_parsing(tmp_path: pathlib.Path) -> None:
temp_file = tmp_path / "test_mlir_attribute_parsing0.ttgir"
temp_file.write_text(sample_ttgir)
context = ir.context()
src = IRSource(str(temp_file), context)
src = IRSource(str(temp_file), context, backend)

# check name and type signature
# should match ty_to_cpp(...)
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_mlir_attribute_parsing(tmp_path: pathlib.Path) -> None:
temp_file = tmp_path / "test_mlir_attribute_parsing1.ttgir"
temp_file.write_text(sample_ttgir_vector_add)
context = ir.context()
src = IRSource(str(temp_file), context)
src = IRSource(str(temp_file), context, backend)

# now test compilation
triton.compile(str(temp_file), target=target)
12 changes: 6 additions & 6 deletions python/triton/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ def parse_options(self):

class IRSource:

def __init__(self, path, context):
def __init__(self, path, context, backend):
self.path = path
path = Path(path)
self.ext = path.suffix[1:]
self.src = path.read_text()
ir.load_dialects(context)
backend.load_dialects(context)

# We don't have a easy-to-use PTX parser that we can use, so keep that regex for now.
# TODO - replace with a proper parser
Expand Down Expand Up @@ -223,7 +224,7 @@ def compile(src, target=None, options=None):
if ir_source:
assert isinstance(src, str), "source must be either AST or a filepath"
context = ir.context()
src = IRSource(src, context)
src = IRSource(src, context, backend)

extra_options = src.parse_options()
options = backend.parse_options(dict(options or dict(), **extra_options))
Expand Down Expand Up @@ -266,14 +267,13 @@ def compile(src, target=None, options=None):
if ir_source:
first_stage += 1

# For IRSource, we have already grabbed the context + called both
# ir.load_dialects and backend.load_dialects.
if not isinstance(src, IRSource):
context = ir.context()
ir.load_dialects(context)
backend.load_dialects(context)
else:
# For IRSource, we have already grabbed the context + called ir.load_dialects
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.

Please keep the comment, and just update it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

# just need to load the dialects for the backend.
backend.load_dialects(context)

codegen_fns = backend.get_codegen_implementation()
module_map = backend.get_module_map()
try:
Expand Down