mbs-octoml commented on code in PR #12107:
URL: https://github.com/apache/tvm/pull/12107#discussion_r922413056
##########
src/target/compilation_config.cc:
##########
@@ -98,19 +98,30 @@ Target CompilationConfigNode::CanonicalTarget(const Target&
target) const {
VirtualDevice CompilationConfigNode::CanonicalVirtualDevice(
const VirtualDevice& virtual_device) const {
- DLDeviceType device_type = virtual_device->device_type();
+ // Targets need special handling.
Target target = virtual_device->target;
if (target.defined()) {
- target = CanonicalTarget(target);
- } else {
- // Find the (unique) target matching the device's device type.
- // TODO(mbs): Proper diagnostics.
- CHECK(device_type != kInvalidDeviceType)
- << "VirtualDevice annotations must include at least a device_type";
- target = FindPrimitiveTargetForDeviceOrFail(device_type);
+ // It is possible the given target object was constructed by the user, but
was then
+ // rewritten on the way into the CompilationConfig. So 'canonicalize' it
by replacing
+ // the given target with one structurally equal to one already known in
the config if
+ // possible.
+ Target canon_target = CanonicalTarget(target);
+ if (canon_target != target) {
+ VLOG(1) << "Canonicalized target " << canon_target->ToDebugString();
+ }
+ target = canon_target;
+ } else if (virtual_device->device_type() != kInvalidDeviceType) {
+ // Since no target was given, choose one with a matching device type.
+ // This is the one place where we allow device types to imply targets.
+ target = FindPrimitiveTargetForDeviceOrFail(virtual_device->device_type());
+ VLOG(1) << "Defaulted to target " << target->ToDebugString();
}
- return virtual_device_cache_.Unique(VirtualDevice(device_type,
virtual_device->virtual_device_id,
- target,
virtual_device->memory_scope));
+ // else: the target will remain unknown.
Review Comment:
Good point -- it is now possible to ask for CanonicalVirtualDevice of a
'fully unconstrained' virtual device (ie one with no fields define at all),
which should be object equal to VirtualDevice::FullyUnconstrained(). Fixed
that, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]