Skip to content

Commit

Permalink
Address issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
zxybazh committed Apr 29, 2022
1 parent 578bce0 commit feb2bfe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion python/tvm/meta_schedule/task_scheduler/task_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from typing import Callable, List, Optional

from tvm._ffi import register_object
from tvm.meta_schedule.utils import make_logging_func
from tvm.runtime import Object

from .. import _ffi_api
Expand All @@ -30,6 +29,7 @@
from ..measure_callback import MeasureCallback
from ..runner import Runner, RunnerResult
from ..tune_context import TuneContext
from ..utils import make_logging_func


logger = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down
9 changes: 5 additions & 4 deletions python/tvm/meta_schedule/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"""User-facing Tuning API"""
# pylint: disable=import-outside-toplevel
import logging
from pathlib import Path
import os.path as osp
import os
from os import path as osp
from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union

from tvm._ffi.registry import register_func
Expand Down Expand Up @@ -502,7 +502,7 @@ def tune_extracted_tasks(
"""
# pylint: disable=protected-access
log_dir = osp.join(work_dir, "logs")
Path(log_dir).mkdir(parents=True, exist_ok=True)
os.makedirs(log_dir, exist_ok=True)
logger_config = config.create_logger_config(
log_dir=log_dir,
propagate=False,
Expand Down Expand Up @@ -545,7 +545,8 @@ def tune_extracted_tasks(
mutator_probs=Parse._mutator_probs(mutator_probs, task.target),
task_name=task.task_name,
logger=Parse._logger(
name="tvm.meta_schedule."
name=__name__
+ "."
+ "_".join(["task", str(i).zfill(max_width), task.task_name]),
**logger_config,
),
Expand Down
5 changes: 3 additions & 2 deletions python/tvm/meta_schedule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,22 @@ def autotvm_silencer():
autotvm.GLOBAL_SCOPE.silent = silent


def make_logging_func(logger: logging.Logger):
def make_logging_func(logger: logging.Logger) -> Optional[Callable]:
"""Get the logging function.
Parameters
----------
logger : logging.Logger
The logger instance.
Returns
-------
result : Callable
result : Optional[Callable]
The function to do the specified level of logging.
"""
if logger is None:
return None

level2log = {
logging.DEBUG: logger.debug,
logging.INFO: logger.info,
logging.WARNING: logger.warning,
logging.ERROR: logger.error,
Expand Down
13 changes: 8 additions & 5 deletions src/meta_schedule/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@
#include "../tir/schedule/primitive.h"
#include "../tir/schedule/utils.h"

#define TVM_PY_LOG(logging_level, logging_func) \
PyLogMessage(__FILE__, __LINE__, logging_func, PyLogMessage::Level::logging_level).stream()
#define TVM_PY_LOG(logging_level, logging_func) \
::tvm::meta_schedule::PyLogMessage(__FILE__, __LINE__, logging_func, \
PyLogMessage::Level::logging_level) \
.stream()

namespace tvm {
namespace meta_schedule {

/*!
* \brief Class to accumulate an log message on the python side. Do not use directly, instead use
* TVM_PY_LOG(INFO), TVM_PY_LOG(WARNING), TVM_PY_ERROR(INFO).
* TVM_PY_LOG(DEBUG), TVM_PY_LOG(INFO), TVM_PY_LOG(WARNING), TVM_PY_ERROR(ERROR).
*/
class PyLogMessage {
public:
enum class Level : int32_t {
DEBUG = 10,
INFO = 20,
WARNING = 30,
ERROR = 40,
Expand Down Expand Up @@ -96,8 +101,6 @@ class PyLogMessage {
Level logging_level;
};

namespace meta_schedule {

/*! \brief The type of the random state */
using TRandState = support::LinearCongruentialEngine::TRandState;

Expand Down

0 comments on commit feb2bfe

Please sign in to comment.