Skip to content

Commit

Permalink
Add physical device to header
Browse files Browse the repository at this point in the history
...to avoid confusion with device context

Signed-off-by: U. Artie Eoff <[email protected]>
  • Loading branch information
uartie committed Feb 27, 2025
1 parent 05999ec commit ae5ce34
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,29 @@ def __str___(self):
def pytest_addoption(parser):
parser.addoption("--token", action="store", default=None)
parser.addoption("--rebase", action="store_true", help="rebase baseline references from current run")
parser.addoption("--device", action="store", default=None)
parser.addoption("--device", "--device-context", action="store", default=None)


@pytest.fixture
def token(request):
return Secret(request.config.option.token)


def pytest_configure(config):
name = ""
try:
import habana_frameworks.torch.hpu as torch_hpu

name = torch_hpu.get_device_name().strip()
finally:
config.stash["physical_device"] = "" if not name else name.split()[-1].lower()


def pytest_sessionstart(session):
session.stash["baseline"] = Baseline(session)

physical_device = session.config.stash["physical_device"]

# User command-line option takes highest priority
if session.config.option.device is not None:
device = str(session.config.option.device).lower()
Expand All @@ -115,12 +127,9 @@ def pytest_sessionstart(session):
device = "gaudi2" if os.environ["GAUDI2_CI"] == "1" else "gaudi1"
# Try to automatically detect it
else:
import habana_frameworks.torch.hpu as torch_hpu

name = torch_hpu.get_device_name().strip()
if not name:
if not physical_device:
raise RuntimeError("Expected a Gaudi device but did not detect one.")
device = name.split()[-1].lower()
device = physical_device

# torch_hpu.get_device_name() returns GAUDI for G1
if "gaudi" == device:
Expand All @@ -130,8 +139,11 @@ def pytest_sessionstart(session):
oh_testutils.OH_DEVICE_CONTEXT = device


def pytest_report_header():
return [f"device context: {oh_testutils.OH_DEVICE_CONTEXT}"]
def pytest_report_header(config):
return [
f"device physical: {config.stash['physical_device'] or '??'}",
f"device context : {oh_testutils.OH_DEVICE_CONTEXT}",
]


def pytest_sessionfinish(session):
Expand Down

0 comments on commit ae5ce34

Please sign in to comment.