Skip to content

Commit 2270851

Browse files
committed
[checkpoint] woops, left target str debug in
Added Target::ToDebugString() so I can see the hosts since they were giving me a lot of trouble.
1 parent 043aaea commit 2270851

File tree

9 files changed

+74
-44
lines changed

9 files changed

+74
-44
lines changed

include/tvm/target/target.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ class TargetNode : public Object {
6666
/*! \return The Optional<Target> typed target host of the TargetNode */
6767
TVM_DLL Optional<Target> GetHost() const;
6868

69+
/*!
70+
* \brief Returns a human readable representation of \p Target which includes all fields,
71+
* especially the host. Useful for diagnostic messages and debugging.
72+
*
73+
* TODO(mbs): The ReprPrinter version should perhaps switch to this form, however currently
74+
* code depends on str() and << being the same.
75+
*/
76+
String ToDebugString() const;
77+
6978
void VisitAttrs(AttrVisitor* v) {
7079
v->Visit("kind", &kind);
7180
v->Visit("tag", &tag);

src/relay/backend/graph_executor_codegen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class GraphExecutorCodegen : public backend::MemoizedExprTranslator<std::vector<
203203
VLOG_CONTEXT << "GraphExecutorCodegen";
204204
VLOG(1) << "compiling:" << std::endl << PrettyPrint(func);
205205
for (const auto& pair : targets_) {
206-
VLOG(1) << "target: " << pair.first << " = " << pair.second->str();
206+
VLOG(1) << "target: " << pair.first << " = " << pair.second->ToDebugString();
207207
}
208208

209209
// This first phase moves from implicit use of compile engine,

src/relay/backend/interpreter.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,12 @@ class Interpreter : public ExprFunctor<ObjectRef(const Expr& n)>,
389389
per_target_module_std_map = backend::TargetModuleMapToTargetStrModuleMap(per_target_module);
390390
auto mod_itr = per_target_module_std_map.find(target);
391391
ICHECK(mod_itr != per_target_module_std_map.end())
392-
<< "No target module for target '" << target->str() << "'";
392+
<< "No target module for target " << target->ToDebugString();
393393
const IRModule& target_module = (*mod_itr).second;
394394
for (const auto& var : all_tir_fn_vars) {
395395
ICHECK(target_module->ContainGlobalVar(var->name_hint))
396-
<< "No global var for '" << var->name_hint << "' in module for target '" << target->str()
397-
<< "'";
396+
<< "No global var for '" << var->name_hint << "' in module for target "
397+
<< target->ToDebugString();
398398
lowered_projected_mod->Add(var, target_module->Lookup(var->name_hint));
399399
}
400400

@@ -410,8 +410,9 @@ class Interpreter : public ExprFunctor<ObjectRef(const Expr& n)>,
410410
// Extract all the packed functions.
411411
for (const auto& var : all_tir_fn_vars) {
412412
PackedFunc packed_func = runtime_module.GetFunction(var->name_hint);
413-
ICHECK(packed_func != nullptr) << "No packed function for global var '" << var->name_hint
414-
<< "' in compiled module for target '" << target->str() << "'";
413+
ICHECK(packed_func != nullptr)
414+
<< "No packed function for global var '" << var->name_hint
415+
<< "' in compiled module for target " << target->ToDebugString();
415416
compiled_packed_funcs_.emplace(std::make_pair(target, var->name_hint), packed_func);
416417
}
417418

src/relay/backend/te_compiler.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ class LowerTensorExprMutator : public DeviceAwareExprMutator {
464464
}
465465

466466
// Non-External Relay Function
467-
VLOG(1) << "lowering to target '" << target->str() << "' for primitive:\n" << PrettyPrint(func);
467+
VLOG(1) << "lowering to target " << target->ToDebugString() << " for primitive:" << std::endl
468+
<< PrettyPrint(func);
468469
CCacheKey key = CCacheKey(func, target);
469470
CachedFunc lowered_func = compiler_->Lower(key, module_name_);
470471
VLOG(1) << "lowered primitive bound to '" << PrettyPrint(lowered_func->prim_fn_var) << "'";
@@ -512,8 +513,8 @@ class LowerTensorExprMutator : public DeviceAwareExprMutator {
512513
// on the host cpu irrespective of where the primitive runs.
513514
// TODO(mbs): Cleanup target handling.
514515
Target shape_target("llvm");
515-
VLOG(1) << "lowering to target '" << shape_target->str()
516-
<< "' for dynamic shape function for primitive";
516+
VLOG(1) << "lowering to target " << shape_target->ToDebugString()
517+
<< " for dynamic shape function for primitive";
517518
CCacheKey shape_key(func, shape_target);
518519
CachedFunc lowered_shape_func = compiler_->LowerShapeFunc(shape_key);
519520
// Capture the shape function's global var and parameters 'states' in call

src/target/compilation_config.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,40 @@ void CompilationConfigNode::EstablishDefaultSEScopes(const transform::PassContex
6161
if (host_target.defined()) {
6262
CHECK(!host_target->host.defined()) << "Host targets are not expected to have hosts";
6363
host_device_type = static_cast<DLDeviceType>(host_target->kind->device_type);
64-
LOG(INFO) << "Using the given host target '" << host_target << "' of device type "
65-
<< host_device_type << " for the host target";
64+
LOG(INFO) << "Using the given host target " << host_target->ToDebugString()
65+
<< " of device type " << host_device_type << " for the host target";
6666
for (const auto& primitive_target : primitive_targets) {
6767
if (primitive_target->host.defined() &&
6868
!StructuralEqual()(primitive_target->host, host_target)) {
69-
LOG(WARNING) << "The primitive target '" << primitive_target
70-
<< "' already has a host which disagrees with the desired host target. It "
69+
LOG(WARNING) << "The primitive target " << primitive_target->ToDebugString()
70+
<< " already has a host which disagrees with the desired host target. It "
7171
"will be ignored.";
7272
}
7373
}
7474
} else if (primitive_targets.size() == 1 && primitive_targets.front()->host.defined()) {
7575
host_target = primitive_targets.front()->GetHost().value();
7676
CHECK(!host_target->host.defined()) << "Host targets are not expected to have hosts";
7777
host_device_type = static_cast<DLDeviceType>(host_target->kind->device_type);
78-
LOG(INFO) << "Using the host of the unique primitive target, namely '" << host_target
79-
<< "' of device type " << host_device_type << " for the host target";
78+
LOG(INFO) << "Using the host of the unique primitive target, namely "
79+
<< host_target->ToDebugString() << " of device type " << host_device_type
80+
<< " for the host target";
8081
} else if (primitive_targets.size() == 1 &&
8182
primitive_targets.front()->kind->device_type == kDLCPU) {
8283
// In the homogenous case without an explicit host target just use the given target so long as
8384
// it's a CPU.
8485
host_device_type = kDLCPU;
8586
host_target = primitive_targets.front();
86-
LOG(INFO) << "Using the unique primitive target '" << host_target << "' of device type "
87-
<< host_device_type << " for the host target";
87+
LOG(INFO) << "Using the unique primitive target " << host_target->ToDebugString()
88+
<< " of device type " << host_device_type << " for the host target";
8889
} else {
8990
// Fallback.
9091
host_device_type = kDLCPU;
9192
// Even if the list of available targets already includes one for kDLCPU we won't use it
9293
// in the hetrogeneous case since its options may not be appropriate for host code
9394
// (eg shape functions). Instead, create a fresh default Target.
9495
host_target = MakeDefaultTarget(host_device_type);
95-
LOG(WARNING) << "Using the default target '" << host_target << "' of device type "
96-
<< host_device_type << " for the host target";
96+
LOG(WARNING) << "Using the default target " << host_target->ToDebugString()
97+
<< " of device type " << host_device_type << " for the host target";
9798
}
9899
ICHECK(host_target.defined());
99100
ICHECK(!host_target->host.defined());
@@ -189,10 +190,10 @@ CompilationConfig::CompilationConfig(const transform::PassContext& pass_ctx,
189190
auto node = make_object<CompilationConfigNode>();
190191

191192
for (const auto& pair : legacy_target_map_arg) {
192-
VLOG(0) << "Available primitive target " << pair.first << " = '" << pair.second << "'";
193+
VLOG(0) << "Available primitive target " << pair.first << " = " << pair.second->ToDebugString();
193194
}
194195
if (optional_host_target_arg.defined()) {
195-
VLOG(0) << "Available host target '" << optional_host_target_arg << "'";
196+
VLOG(0) << "Available host target " << optional_host_target_arg->ToDebugString();
196197
}
197198

198199
// Capture the arguments in our representation.
@@ -221,8 +222,8 @@ CompilationConfig::CompilationConfig(const transform::PassContext& pass_ctx,
221222
node->primitive_targets.size() == 1 ? *node->primitive_targets.begin() : Target();
222223

223224
for (const auto& target : node->primitive_targets) {
224-
LOG(INFO) << "Target '" << target << "' of device type " << target->kind->device_type
225-
<< " is available for primitives";
225+
LOG(INFO) << "Target " << target->ToDebugString() << " of device type "
226+
<< target->kind->device_type << " is available for primitives";
226227
}
227228
LOG(INFO) << "Using default primitive scope " << node->default_primitive_se_scope;
228229
LOG(INFO) << "Using host scope " << node->host_se_scope;

src/target/se_scope.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
5252
if (need_sep) {
5353
p->stream << ", ";
5454
}
55-
p->stream << "target='" << node->target << "'";
55+
p->stream << "target=" << node->target->ToDebugString();
5656
need_sep = true;
5757
}
5858
if (!node->memory_scope.empty()) {
@@ -72,7 +72,7 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
7272
SEScope::SEScope(DLDeviceType device_type, int virtual_device_id, Target target,
7373
MemoryScope memory_scope) {
7474
ICHECK(!target.defined() || device_type == target->kind->device_type)
75-
<< "target '" << target << "' has device type " << target->kind->device_type
75+
<< "target " << target->ToDebugString() << " has device type " << target->kind->device_type
7676
<< " but scope has device type " << device_type;
7777
auto node = make_object<SEScopeNode>();
7878
node->device_type_int = device_type;
@@ -177,7 +177,7 @@ SEScope SEScopeCache::Make(DLDeviceType device_type, int virtual_device_id, Targ
177177
cache_.emplace(prototype);
178178
return prototype;
179179
} else {
180-
VLOG(1) << "reusing '" << *itr << "' for '" << prototype << "'";
180+
VLOG(1) << "reusing existing scope " << *itr;
181181
ICHECK_EQ(prototype->target.defined(), (*itr)->target.defined());
182182
if (prototype->target.defined()) {
183183
ICHECK_EQ(prototype->target->host.defined(), (*itr)->target->host.defined());

src/target/target.cc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ const std::string& TargetNode::str() const {
457457
if (Optional<String> attrs_str = TargetInternal::StringifyAttrsToRaw(attrs)) {
458458
os << ' ' << attrs_str.value();
459459
}
460-
if (host.defined()) {
461-
os << " host='" << host << "'";
462-
}
463460

464461
str_repr_ = os.str();
465462
}
@@ -535,6 +532,34 @@ Optional<Target> TargetNode::GetHost() const {
535532
return GetRef<Optional<Target>>(this->host.as<TargetNode>());
536533
}
537534

535+
String TargetNode::ToDebugString() const {
536+
std::ostringstream os;
537+
os << "Target(tag='" << tag << "'";
538+
os << ", kind='" << kind->name << "'";
539+
if (!tag.empty()) {
540+
os << ", tag='" << tag << "'";
541+
}
542+
if (!keys.empty()) {
543+
os << ", keys={";
544+
for (const auto& key : keys) {
545+
os << "'" << key << "',";
546+
}
547+
os << "}";
548+
}
549+
if (!attrs.empty()) {
550+
os << ", attrs={";
551+
for (const auto& pair : attrs) {
552+
os << '"' << pair.first << "': " << pair.second << ",";
553+
}
554+
os << "}";
555+
}
556+
if (host.defined()) {
557+
os << ", host=" << host.value();
558+
}
559+
os << ")";
560+
return os.str();
561+
}
562+
538563
bool TargetNode::SEqualReduce(const TargetNode* other, SEqualReducer equal) const {
539564
return equal(kind.get(), other->kind.get()) && equal(host, other->host) &&
540565
equal(tag, other->tag) && equal(keys, other->keys) && equal(attrs, other->attrs);

tests/python/unittest/test_auto_scheduler_measure.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,7 @@ def foo():
424424

425425

426426
if __name__ == "__main__":
427-
test_record_split_reorder_fuse_annotation()
428-
test_record_compute_at_root_inline_cache_read_write()
429-
test_record_follow_split_follow_fused_split()
430-
test_record_pragma_storage_align_rfactor()
431-
test_recover_measure_input()
432-
test_workload_dis_factor()
433-
test_measure_local_builder_runner()
434-
test_dag_measure_local_builder_runner()
435-
test_workload_serialization()
436-
test_measure_local_builder_rpc_runner()
437-
test_measure_target_host()
438-
test_measure_special_inputs_map_by_name_local_runner()
439-
test_measure_special_inputs_map_by_name_rpc_runner()
427+
import sys
428+
import pytest
429+
430+
sys.exit(pytest.main([__file__] + sys.argv[1:]))

tests/python/unittest/test_micro_model_library_format.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import datetime
1919
import json
2020
import os
21-
import sys
2221
import tarfile
2322

2423
import numpy
@@ -411,4 +410,7 @@ def test_export_byoc_c_module():
411410

412411

413412
if __name__ == "__main__":
414-
sys.exit(pytest.main([__file__] + sys.argv[1:]))
413+
import sys
414+
415+
# sys.exit(pytest.main([__file__] + sys.argv[1:]))
416+
test_export_operator_model_library_format()

0 commit comments

Comments
 (0)