Skip to content

Commit

Permalink
[Vulkan][Target] Change error to warning for "vulkan -from_device=0"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lunderberg committed Aug 3, 2021
1 parent 945c79c commit 60e3b85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
40 changes: 23 additions & 17 deletions src/target/target_kind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ Map<String, ObjectRef> UpdateROCmAttrs(Map<String, ObjectRef> attrs) {
Map<String, ObjectRef> UpdateVulkanAttrs(Map<String, ObjectRef> attrs) {
if (attrs.count("from_device")) {
int device_id = Downcast<Integer>(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
Expand Down Expand Up @@ -251,23 +249,31 @@ Map<String, ObjectRef> UpdateVulkanAttrs(Map<String, ObjectRef> attrs) {
"max_spirv_version"};
std::vector<const char*> str_opts = {"device_name", "device_type"};

for (auto& key : bool_opts) {
if (!attrs.count(key)) {
attrs.Set(key, Bool(static_cast<bool>((*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<bool>((*get_target_property)(device, key))));
}
}
}
for (auto& key : int_opts) {
if (!attrs.count(key)) {
attrs.Set(key, Integer(static_cast<int64_t>((*get_target_property)(device, key))));
for (auto& key : int_opts) {
if (!attrs.count(key)) {
attrs.Set(key, Integer(static_cast<int64_t>((*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.
Expand Down
3 changes: 2 additions & 1 deletion tests/python/topi/python/test_topi_batch_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 60e3b85

Please sign in to comment.