Skip to content

Intel ARC DirectML support (broken) #47

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions sdkit/models/model_loader/stable_diffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def load_diffusers_model(context: Context, model_path, config_file_path, convert
import platform

from sdkit.generate.sampler import diffusers_samplers
from sdkit.utils import gc, has_amd_gpu
from sdkit.utils import gc, get_directml_device_id

from diffusers.pipelines.stable_diffusion.convert_from_ckpt import download_from_original_stable_diffusion_ckpt
from . import diffusers_bugfixes
Expand Down Expand Up @@ -159,7 +159,7 @@ def load_diffusers_model(context: Context, model_path, config_file_path, convert
unet_trt_path = model_component + ".unet.trt"
unet_onnx_path = model_component + ".unet.onnx"

use_directml = platform.system() == "Windows" and has_amd_gpu()
use_directml = (get_directml_device_id() != None)
try:
from importlib.metadata import version

Expand Down
12 changes: 2 additions & 10 deletions sdkit/models/model_loader/stable_diffusion/accelerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
import numpy as np

from sdkit.utils import log
from sdkit.utils import log, get_directml_device_id

"""
Current issues:
Expand Down Expand Up @@ -53,15 +53,7 @@ def __init__(self, onnx_path):
# sess_options.add_free_dimension_override_by_name("encoder_hidden_states_batch", batch_size * 2)
# sess_options.add_free_dimension_override_by_name("encoder_hidden_states_sequence", 77)

import wmi

w = wmi.WMI()
device_id = 0
for i, controller in enumerate(w.Win32_VideoController()):
device_name = controller.wmi_property("Name").value
if "AMD" in device_name and "Radeon" in device_name:
device_id = i
break
device_id = get_directml_device_id()

log.info(f"Using DirectML device_id: {device_id}")
sess = ort.InferenceSession(
Expand Down
5 changes: 4 additions & 1 deletion sdkit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@
convert_pipeline_unet_to_onnx,
convert_pipeline_unet_to_tensorrt,
)
from .device_utils import has_amd_gpu
from .device_utils import (
has_amd_gpu,
get_directml_device_id
)
18 changes: 18 additions & 0 deletions sdkit/utils/device_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import platform
import subprocess
import wmi


def has_amd_gpu():
Expand All @@ -18,3 +19,20 @@ def has_amd_gpu():
return False

return False

def get_directml_device_id():
os_name = platform.system()

if os_name != "Windows":
return None

w = wmi.WMI()
device_id = None
for i, controller in enumerate(w.Win32_VideoController()):
device_name = controller.wmi_property("Name").value
if ("AMD" in device_name and "Radeon" in device_name) or ("Intel" in device_name and "Arc" in device_name):
device_id = i
break

return device_id