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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from unittest.mock import Mock

import pytest
from rocke.assets import dsl_docs_dir
from rocke.core.ir import KernelDef
from rocke.tests.source_tree import require_dsl_docs

_PROBE_MODULES = (
"probe_occupancy",
Expand All @@ -32,9 +32,7 @@ def demos():
/ "common"
/ "dsl_probe_attention_demos.py"
)
probe_dir = dsl_docs_dir() / "optimization" / "utilities" / "tools" / "dsl_probes"
if not all((probe_dir / f"{name}.py").is_file() for name in _PROBE_MODULES):
pytest.skip(f"attention CLI probe source assets unavailable: {probe_dir}")
require_dsl_docs() # the driver imports its probes from the dsl_docs tree
saved_path = sys.path[:]
saved_modules = {
name: sys.modules[name] for name in _PROBE_MODULES if name in sys.modules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT

"""Test helper: reach the ``dsl_docs`` tree, which exists only in a source checkout.

The installed test payload carries the ``rocke`` package and most of the test
tree, but not ``dsl_docs/``: that tree is documentation and authoring tools, and
it stays in the source checkout. A test that reads it is a source-tree check. It
runs where the tree exists and skips, with the reason, in the installed layout.

def test_doc_names_every_target():
doc = require_dsl_docs() / "reference" / "dtype_support.md"
...

The skip is keyed on the tree, not on the file the test reads. Where the tree
exists, a file missing from it (a renamed or deleted doc) fails the test.

Use this for a source-tree check inside a test file that is otherwise installed.
A test file that is source-tree tooling throughout is instead left out of the
install (the exclusion list in ``platform/CMakeLists.txt``).
"""

from __future__ import annotations

from pathlib import Path

import pytest

from rocke.assets import dsl_docs_dir

__all__ = ["require_dsl_docs"]


def require_dsl_docs() -> Path:
"""Return the ``dsl_docs`` tree, or skip the test when this layout lacks it."""
docs = dsl_docs_dir()
if not docs.is_dir():
pytest.skip(
f"source-tree check: no dsl_docs tree at {docs}; the installed test "
"payload does not ship it"
)
return docs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import os
import re
from importlib.resources import files

import numpy as np
import pytest
from rocke.assets import dsl_docs_dir, platform_root
from rocke.core.arch import ArchTarget, known_arches
from rocke.core.backend import universal_gemm_spec_to_dict
from rocke.instances.common.gemm_universal import (
Expand All @@ -26,6 +26,7 @@
from rocke.tests.arch_marks import arch_specific
from rocke.tests.engines import available_engines
from rocke.tests.gpu import current_device_arch_in
from rocke.tests.source_tree import require_dsl_docs
from rocke.tests.universal_gemm import launch_universal_gemm, lower_universal_gemm


Expand Down Expand Up @@ -271,15 +272,7 @@ def _doc_sentences(text):
yield from re.split(r"(?<=[.;])\s+|(?<=\.\*\*)\s+", " ".join(block.split()))


@pytest.mark.parametrize(
"doc",
[
dsl_docs_dir() / "reference" / "dtype_support.md",
platform_root() / "python" / "rocke" / "instances" / "SUPPORT_MATRIX.md",
],
ids=lambda path: path.name,
)
def test_f64_gemm_doc_sentences_name_every_admitted_target(doc):
def _assert_names_every_admitted_target(doc):
"""A sentence that places fp64 universal GEMM on named targets names all of
them, so no summary line describes it as narrower than the validator."""
narrower = []
Expand All @@ -292,6 +285,18 @@ def test_f64_gemm_doc_sentences_name_every_admitted_target(doc):
assert not narrower, f"{doc.name} names only some fp64 GEMM targets in: {narrower}"


def test_dtype_support_doc_names_every_f64_gemm_target():
_assert_names_every_admitted_target(
require_dsl_docs() / "reference" / "dtype_support.md"
)


def test_support_matrix_names_every_f64_gemm_target():
# Read through the package, so the CMake-installed test payload, which
# installs the package directory whole, checks its copy too.
_assert_names_every_admitted_target(files("rocke.instances") / "SUPPORT_MATRIX.md")


@pytest.mark.parametrize("arch", _F64_GEMM_ARCHS_WITHOUT_DMA)
def test_f64_gemm_direct_to_lds_refused_without_dma(arch):
spec = _spec((64, 64, 16, 2, 2), "compv3", "cshuffle", direct_to_lds=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT

"""The source-tree helper returns the ``dsl_docs`` tree or skips without it.

The helper's skip hides every check built on it, so a helper that skipped a present
tree would turn those checks off silently. These tests point the helper at a tree
through its documented ``ROCKE_DSL_DOCS`` override: a present tree must come back
(a skip there fails the test), and an absent tree must skip, naming the path.
"""

from __future__ import annotations

from pathlib import Path

import pytest
from rocke.tests.source_tree import require_dsl_docs


def _require_present_dsl_docs() -> Path:
"""Call the helper where the tree exists, turning its skip into a failure."""
try:
return require_dsl_docs()
except pytest.skip.Exception as skip:
pytest.fail(f"require_dsl_docs() skipped a present tree: {skip}")


def test_returns_a_present_tree(monkeypatch, tmp_path):
docs = tmp_path / "dsl_docs"
docs.mkdir()
monkeypatch.setenv("ROCKE_DSL_DOCS", str(docs))
assert _require_present_dsl_docs() == docs


def test_skips_an_absent_tree_and_names_it(monkeypatch, tmp_path):
docs = tmp_path / "dsl_docs"
monkeypatch.setenv("ROCKE_DSL_DOCS", str(docs))
with pytest.raises(pytest.skip.Exception) as skip:
require_dsl_docs()
assert str(skip.value) == (
f"source-tree check: no dsl_docs tree at {docs}; the installed test "
"payload does not ship it"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
from dataclasses import dataclass

import pytest
from rocke.assets import dsl_docs_dir
from rocke.core.arch import domain as arch_domain
from rocke.core.ir import F16, I32, IRBuilder, PtrType
from rocke.core.lower_llvm import ArchDomainWarning, lower_kernel_to_llvm
from rocke.tests.source_tree import require_dsl_docs

_ARCH, _FLAVOR = "gfx942", "llvm22"


def _load(name):
path = dsl_docs_dir() / "optimization/utilities/tools/dsl_probes" / f"{name}.py"
if not path.is_file():
pytest.skip("dsl_probes source tools are absent from this test layout")
probes = require_dsl_docs() / "optimization" / "utilities" / "tools" / "dsl_probes"
path = probes / f"{name}.py"
spec = importlib.util.spec_from_file_location(f"rocke_test_{name}", path)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
Expand Down
Loading