Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Target] Refine equality check on TargetKind instances #17321

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/target/target_kind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@

namespace tvm {

TVM_REGISTER_NODE_TYPE(TargetKindNode);
// helper to get internal dev function in objectref.
struct TargetKind2ObjectPtr : public ObjectRef {
static ObjectPtr<Object> Get(const TargetKind& kind) { return GetDataPtr<Object>(kind); }
};

TVM_REGISTER_NODE_TYPE(TargetKindNode)
.set_creator([](const std::string& name) {
auto kind = TargetKind::Get(name);
ICHECK(kind.defined()) << "Cannot find target kind \'" << name << '\'';
return TargetKind2ObjectPtr::Get(kind.value());
})
.set_repr_bytes([](const Object* n) -> std::string {
return static_cast<const TargetKindNode*>(n)->name;
});

TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
.set_dispatch<TargetKindNode>([](const ObjectRef& obj, ReprPrinter* p) {
Expand Down
16 changes: 16 additions & 0 deletions tests/python/target/test_target_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,5 +559,21 @@ def test_target_from_device_opencl(input_device):
assert target.thread_warp_size == dev.warp_size


def test_module_dict_from_deserialized_targets():
target = Target("llvm")

from tvm.script import tir as T

@T.prim_func
def func():
T.evaluate(0)

func = func.with_attr("Target", target)
target2 = tvm.ir.load_json(tvm.ir.save_json(target))
mod = tvm.IRModule({"main": func})
lib = tvm.build({target2: mod}, target_host=target)
lib["func"]()


if __name__ == "__main__":
tvm.testing.main()
Loading