-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add XPU support to basic GNN examples (#9421)
Add XPU support to basic GNN examples(gat,gcn, graphsage. etc.) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: rusty1s <[email protected]>
- Loading branch information
1 parent
9b7874b
commit cd36c86
Showing
9 changed files
with
84 additions
and
34 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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Any | ||
|
||
import torch | ||
|
||
|
||
def is_mps_available() -> bool: | ||
r"""Returns a bool indicating if MPS is currently available.""" | ||
if hasattr(torch.backends, 'mps') and torch.backends.mps.is_available(): | ||
try: # Github CI may not have access to MPS hardware. Confirm: | ||
torch.empty(1, device='mps') | ||
return True | ||
except Exception: | ||
return False | ||
return False | ||
|
||
|
||
def is_xpu_available() -> bool: | ||
r"""Returns a bool indicating if XPU is currently available.""" | ||
if hasattr(torch, 'xpu') and torch.xpu.is_available(): | ||
return True | ||
try: | ||
import intel_extension_for_pytorch as ipex | ||
return ipex.xpu.is_available() | ||
except ImportError: | ||
return False | ||
|
||
|
||
def device(device: Any) -> torch.device: | ||
r"""Returns a :class:`torch.device`. | ||
If :obj:`"auto"` is specified, returns the optimal device depending on | ||
available hardware. | ||
""" | ||
if device != 'auto': | ||
return torch.device(device) | ||
if torch.cuda.is_available(): | ||
return torch.device('cuda') | ||
if is_mps_available(): | ||
return torch.device('mps') | ||
if is_xpu_available(): | ||
return torch.device('xpu') | ||
return torch.device('cpu') |
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