test_global_device.py 646 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Christian Heider Nielsen"
  4. __doc__ = r"""
  5. Created on 11/05/2020
  6. """
  7. from draugr.torch_utilities import (
  8. TorchCpuSession,
  9. TorchCudaSession,
  10. global_torch_device,
  11. )
  12. def test_cpu():
  13. print(global_torch_device(override=global_torch_device(device_preference=True)))
  14. print(global_torch_device())
  15. with TorchCpuSession():
  16. print(global_torch_device())
  17. with TorchCudaSession():
  18. print(global_torch_device())
  19. print(global_torch_device(override=global_torch_device(device_preference="cpu")))
  20. print(global_torch_device())