File size: 427 Bytes
b4f3263
 
 
 
 
 
 
 
 
 
 
933b7b6
b4f3263
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import torch


class DeviceManager:
    _instance = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(DeviceManager, cls).__new__(cls)
            cls._instance.device = torch.device(
                "cuda" if torch.cuda.is_available() else "cpu")
        print("using c̶p̶u̶ cuda" if torch.cuda.is_available() else "using c̶u̶d̶a̶ cpu")
        return cls._instance.device