Skip to content

Commit e6a9640

Browse files
authored
Add os agnostic vulkan device name check (huggingface#445)
1 parent e3e767c commit e6a9640

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

shark/iree_utils/vulkan_utils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,28 @@
1414

1515
# All the iree_vulkan related functionalities go here.
1616

17+
from os import linesep
1718
from shark.iree_utils._common import run_cmd
1819

1920

21+
def get_vulkan_device_name():
22+
vulkaninfo_dump = run_cmd("vulkaninfo").split(linesep)
23+
vulkaninfo_list = [s.strip() for s in vulkaninfo_dump if "deviceName" in s]
24+
if len(vulkaninfo_list) == 0:
25+
raise ValueError("No device name found in VulkanInfo!")
26+
if len(vulkaninfo_list) > 1:
27+
print(
28+
f"Found {len(vulkaninfo_list)} device names. choosing first one: {vulkaninfo_list[0]}"
29+
)
30+
return vulkaninfo_list[0]
31+
32+
2033
def get_vulkan_triple_flag(extra_args=[]):
2134
if "-iree-vulkan-target-triple=" in " ".join(extra_args):
2235
print(f"Using target triple from command line args")
2336
return None
2437

25-
vulkan_device_cmd = "vulkaninfo | grep deviceName"
26-
vulkan_device = run_cmd(vulkan_device_cmd).strip()
38+
vulkan_device = get_vulkan_device_name()
2739
if all(x in vulkan_device for x in ("Apple", "M1")):
2840
print(f"Found {vulkan_device} Device. Using m1-moltenvk-macos")
2941
return "-iree-vulkan-target-triple=m1-moltenvk-macos"

0 commit comments

Comments
 (0)