junrushao1994 commented on a change in pull request #10368:
URL: https://github.com/apache/tvm/pull/10368#discussion_r817417194
##########
File path: python/tvm/meta_schedule/utils.py
##########
@@ -31,6 +31,107 @@
from tvm.tir import FloatImm, IntImm
+def derived_object(cls: type) -> type:
+ """A decorator to register derived subclasses for TVM objects.
+
+ Parameters
+ ----------
+ cls : type
+ The derived class to be registered.
+
+ Returns
+ -------
+ cls : type
+ The decorated TVM object.
+
+ Example
+ -------
+ .. code-block:: python
+
+ @register_object("meta_schedule.PyRunner")
+ class _PyRunner(meta_schedule.Runner):
+ def __init__(self, methods: List[Callable]):
+ self.__init_handle_by_constructor__(_ffi_api.RunnerPyRunner,
*methods)
+
+ class PyRunner():
+ _tvm_metadata = {
+ "cls": _PyRunner,
+ "methods": ["run"]
+ }
+ def run(self, runner_inputs):
+ raise NotImplementedError
+
+ @derived_object
+ class LocalRunner(PyRunner):
+ def run(self, runner_inputs):
+ ...
+ """
+
+ import functools # pylint: disable=import-outside-toplevel
+ import weakref # pylint: disable=import-outside-toplevel
+
+ def _extract(inst: type, name: str):
+ """Extract function from intrinsic class."""
+
+ def method(*args, **kwargs):
+ return getattr(inst, name)(*args, **kwargs)
+
+ if getattr(base, name) is getattr(cls, name) and name != "__str__":
+ # for task scheduler return None means calling default function
+ # otherwise it will trigger a TVMError of method not implemented
+ # on the c++ side when you call the method, __str__ not required
+ return None
Review comment:
Why `__str__` is the special case btw?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]