26 #ifndef TVM_TARGET_VIRTUAL_DEVICE_H_ 27 #define TVM_TARGET_VIRTUAL_DEVICE_H_ 33 #include <unordered_set> 192 DLDeviceType
device_type()
const {
return static_cast<DLDeviceType
>(device_type_int); }
223 return !target.
defined() &&
device_type() == kInvalidDeviceType && virtual_device_id == -1 &&
224 memory_scope.
empty();
232 return target.
defined() && virtual_device_id != -1 && !memory_scope.
empty();
242 ICHECK(device_type_int != kInvalidDeviceType);
243 ICHECK(virtual_device_id != -1);
252 .describe(
"The type of the virtual device.")
253 .set_default(kInvalidDeviceType);
255 .describe(
"The device id of the virtual device.")
258 .describe(
"The target describing how to compile for the virtual device.")
261 .describe(
"The area of memory w.r.t. the virtual device where data is stored.")
295 ICHECK_GT(device_type, 0);
307 return ForDeviceType(device.device_type, device.device_id);
312 return VirtualDevice(device.device_type, device.device_id, std::move(target));
317 DLDeviceType
device_type =
static_cast<DLDeviceType
>(target->GetTargetDeviceType());
323 return VirtualDevice(kInvalidDeviceType, -1, {}, std::move(memory_scope));
329 return VirtualDevice(device.device_type, device.device_id, std::move(target),
330 std::move(memory_scope));
372 std::unordered_set<VirtualDevice, StructuralHash, StructuralEqual> cache_;
384 #endif // TVM_TARGET_VIRTUAL_DEVICE_H_ constexpr int kInvalidDeviceType
Definition: virtual_device.h:55
static VirtualDevice ForDeviceType(DLDeviceType device_type, int virtual_device_id=-1)
Returns the VirtualDevice for device_type and (if not -1) virtual_device_id. The target and memory sc...
Definition: virtual_device.h:294
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
static VirtualDevice ForMemoryScope(MemoryScope memory_scope)
Returns the VirtualDevice for memory_scope alone.
Definition: virtual_device.h:322
friend class VirtualDevice
Definition: virtual_device.h:265
constexpr int kNullDeviceType
Definition: virtual_device.h:52
A cache of VirtualDevices. This can be used:
Definition: virtual_device.h:359
int virtual_device_id
The device identifier for the virtual device. This must be resolved to a physical device identifier e...
Definition: virtual_device.h:200
TVM_DECLARE_ATTRS(VirtualDeviceNode, "VirtualDevice")
Definition: virtual_device.h:250
static VirtualDevice ForDeviceTargetAndMemoryScope(const Device &device, Target target, MemoryScope memory_scope)
Returns the VirtualDevice for device, target and memory_scope.
Definition: virtual_device.h:327
Managed reference class to VirtualDeviceNode.
Definition: virtual_device.h:271
bool defined() const
Definition: object.h:544
bool IsFullyConstrained() const
Returns true if virtual device is 'fully constrained', ie target, device id and memory scope are all ...
Definition: virtual_device.h:231
static VirtualDevice ForDeviceType(const Integer &device_type, int virtual_device_id=-1)
Definition: virtual_device.h:301
MemoryScope memory_scope
The scope of memory w.r.t. the virtual device which holds data.
Definition: virtual_device.h:216
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
Reference to string objects.
Definition: string.h:98
DLDevice Device
Definition: ndarray.h:43
Describes at compile time the constraints on where data is to be stored at runtime down to the (virtu...
Definition: virtual_device.h:176
Managed reference class to TargetNode.
Definition: target.h:183
static VirtualDevice ForDeviceType(int device_type, int virtual_device_id=-1)
Definition: virtual_device.h:298
Base class of all object reference.
Definition: object.h:511
static VirtualDevice ForDevice(const Device &device)
Returns the VirtualDevice for device.
Definition: virtual_device.h:306
Target target
The Target describing how to compile for the virtual device.
Definition: virtual_device.h:209
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:834
constexpr const char * kVirtualDevice
Definition: virtual_device.h:380
Compilation target object.
DLDeviceType device_type() const
Definition: virtual_device.h:192
static VirtualDevice ForTarget(Target target)
Returns the VirtualDevice for target.
Definition: virtual_device.h:316
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
bool empty() const
Retun if the string is empty.
Definition: string.h:208
static VirtualDevice ForDeviceAndTarget(const Device &device, Target target)
Returns the VirtualDevice for device and target.
Definition: virtual_device.h:311
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
bool IsFullyUnconstrained() const
Returns true if virtual device is 'fully unconstrained', ie no target/device type, device id or memory scope is specified.
Definition: virtual_device.h:222
Container of constant int that adds more constructors.
Definition: expr.h:622
Device ToDevice() const
Returns the (virtual) Device implied by this VirtualDevice. Both the device_type and virtual_device_m...
Definition: virtual_device.h:241