3 #include <c10/core/DeviceType.h> 4 #include <c10/core/TensorTypeId.h> 5 #include <c10/core/TensorTypeIdRegistration.h> 6 #include <c10/util/Exception.h> 23 enum class Backend { CPU, CUDA, HIP, SparseCPU, SparseCUDA, SparseHIP, MSNPU, XLA, Undefined, NumOptions };
28 return Backend::SparseCPU;
30 return Backend::SparseCUDA;
32 return Backend::SparseHIP;
33 case Backend::SparseCPU:
34 return Backend::SparseCPU;
35 case Backend::SparseCUDA:
36 return Backend::SparseCUDA;
37 case Backend::SparseHIP:
38 return Backend::SparseHIP;
40 throw std::runtime_error(
"Unknown backend");
53 return Backend::MSNPU;
56 case Backend::SparseCPU:
58 case Backend::SparseCUDA:
60 case Backend::SparseHIP:
63 throw std::runtime_error(
"Unknown backend");
68 if (t == CPUTensorId()) {
70 }
else if (t == CUDATensorId()) {
72 }
else if (t == HIPTensorId()) {
74 }
else if (t == MSNPUTensorId()) {
75 return Backend::MSNPU;
76 }
else if (t == XLATensorId()) {
78 }
else if (t == SparseCPUTensorId()) {
79 return Backend::SparseCPU;
80 }
else if (t == SparseCUDATensorId()) {
81 return Backend::SparseCUDA;
82 }
else if (t == SparseHIPTensorId()) {
83 return Backend::SparseHIP;
84 }
else if (t == UndefinedTensorId()) {
85 return Backend::Undefined;
87 AT_ERROR(
"Unrecognized tensor type ID: ", t);
96 return CUDATensorId();
100 return MSNPUTensorId();
102 return XLATensorId();
103 case Backend::SparseCPU:
104 return SparseCPUTensorId();
105 case Backend::SparseCUDA:
106 return SparseCUDATensorId();
107 case Backend::SparseHIP:
108 return SparseHIPTensorId();
109 case Backend::Undefined:
110 return UndefinedTensorId();
112 throw std::runtime_error(
"Unknown backend");
116 static inline DeviceType backendToDeviceType(
Backend b) {
119 return DeviceType::CPU;
121 return DeviceType::CUDA;
123 return DeviceType::HIP;
125 return DeviceType::MSNPU;
127 return DeviceType::XLA;
128 case Backend::SparseCPU:
129 return DeviceType::CPU;
130 case Backend::SparseCUDA:
131 return DeviceType::CUDA;
132 case Backend::SparseHIP:
133 return DeviceType::HIP;
134 case Backend::Undefined:
135 AT_ERROR(
"Undefined backend is not a valid device type");
137 AT_ERROR(
"Unknown backend");
149 case Backend::SparseCPU:
150 return Backend::SparseCPU;
151 case Backend::SparseCUDA:
152 return Backend::SparseCPU;
153 case Backend::SparseHIP:
154 return Backend::SparseCPU;
158 case Backend::Undefined:
159 return Backend::Undefined;
161 AT_ERROR(
"Unknown backend");
172 return Backend::CUDA;
173 case Backend::SparseCPU:
174 case Backend::SparseCUDA:
175 case Backend::SparseHIP:
176 return Backend::SparseCUDA;
177 case Backend::Undefined:
178 return Backend::Undefined;
180 AT_ERROR(
"Unknown backend");
192 case Backend::SparseCPU:
193 case Backend::SparseCUDA:
194 case Backend::SparseHIP:
195 return Backend::SparseHIP;
196 case Backend::Undefined:
197 return Backend::Undefined;
199 AT_ERROR(
"Unknown backend");
203 constexpr DeviceType kCPU = DeviceType::CPU;
204 constexpr DeviceType kCUDA = DeviceType::CUDA;
205 constexpr DeviceType kHIP = DeviceType::HIP;
206 constexpr DeviceType kMSNPU = DeviceType::MSNPU;
207 constexpr DeviceType kXLA = DeviceType::XLA;
209 static inline const char* toString(
Backend b) {
221 case Backend::SparseCPU:
223 case Backend::SparseCUDA:
225 case Backend::SparseHIP:
228 return "UNKNOWN_BACKEND";
Backend
This legacy enum class defines the set of backends supported by old school, code generated Type-based...
Dynamic type ID of a Tensor argument.
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...