junrushao1994 commented on code in PR #11622: URL: https://github.com/apache/tvm/pull/11622#discussion_r894020602
########## python/tvm/meta_schedule/default.py: ########## @@ -0,0 +1,327 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=import-outside-toplevel +"""Pre-configured Defaults for MetaSchedule search rules""" +import logging +from os import path as osp +from typing import Callable, Dict, List, Optional, Union + +from tvm._ffi.registry import register_func +from tvm.ir import IRModule +from tvm.target import Target +from tvm.tir import PrimFunc + +from .builder import Builder, LocalBuilder +from .cost_model import CostModel, XGBModel +from .database import Database, JSONDatabase +from .feature_extractor import PerStoreFeature +from .measure_callback import MeasureCallback +from .mutator import Mutator +from .postproc import Postproc +from .runner import LocalRunner, Runner +from .schedule_rule import ScheduleRule +from .space_generator import PostOrderApply, SpaceGenerator + +logger = logging.getLogger(__name__) # pylint: disable=invalid-name + +FnSpaceGenerator = Callable[[], SpaceGenerator] +FnScheduleRule = Callable[[], List[ScheduleRule]] +FnPostproc = Callable[[], List[Postproc]] +FnMutatorProb = Callable[[], Dict[Mutator, float]] + + +class Default: Review Comment: > Currently DefaultLLVM and DefaultCUDA have no inheritance relationship with Default, so I think it might be better to move DefaultLLVM and DefaultCUDA into Default as subclasses, and give them the same names for functions Generally speaking i'm a big fan of subclassing-based approach, but in this particular case, I'm not 100% sure this is the most straightforward approach, and the fundamental reasons here are: 1) `Default` is the only interface that interacts with end users, while `DefaultLLVM` and `DefaultCUDA` are not supposed to be directly used; 2) Here classes with static methods are only used without instantiating objects, i.e. more like namespaces. On the other hand, inheritance helps more in instantiated objects (admittedly though it does hide static methods from parent, but it's a bit less straightforward). Indeed, the three default classes are a bit misleading. Therefore, I would love to propose an alternative: 1) Remove `Default` class and pull all its methods out as global methods, which end users are encouraged to use. For example: ```python from tvm import meta_schedule as ms ms.default_config.schedule_rules() ``` 2) Rename `DefaultLLVM` -> `_DefaultLLVM`, `DefaultCUDA` -> `_DefaultCUDA` to stress both are private implementation. Let me know what you think! -- 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: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org