Skip to content
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

feat: Remove device information in image class #735

Merged
merged 14 commits into from
May 7, 2024
Merged
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: 3 additions & 1 deletion src/safeds/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import apipkg

if TYPE_CHECKING:
from ._device import _get_device
from ._device import _get_device, _init_default_device

apipkg.initpkg(
__name__,
{
"_get_device": "._device:_get_device",
"_init_default_device": "._device:_init_default_device",
},
)

__all__ = [
"_get_device",
"_init_default_device",
]
24 changes: 23 additions & 1 deletion src/safeds/_config/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
from torch.types import Device


_default_device: Device | None = None


def _get_device() -> Device:
import torch

return torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
return torch.get_default_device()


def _init_default_device() -> None:
import torch

global _default_device

if _default_device is None:
_default_device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

torch.set_default_device(_default_device)


def _set_default_device(device: Device) -> None:
# This changes all future tensors, but not any tensor that already exists
global _default_device

_default_device = device
_init_default_device()
Loading