:github_url: https://github.com/pytorch/pytorch .. _program_listing_file_aten_src_ATen_DeviceGuard.h: Program Listing for File DeviceGuard.h ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``aten/src/ATen/DeviceGuard.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include // TensorList whyyyyy namespace at { // Are you here because you're wondering why DeviceGuard(tensor) no // longer works? For code organization reasons, we have temporarily(?) // removed this constructor from DeviceGuard. The new way to // spell it is: // // OptionalDeviceGuard guard(device_of(tensor)); inline std::optional device_of(const Tensor& t) { if (t.defined()) { return t.device(); } else { return std::nullopt; } } inline std::optional device_of(const std::optional& t) { return t.has_value() ? device_of(t.value()) : std::nullopt; } inline std::optional device_of(ITensorListRef t) { if (!t.empty()) { return device_of(t.front()); } else { return std::nullopt; } } } // namespace at