From faee545c8011abf018470d051178233fd9e62dae Mon Sep 17 00:00:00 2001 From: Zhi Chen Date: Thu, 2 Apr 2020 00:09:28 +0000 Subject: [PATCH 1/2] expose runtime::String to Python --- include/tvm/runtime/container.h | 6 +++--- python/tvm/runtime/container.py | 18 ++++++++++++++++++ src/runtime/container.cc | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/tvm/runtime/container.h b/include/tvm/runtime/container.h index 4164451e24b1..50b406b2c030 100644 --- a/include/tvm/runtime/container.h +++ b/include/tvm/runtime/container.h @@ -512,12 +512,12 @@ class String : public ObjectRef { #endif } - TVM_DEFINE_OBJECT_REF_METHODS(String, ObjectRef, StringObj); - - private: /*! \return the internal StringObj pointer */ const StringObj* get() const { return operator->(); } + TVM_DEFINE_OBJECT_REF_METHODS(String, ObjectRef, StringObj); + + private: /*! * \brief Compare two char sequence * diff --git a/python/tvm/runtime/container.py b/python/tvm/runtime/container.py index 02a082affc77..dd59011b1eca 100644 --- a/python/tvm/runtime/container.py +++ b/python/tvm/runtime/container.py @@ -109,4 +109,22 @@ def tuple_object(fields=None): return _Tuple(*fields) +@tvm._ffi.register_object("runtime.String") +class String(Object): + """The string object. + + Parameters + ---------- + string : Str + The string used to construct a runtime String object + + Returns + ------- + ret : String + The created object. + """ + def __init__(self, string): + self.__init_handle_by_constructor__(_String, string) + + tvm._ffi._init_api("tvm.runtime.container") diff --git a/src/runtime/container.cc b/src/runtime/container.cc index f54ae6cf9c23..400f6469615f 100644 --- a/src/runtime/container.cc +++ b/src/runtime/container.cc @@ -76,7 +76,13 @@ TVM_REGISTER_GLOBAL("runtime.container._ADT") *rv = ADT(tag, fields); }); +TVM_REGISTER_GLOBAL("runtime.container._String") +.set_body_typed([](std::string str) { + return String(std::move(str)); +}); + TVM_REGISTER_OBJECT_TYPE(ADTObj); +TVM_REGISTER_OBJECT_TYPE(StringObj); TVM_REGISTER_OBJECT_TYPE(ClosureObj); } // namespace runtime From db98e357d6e9d7c39e58e1d45071e3fa87932b5a Mon Sep 17 00:00:00 2001 From: Zhi Chen Date: Thu, 2 Apr 2020 04:57:16 +0000 Subject: [PATCH 2/2] retrigger ci