From 0ab1190656e4ef800eb68a03bc9ea6345bbfc75a Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Sat, 10 Jul 2021 11:00:14 -0500 Subject: [PATCH] [Vulkan][Target] Change error to warning for "vulkan -from_device=0" Previously, this would give an error if used on a system without vulkan support enabled, or without a vulkan-compatible device. This causes issues in building a `tvm.target.Target` object on a CPU-only device, such as when determining the pytest marks needed for a given target. This is now a warning, defaulting to a minimum vulkan 1.0-compliant target if no device is present. --- src/target/target_kind.cc | 40 +++++++++++-------- .../topi/python/test_topi_batch_matmul.py | 3 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/target/target_kind.cc b/src/target/target_kind.cc index d037b9dfdbdb6..777e016939392 100644 --- a/src/target/target_kind.cc +++ b/src/target/target_kind.cc @@ -217,11 +217,9 @@ Map UpdateROCmAttrs(Map attrs) { Map UpdateVulkanAttrs(Map attrs) { if (attrs.count("from_device")) { int device_id = Downcast(attrs.at("from_device")); + attrs.erase("from_device"); + Device device{kDLVulkan, device_id}; - const PackedFunc* get_target_property = - runtime::Registry::Get("device_api.vulkan.get_target_property"); - ICHECK(get_target_property) - << "Requested to read Vulkan parameters from device, but no Vulkan runtime available"; // Current vulkan implementation is partially a proof-of-concept, // with long-term goal to move the -from_device functionality to @@ -251,23 +249,31 @@ Map UpdateVulkanAttrs(Map attrs) { "max_spirv_version"}; std::vector str_opts = {"device_name"}; - for (auto& key : bool_opts) { - if (!attrs.count(key)) { - attrs.Set(key, Bool(static_cast((*get_target_property)(device, key)))); + const PackedFunc* get_target_property = + runtime::Registry::Get("device_api.vulkan.get_target_property"); + + if (get_target_property) { + for (auto& key : bool_opts) { + if (!attrs.count(key)) { + attrs.Set(key, Bool(static_cast((*get_target_property)(device, key)))); + } } - } - for (auto& key : int_opts) { - if (!attrs.count(key)) { - attrs.Set(key, Integer(static_cast((*get_target_property)(device, key)))); + for (auto& key : int_opts) { + if (!attrs.count(key)) { + attrs.Set(key, Integer(static_cast((*get_target_property)(device, key)))); + } } - } - for (auto& key : str_opts) { - if (!attrs.count(key)) { - attrs.Set(key, (*get_target_property)(device, key)); + for (auto& key : str_opts) { + if (!attrs.count(key)) { + attrs.Set(key, (*get_target_property)(device, key)); + } } - } - attrs.erase("from_device"); + } else { + DLOG(WARNING) + << "Requested to read Vulkan parameters from device, but no Vulkan runtime available. " + << "Defaulting to the minimum provided by the Vulkan 1.0 spec."; + } } // Set defaults here, rather than in the .add_attr_option() calls. diff --git a/tests/python/topi/python/test_topi_batch_matmul.py b/tests/python/topi/python/test_topi_batch_matmul.py index 8c8ad37287dc0..29308ab4d1bc9 100644 --- a/tests/python/topi/python/test_topi_batch_matmul.py +++ b/tests/python/topi/python/test_topi_batch_matmul.py @@ -85,7 +85,8 @@ def check_device(target, dev): tvm.testing.assert_allclose(c.numpy(), c_np, rtol=1e-5) for target, dev in tvm.testing.enabled_targets(): - if dynamic and (target == "cuda" or target == "nvptx"): + target_kind = tvm.target.Target(target).kind.name + if dynamic and target_kind in ["cuda", "nvptx"]: print("Dynamic batch matmul test is skippped on %s" % target) continue