Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions dnn-providers/hip-kernel-provider/rocke/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cd platform && export ROCKE=$(pwd) PYTHONPATH=$ROCKE/python
ROCKE_LLVM_FLAVOR=llvm20 python tools/check_byte_identity.py # llvm20
ROCKE_LLVM_FLAVOR=llvm22 python tools/check_byte_identity.py # llvm22
ROCKE_LLVM_FLAVOR=llvm23 python tools/check_byte_identity.py # llvm23
ROCKE_LLVM_FLAVOR=llvm24 python tools/check_byte_identity.py # llvm24
python tools/check_byte_identity.py --only gemm # scope to a family
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"arches": {
"gfx942": {
"flavors": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"aliases": {"llvm24": "llvm23"},
"flavors": {
"llvm20": {
"cases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
from pathlib import Path

import pytest
from rocke.core.ir_golden import (
GOLDEN_ALIASES,
GOLDEN_FLAVORS,
GOLDEN_PROFILE_FLAVORS,
golden_subdocument,
)

from ._attention_bwd_test_utils import kernel_signature

_TESTS = Path(__file__).resolve().parent
Expand All @@ -49,7 +56,7 @@
sys.path.insert(0, _LIB_ROOT)

_GOLDEN = _TESTS / "golden" / "attention_dense_bwd_ir_sha256.json"
_FLAVORS = ("llvm20", "llvm22", "llvm23")
_FLAVORS = GOLDEN_FLAVORS
_ARCHS = ("gfx942", "gfx950")


Expand Down Expand Up @@ -383,8 +390,12 @@ def _current_flavor():


def _build_doc():
doc = {"schema": "attention_dense_bwd.ir_golden_sha256/v1", "flavors": {}}
for flavor in _FLAVORS:
doc = {
"schema": "attention_dense_bwd.ir_golden_sha256/v1",
"aliases": GOLDEN_ALIASES,
"flavors": {},
}
for flavor in GOLDEN_PROFILE_FLAVORS:
cases = {}
for arch in _ARCHS:
for key, over, dq in _golden_rows(arch):
Expand All @@ -402,7 +413,7 @@ def test_dense_bwd_ir_matches_golden(arch, flavor):
if not _GOLDEN.exists():
pytest.fail("dense backward golden fixture missing; generate with --write")
golden = json.loads(_GOLDEN.read_text())
gflav = golden.get("flavors", {}).get(flavor)
gflav = golden_subdocument(golden, flavor)
if not gflav:
pytest.fail(f"no dense backward golden recorded for llvm flavor {flavor!r}")
drift = []
Expand All @@ -419,9 +430,16 @@ def test_dense_bwd_ir_matches_golden(arch, flavor):

def test_golden_covers_every_case_and_flavor():
golden = json.loads(_GOLDEN.read_text())
aliases = golden.get("aliases", {})
direct = golden.get("flavors", {})
assert aliases == GOLDEN_ALIASES
assert set(direct) == set(GOLDEN_PROFILE_FLAVORS)
assert not set(aliases) & set(direct)
want = {key for a in _ARCHS for key, _, _ in _golden_rows(a)}
for flavor in _FLAVORS:
got = set(golden["flavors"][flavor]["cases"])
sub = golden_subdocument(golden, flavor)
assert sub is not None, flavor
got = set(sub["cases"])
assert got == want, flavor


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ def _run(flavor):


def _build_doc():
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_ALIASES, GOLDEN_PROFILE_FLAVORS

return {
"schema": "attention_dense_gfx942.ir_golden_sha256/v1",
"flavors": {fl: _run(fl) for fl in GOLDEN_FLAVORS},
"aliases": GOLDEN_ALIASES,
"flavors": {fl: _run(fl) for fl in GOLDEN_PROFILE_FLAVORS},
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
_PLATFORM_PYTHON = _LIBRARY.parent / "platform" / "python"
_GOLDEN = _TESTS / "golden" / "dsa_indexer_ir_sha256.json"
_SCHEMA = "dsa_indexer.ir_golden_sha256/v1"
_FLAVORS = ("llvm20", "llvm22", "llvm23")
_ARCHES = ("gfx942", "gfx950")

for _path in (str(_LIBRARY), str(_PLATFORM_PYTHON)):
if _path not in sys.path:
sys.path.insert(0, _path)

from rocke.core.ir_golden import ( # noqa: E402
GOLDEN_ALIASES,
GOLDEN_FLAVORS,
GOLDEN_PROFILE_FLAVORS,
)


def _cases() -> dict[str, Callable]:
"""Representative builders, arch-neutral (the arch is applied at lower time).
Expand Down Expand Up @@ -91,12 +96,6 @@ def _cases() -> dict[str, Callable]:
}


def _current_flavor() -> str:
from rocke.core.lower_llvm import _resolve_llvm_flavor

return _resolve_llvm_flavor()


def _sha_for(build: Callable, arch: str, flavor: str) -> tuple[str, int]:
from rocke.core.lower_llvm import _lower_kernel_to_llvm_python

Expand All @@ -109,6 +108,7 @@ def _build_doc() -> dict:
cases = _cases()
return {
"schema": _SCHEMA,
"aliases": GOLDEN_ALIASES,
"arches": {
arch: {
"flavors": {
Expand All @@ -119,16 +119,17 @@ def _build_doc() -> dict:
for sha, nbytes in [_sha_for(build, arch, flavor)]
}
}
for flavor in _FLAVORS
for flavor in GOLDEN_PROFILE_FLAVORS
}
}
for arch in _ARCHES
},
}


@pytest.mark.parametrize("flavor", GOLDEN_FLAVORS)
@pytest.mark.parametrize("arch", _ARCHES)
def test_dsa_indexer_ir_matches_golden(arch: str):
def test_dsa_indexer_ir_matches_golden(arch: str, flavor: str):
assert _GOLDEN.exists(), (
f"missing indexer golden fixture; generate it with "
f"`python {Path(__file__).name} --write`"
Expand All @@ -137,15 +138,17 @@ def test_dsa_indexer_ir_matches_golden(arch: str):
assert golden.get("schema") == _SCHEMA
assert arch in golden.get("arches", {}), f"no golden recorded for arch {arch!r}"

flavor = _current_flavor()
assert golden.get("aliases", {}) == GOLDEN_ALIASES
golden_flavor = golden.get("aliases", {}).get(flavor, flavor)
arch_doc = golden["arches"][arch]
assert flavor in arch_doc.get("flavors", {}), (
assert set(arch_doc.get("flavors", {})) == set(GOLDEN_PROFILE_FLAVORS)
assert golden_flavor in arch_doc.get("flavors", {}), (
f"no {arch} indexer golden recorded for LLVM flavor {flavor!r}; "
"review and re-bless the fixture"
)

cases = _cases()
recorded = arch_doc["flavors"][flavor]["cases"]
recorded = arch_doc["flavors"][golden_flavor]["cases"]
assert set(recorded) == set(cases), (
f"{arch} indexer golden case set drifted: "
f"recorded={sorted(recorded)}, current={sorted(cases)}"
Expand All @@ -171,5 +174,6 @@ def test_dsa_indexer_ir_matches_golden(arch: str):
print(f"wrote {_GOLDEN}")
else:
for _arch in _ARCHES:
test_dsa_indexer_ir_matches_golden(_arch)
for _flavor in GOLDEN_FLAVORS:
test_dsa_indexer_ir_matches_golden(_arch, _flavor)
print("PASS")
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,15 @@ def _run(flavor):


def _build_doc():
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_ALIASES, GOLDEN_PROFILE_FLAVORS

doc = {"schema": "gdn_decode_gfx950.ir_golden_sha256/v1", "flavors": {}}
doc = {
"schema": "gdn_decode_gfx950.ir_golden_sha256/v1",
"aliases": GOLDEN_ALIASES,
"flavors": {},
}
failures = []
for flavor in GOLDEN_FLAVORS:
for flavor in GOLDEN_PROFILE_FLAVORS:
cases = {}
for cid, build in _cases().items():
try:
Expand Down Expand Up @@ -424,18 +428,21 @@ def test_gdn_decode_ir_matches_golden():
def test_every_shipped_configuration_is_recorded():
"""A new tuned tile must arrive with a golden entry, not silently uncovered."""
import pytest
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_FLAVORS, golden_subdocument

if not _GOLDEN.exists():
pytest.skip("gdn_decode golden fixture missing; generate with --write")
golden = json.loads(_GOLDEN.read_text())
flavors = golden.get("flavors", {})
# A flavor with no sub-document leaves every configuration unrecorded.
# A lane with no direct or aliased profile document leaves every
# configuration unrecorded.
missing = sorted(
f"{flavor}/{cid}"
for flavor in GOLDEN_FLAVORS
for cid in _cases()
if not flavors.get(flavor, {}).get("cases", {}).get(cid, {}).get("sha256")
if not (golden_subdocument(golden, flavor) or {})
.get("cases", {})
.get(cid, {})
.get("sha256")
)
assert not missing, f"configurations without a SHA-256: {missing}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def _run(flavor: str) -> dict:


def _build_doc() -> dict:
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_ALIASES, GOLDEN_PROFILE_FLAVORS

return {
"schema": "kda_gfx942.ir_golden_sha256/v1",
"flavors": {flavor: _run(flavor) for flavor in GOLDEN_FLAVORS},
"aliases": GOLDEN_ALIASES,
"flavors": {flavor: _run(flavor) for flavor in GOLDEN_PROFILE_FLAVORS},
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ def _run(flavor: str) -> dict:


def _build_doc() -> dict:
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_ALIASES, GOLDEN_PROFILE_FLAVORS

return {
"schema": "kda_gfx950.ir_golden_sha256/v1",
"flavors": {flavor: _run(flavor) for flavor in GOLDEN_FLAVORS},
"aliases": GOLDEN_ALIASES,
"flavors": {flavor: _run(flavor) for flavor in GOLDEN_PROFILE_FLAVORS},
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ def _run(flavor):


def _build_doc():
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_ALIASES, GOLDEN_PROFILE_FLAVORS

return {
"schema": _SCHEMA,
"flavors": {fl: _run(fl) for fl in GOLDEN_FLAVORS},
"aliases": GOLDEN_ALIASES,
"flavors": {fl: _run(fl) for fl in GOLDEN_PROFILE_FLAVORS},
}


Expand All @@ -215,12 +216,13 @@ def test_mla_prefill_gfx942_golden_covers_every_case():
Without this, a case added to ``_cases()`` but never blessed would be
silently skipped rather than failing, and a typo'd cid would pin nothing.
"""
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_FLAVORS, golden_subdocument

golden = _golden()
want = set(_cases())
for flavor in GOLDEN_FLAVORS:
sub = golden["flavors"][flavor]
sub = golden_subdocument(golden, flavor)
assert sub is not None, flavor
hashed = set(sub["cases"])
refused = set(sub.get("expected_failures", {}))
assert not hashed & refused, f"{flavor}: {sorted(hashed & refused)}"
Expand All @@ -235,15 +237,17 @@ def test_mla_prefill_gfx942_golden_expected_failures_are_the_llvm20_agpr_refusal
"""The only refusals the golden may hold are the agpr_acc cases at llvm20;
anything else recorded as an expected failure is a failed bless, not a
golden."""
from rocke.core.ir_golden import GOLDEN_FLAVORS
from rocke.core.ir_golden import GOLDEN_FLAVORS, golden_subdocument

agpr_cases = {
"mla_prefill_gfx942/fwd_h128_agpr",
"mla_prefill_gfx942/fwd_h128_agpr_aq",
}
golden = _golden()
for flavor in GOLDEN_FLAVORS:
refused = golden["flavors"][flavor].get("expected_failures", {})
sub = golden_subdocument(golden, flavor)
assert sub is not None, flavor
refused = sub.get("expected_failures", {})
if flavor == "llvm20":
assert set(refused) == agpr_cases
for cid in agpr_cases:
Expand Down
5 changes: 3 additions & 2 deletions dnn-providers/hip-kernel-provider/rocke/platform/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ change must be made in **both** engines in the same change. Prove it:
ROCKE_LLVM_FLAVOR=llvm20 python tools/check_byte_identity.py # build engine fresh + gate
ROCKE_LLVM_FLAVOR=llvm22 python tools/check_byte_identity.py # and llvm22
ROCKE_LLVM_FLAVOR=llvm23 python tools/check_byte_identity.py # and llvm23
ROCKE_LLVM_FLAVOR=llvm24 python tools/check_byte_identity.py # and llvm24
```

A change is done only when the gate is GREEN for every family at every flavor.
The llvm20 and llvm22 runs also re-run the `gfx1250_lowering` family at llvm23,
because its gfx1250-only ops lower at no other flavor.
because its gfx1250-only ops need the LLVM23-generation emission profile.

## Build / test / run

Expand Down Expand Up @@ -481,7 +482,7 @@ dual-engine vs Python-only split.
| `ROCKE_BACKEND` | `cpp` (default) \| `python` \| `both` (differential assert) |
| `ROCKE_CPP_STRICT` | `1` = raise instead of silently falling back to Python when `rocke_engine` isn't built |
| `ROCKE_DEBUG_LOC` | `1` = capture Python source locations while building and emit DWARF, so ATT traces map to source; off by default because it changes the emitted `.ll` |
| `ROCKE_LLVM_FLAVOR` | `llvm20` \| `llvm22` \| `llvm23` (AUTO queries the loaded COMGR compiler: LLVM <=20, 21/22, >=23; unavailable evidence raises; explicit flavors support offline emission) |
| `ROCKE_LLVM_FLAVOR` | `llvm20` \| `llvm22` \| `llvm23` \| `llvm24` (AUTO queries loaded COMGR: LLVM <=20, 21/22, 23, or 24; newer majors and unavailable evidence raise; explicit lanes support offline emission) |
| `ROCKE_TEST_VERIFY_IR` | `1` = assemble emitted IR with `llvm-as` in `TestNewTargetIntrinsics`; needs an LLVM as new as the newest flavor |
| `ROCM_PATH` / `ROCM_HOME` | ROCm install root; `<root>/lib` is searched for `comgr`/HIP before the globbed `/opt/rocm*` trees |
| `ROCKE_COMGR_LIB` / `ROCKE_HIP_LIB` | explicit full path to `libamd_comgr` / `libamdhip64`; wins over all discovery |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4070,7 +4070,7 @@ std::vector<std::string> gfx1201_wmma_gemm_verify(const py::dict& d, const std::
* the engine's extern "C" boundary never aborts/terminates.
* ------------------------------------------------------------------------ */

/* "'llvm20', 'llvm22', 'llvm23'" -- built from the engine's flavor ladder so
/* Canonical concrete flavor names -- built from the engine's ladder so
* the message cannot drift from what from_name() actually accepts. */
static std::string rocke_engine_flavor_list()
{
Expand Down Expand Up @@ -4138,7 +4138,7 @@ std::string lower_serialized_ir(const std::string& ir_text,
fl = rocke_llvm_flavor_from_name(flavor.c_str());
if(fl == ROCKE_LLVM_FLAVOR_AUTO)
{
throw std::runtime_error(
throw pybind11::value_error(
std::string("rocke_engine.lower_serialized_ir: unknown LLVM flavor '") + flavor
+ "' (expected one of " + rocke_engine_flavor_list() + ")");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ static void rocke_b_gfx1250_scalar_control(rocke_ir_builder_t* b, const char* mn
if(!op)
return;
rocke_attr_set_str(b, &op->attrs, "required_arch", "gfx1250");
rocke_attr_set_str(b, &op->attrs, "required_llvm_flavor", "llvm23");
rocke_attr_set_str(b, &op->attrs, "minimum_llvm_flavor", "llvm23");
}

void rocke_b_s_delay_alu(rocke_ir_builder_t* b, int imm)
Expand Down
Loading
Loading