-
Notifications
You must be signed in to change notification settings - Fork 54
Update mlir-aie and use mlir-aie utils when possible #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0bdebc0
Update mlir-aie to v1.4.0 and migrate the operator library to its APIs
atassis 43117d2
Update mlir-aie to latest nightly (1.4.2.dev12) and llvm-aie to 22.0.…
hunhoffe 3cded00
Replace hand-rolled XRTSubBuffer with upstream NpuTensor.subview()
hunhoffe 5ab6c26
device_utils: delegate arch string mapping to upstream resolve_target…
hunhoffe 19d8950
KernelCompilationRule: delegate kernel .o compilation to upstream
hunhoffe 4f50d26
Aiecc*CompilationRule: delegate to upstream compile_mlir_module()
hunhoffe a9e584a
bump
hunhoffe 3d012cf
Update mlir-aie to 1.4.2.dev16 and llvm-aie to nightly 2026082001
hunhoffe 28a51e5
sequence.py: fix params.txt path after aiecc --tmpdir delegation
hunhoffe 4ec70bf
_PerBufferCallable: finish the XRTSubBuffer -> subview() migration
hunhoffe 5926b93
Merge remote-tracking branch 'origin/devel' into dedupe-sequence-subview
Copilot 0e3905c
Update mlir-aie nightly and reuse upstream timing and tensor APIs
Copilot cfe3918
Keep reference sequence inputs CPU-resident for upstream subviews
Copilot 18875f1
Fix CI Black formatting and apt installation permissions
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """The operator test adapter keeps reporting NPU, not host, latency.""" | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| torch = pytest.importorskip("torch") | ||
|
|
||
| from aie.utils.hostruntime.tensor_class import CPUOnlyTensor | ||
| from iron.common.base import AIEOperatorBase, AIERuntimeArgSpec | ||
| from iron.common import test_utils | ||
|
|
||
|
|
||
| class _Operator(AIEOperatorBase): | ||
| def __init__(self, results): | ||
| self.results = iter(results) | ||
| self.calls = 0 | ||
|
|
||
| def set_up_artifacts(self): | ||
| pass | ||
|
|
||
| def compile(self): | ||
| return self | ||
|
|
||
| def get_arg_spec(self): | ||
| return [ | ||
| AIERuntimeArgSpec("in", (32,)), | ||
| AIERuntimeArgSpec("out", (32,)), | ||
| ] | ||
|
|
||
| def get_callable(self): | ||
| def run(source, target): | ||
| self.calls += 1 | ||
| target[:] = source.numpy() | ||
| return next(self.results) | ||
|
|
||
| return run | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("tuple_result", [False, True]) | ||
| def test_run_test_uses_upstream_npu_timing(monkeypatch, tuple_result): | ||
| monkeypatch.setattr(test_utils.aie_utils, "DEFAULT_TENSOR_CLASS", CPUOnlyTensor) | ||
| results = [SimpleNamespace(npu_time=ns) for ns in (1000000, 2000, 4000)] | ||
| if tuple_result: | ||
| results = [(None, result) for result in results] | ||
| op = _Operator(results) | ||
| data = torch.ones(32, dtype=torch.bfloat16) | ||
|
|
||
| errors, latency_us, bandwidth = test_utils.run_test( | ||
| op, {"in": data}, {"out": data}, warmup_iters=1, timed_iters=2 | ||
| ) | ||
|
|
||
| assert op.calls == 3 | ||
| assert errors == {} | ||
| assert latency_us == 3.0 | ||
| assert bandwidth == pytest.approx(128 / (3e-6) / 1e9) | ||
|
|
||
|
|
||
| def test_missing_npu_timing_is_rejected(monkeypatch): | ||
| monkeypatch.setattr(test_utils.aie_utils, "DEFAULT_TENSOR_CLASS", CPUOnlyTensor) | ||
| op = _Operator([None]) | ||
| data = torch.ones(32, dtype=torch.bfloat16) | ||
| with pytest.raises(RuntimeError, match="NPU execution time"): | ||
| test_utils.run_test( | ||
| op, {"in": data}, {"out": data}, warmup_iters=0, timed_iters=1 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Host-only coverage of the shared upstream tensor subview path.""" | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| from ml_dtypes import bfloat16 | ||
|
|
||
| from iron.common.sequence import SequenceReferenceCallable | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def run(): | ||
| op = SimpleNamespace( | ||
| subbuffer_layout={"packed": ("output", 0, 1024)}, | ||
| slice_info={ | ||
| "first": ("packed", 0, 512), | ||
| "second": ("packed", 512, 1024), | ||
| }, | ||
| ) | ||
| return SequenceReferenceCallable(op) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("name, start", [("first", 0), ("second", 256)]) | ||
| def test_slices_alias_the_parent_and_are_cached(run, name, start): | ||
| parent = run.get_buffer("packed") | ||
| parent.fill_(0) | ||
| view = run.get_buffer(name) | ||
|
|
||
| assert view is run.get_buffer(name) | ||
| assert view is run._resolve_buffer(name) | ||
| assert view.dtype == np.dtype(bfloat16) | ||
| assert view.shape == (256,) | ||
| assert np.shares_memory(view.data, parent.data) | ||
|
|
||
| view.fill_(3) | ||
| expected = np.zeros(512, dtype=bfloat16) | ||
| expected[start : start + 256] = 3 | ||
| np.testing.assert_array_equal(parent.numpy(), expected) | ||
|
|
||
| parent.fill_(7) | ||
| np.testing.assert_array_equal(view.numpy(), np.full(256, 7, dtype=bfloat16)) | ||
|
|
||
|
|
||
| def test_unknown_buffer_is_rejected(run): | ||
| with pytest.raises(ValueError, match="Unknown buffer"): | ||
| run.get_buffer("missing") | ||
|
|
||
|
|
||
| def test_out_of_bounds_slice_is_rejected_by_upstream(run): | ||
| run.op.slice_info["invalid"] = ("packed", 512, 1536) | ||
| with pytest.raises(ValueError): | ||
| run.get_buffer("invalid") | ||
|
|
||
|
|
||
| def test_input_slices_resolve_during_reference_dispatch(run, monkeypatch): | ||
| run.op.input_args = ["packed"] | ||
| parent = run.get_buffer("packed") | ||
|
|
||
| def evaluate(): | ||
| assert parent.device == "cpu" | ||
| for name in ("first", "second"): | ||
| view = run._resolve_buffer(name) | ||
| assert view.device == "cpu" | ||
| np.testing.assert_array_equal(view.numpy(), parent.numpy()[:256]) | ||
|
|
||
| monkeypatch.setattr(run, "_run", evaluate) | ||
| for value in (3, 7): | ||
| parent.fill_(value) | ||
| run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Trace dumps use the upstream tensor's host interface without torch.""" | ||
|
|
||
| import json | ||
| from types import SimpleNamespace | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| from aie.utils.hostruntime.tensor_class import CPUOnlyTensor | ||
|
|
||
| from iron.common import tracing_utils | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dtype", [np.int8, np.uint8]) | ||
| def test_dump_preserves_raw_trace_bits(monkeypatch, tmp_path, dtype): | ||
| words = np.array([0xFFFFFFFF, 0x80000000, 0x12345678, 0], dtype=np.uint32) | ||
| buffer = CPUOnlyTensor(words.view(dtype), dtype=dtype) | ||
| run = SimpleNamespace(trace_buffer=buffer) | ||
| monkeypatch.setattr( | ||
| tracing_utils, "lowered_mlir", lambda run: (tmp_path / "test.mlir", "mlir") | ||
| ) | ||
| events = [{"name": "event"}] | ||
|
|
||
| def parse(actual, mlir_text, colshift): | ||
| np.testing.assert_array_equal(actual, words) | ||
| assert mlir_text == "mlir" | ||
| assert colshift == 2 | ||
| return [(None, events)] | ||
|
|
||
| monkeypatch.setattr(tracing_utils, "parse_trace_buffer", parse) | ||
| written = tracing_utils.dump_traces( | ||
| run, "test", out_dir=tmp_path, colshift=2, summary=False | ||
| ) | ||
|
|
||
| assert written == [tmp_path / "test_trace.json"] | ||
| assert json.loads(written[0].read_text()) == events | ||
| assert (tmp_path / "test.txt").read_text().splitlines() == [ | ||
| "ffffffff", | ||
| "80000000", | ||
| "12345678", | ||
| "00000000", | ||
| ] | ||
|
|
||
|
|
||
| def test_untraced_run_needs_no_buffer(tmp_path): | ||
| assert tracing_utils.dump_traces(SimpleNamespace(), "test", tmp_path) == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worked in the past, why was there a permission error now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn’t new—I checked the successful devel run from September 16, and it already logged the identical
/var/lib/apt/lists/lock ... Permission deniederror.The workflow appeared to work because:
apt-get updatewas the left side of&&, so Bash’s-edid not exit when it failed; the install was skipped.pip installsucceeded, making the step green.My earlier explanation should have distinguished this hidden pre-existing error from the actual PR failure, which was Black formatting.
sudomakes the apt commands work as intended, and separate lines ensure failures aren’t masked. Both latest lint runs now pass; no further code changes were needed.