-
Notifications
You must be signed in to change notification settings - Fork 269
Only enumerate ROCm-capable AMD GPUs #1500
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """utilities for working with AMDKFD driver""" | ||
|
|
||
| import glob | ||
|
|
||
|
|
||
| def parse_props(path): | ||
| """Returns a dict corresponding to a KFD properties file""" | ||
| with open(path) as file: | ||
| return {key: int(value) for key, _, value in (line.partition(' ') for line in file)} | ||
|
|
||
|
|
||
| def gpus(): | ||
| """Yields GPU nodes within KFD topology and their properties""" | ||
| for np in sorted(glob.glob('/sys/devices/virtual/kfd/kfd/topology/nodes/*')): | ||
| props = parse_props(np + '/properties') | ||
|
|
||
| # Skip CPUs | ||
| if props['gfx_target_version'] == 0: | ||
| continue | ||
|
|
||
| yield np, props |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||||
| import urllib.error | ||||||
| from typing import List | ||||||
|
|
||||||
| import ramalama.amdkfd as amdkfd | ||||||
| import ramalama.console as console | ||||||
| from ramalama.http_client import HttpClient | ||||||
| from ramalama.logger import logger | ||||||
|
|
@@ -35,6 +36,8 @@ | |||||
|
|
||||||
| DEFAULT_IMAGE = "quay.io/ramalama/ramalama" | ||||||
|
|
||||||
| MIN_VRAM_BYTES = 1073741824 # 1GiB | ||||||
|
|
||||||
|
|
||||||
| _engine = -1 # -1 means cached variable not set yet | ||||||
| _nvidia = -1 # -1 means cached variable not set yet | ||||||
|
|
@@ -447,12 +450,24 @@ def check_ascend(): | |||||
| def check_rocm_amd(): | ||||||
| gpu_num = 0 | ||||||
| gpu_bytes = 0 | ||||||
| for i, fp in enumerate(sorted(glob.glob('/sys/bus/pci/devices/*/mem_info_vram_total'))): | ||||||
| with open(fp, 'r') as file: | ||||||
| content = int(file.read()) | ||||||
| if content > 1073741824 and content > gpu_bytes: | ||||||
| gpu_bytes = content | ||||||
| gpu_num = i | ||||||
| for i, (np, props) in enumerate(amdkfd.gpus()): | ||||||
| # Radeon GPUs older than gfx900 are not supported by ROCm (e.g. Polaris) | ||||||
| if props['gfx_target_version'] < 90000: | ||||||
| continue | ||||||
|
|
||||||
| mem_banks_count = int(props['mem_banks_count']) | ||||||
| mem_bytes = 0 | ||||||
| for bank in range(mem_banks_count): | ||||||
| bank_props = amdkfd.parse_props(np + f'/mem_banks/{bank}/properties') | ||||||
| # See /usr/include/linux/kfd_sysfs.h for possible heap types | ||||||
| # | ||||||
| # Count public and private framebuffer memory as VRAM | ||||||
| if bank_props['heap_type'] in [1, 2]: | ||||||
|
||||||
| if bank_props['heap_type'] in [1, 2]: | |
| if bank_props['heap_type'] in [HEAP_TYPE_PUBLIC, HEAP_TYPE_PRIVATE]: |
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.
If this is correct we should try and take this is another PR @alaviss . I have no idea what 1 and 2 mean.
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.
[nitpick] Path construction via string concatenation can be fragile; prefer
os.path.join(np, 'mem_banks', str(bank), 'properties').