Caffe2 - C++ API
A deep learning, cross platform ML framework
DeviceGuard.h
1 #pragma once
2 
3 #include <c10/core/DeviceGuard.h>
4 #include <ATen/core/Tensor.h>
5 #include <c10/core/ScalarType.h> // TensorList whyyyyy
6 
7 namespace at {
8 
9 // Are you here because you're wondering why DeviceGuard(tensor) no
10 // longer works? For code organization reasons, we have temporarily(?)
11 // removed this constructor from DeviceGuard. The new way to
12 // spell it is:
13 //
14 // OptionalDeviceGuard guard(device_of(tensor));
15 
18  if (t.defined()) {
19  return make_optional(t.device());
20  } else {
21  return nullopt;
22  }
23 }
24 
29  if (!t.empty()) {
30  return device_of(t.front());
31  } else {
32  return nullopt;
33  }
34 }
35 
36 } // namespace at
AT_CPP14_CONSTEXPR const T & front() const
front - Get the first element.
Definition: ArrayRef.h:143
optional< Device > device_of(Tensor t)
Return the Device of a Tensor, if the Tensor is defined.
Definition: DeviceGuard.h:17
Device device() const
Returns a Tensor&#39;s device.
constexpr bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:129
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
Flush-To-Zero and Denormals-Are-Zero mode.