Skip to content

Commit

Permalink
Get device name without hlsmi (#240)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jerome-habana and pre-commit-ci[bot] authored Oct 17, 2024
1 parent 1b754e1 commit a33a6f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

-
- Fixed device name retrieval without hlsmi ([#240](https://github.com/Lightning-AI/lightning-Habana/pull/240))

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/lightning_habana/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.7.0"
__version__ = "1.7.0.rc0"
__author__ = "Lightning-AI et al."
__author_email__ = "[email protected]"
__license__ = "Apache-2.0"
Expand Down
15 changes: 13 additions & 2 deletions src/lightning_habana/utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ def get_hpu_synapse_version() -> str:
return hl or "0.0.0"


@lru_cache
def get_device_name_from_backend() -> str:
"""Return the name of the HPU device."""
try:
# this opens up a device to retrieve the name
return torch_hpu.get_device_name()
except (AttributeError, NameError):
# return GAUDI as default name
return "GAUDI"


def _parse_for_device_name(line: str) -> str:
"""Parse the CMD output with version capture.
Expand Down Expand Up @@ -123,9 +134,9 @@ def get_device_name_from_hlsmi() -> str:
"""Get hpu device name from hl-smi."""
try:
proc = subprocess.Popen(["hl-smi", "-L"], stdout=subprocess.PIPE)
# TODO: FileNotFoundError: No such file or directory: 'hl-smi'
except (FileNotFoundError, NotADirectoryError):
return "GAUDI"
# if hl-smi is not present, we open a device to get the name
return get_device_name_from_backend()
out = proc.communicate()[0]
return _parse_for_device_name(out.decode("utf-8"))

Expand Down

0 comments on commit a33a6f3

Please sign in to comment.