-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reserve interface for other torch devices (#27)
- Loading branch information
Showing
5 changed files
with
37 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from Final2x_core.util.progressLog import PrintProgressLog # noqa | ||
from Final2x_core.util.singleton import singleton # noqa | ||
from Final2x_core.util.device import get_device # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Union | ||
|
||
import torch | ||
from ccrestoration.util.device import default_device | ||
|
||
|
||
def get_device(device: str) -> Union[torch.device, str]: | ||
""" | ||
Get device from string | ||
:param device: device string | ||
""" | ||
if device.startswith("auto"): | ||
return default_device() | ||
elif device.startswith("cpu"): | ||
return torch.device("cpu") | ||
elif device.startswith("cuda"): | ||
return torch.device("cuda") | ||
elif device.startswith("mps"): | ||
return torch.device("mps") | ||
elif device.startswith("directml"): | ||
import torch_directml | ||
|
||
return torch_directml.device() | ||
elif device.startswith("xpu"): | ||
return torch.device("xpu") | ||
else: | ||
print(f"Unknown device: {device}, use auto instead.") | ||
return default_device() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters