Skip to content

Commit

Permalink
Add Python API: Measure & Task (apache#7)
Browse files Browse the repository at this point in the history
* Update the return value of state operation

* Add task

* Copy measure.py & utils.py

* Fix LocalBuilder

* Fix LocalRunner
  • Loading branch information
jcf94 authored and merrymercy committed Jun 20, 2020
1 parent 359905a commit 2032a64
Show file tree
Hide file tree
Showing 14 changed files with 1,401 additions and 429 deletions.
2 changes: 2 additions & 0 deletions python/tvm/ansor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
"""Namespace for Ansor autoSchedule"""

from .compute_dag import ComputeDAG
from .task import SearchTask
from .measure import MeasureInput, LocalBuilder, LocalRunner
50 changes: 48 additions & 2 deletions python/tvm/ansor/compute_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,56 @@
from . import _ffi_api


class LayoutRewriteLevel(object):
NO_REWRITE = 0 # No layout rewrite
PLACEHOLDER_REWRITE = 1 # Only rewrite layout of placeholder in the compute dag
COMPUTE_REWRITE = 2 # Only rewrite compute body for new layout in the compute dag
BOTH_REWRITE = 3 # Rewrite both placeholder and compute body in the compute dag


@tvm._ffi.register_object("ansor.ComputeDAG")
class ComputeDAG(Object):
"""
Parameters
----------
tensors : List[Tensor]
"""

def __init__(self, tensors):
self.__init_handle_by_constructor__(_ffi_api.ComputeDAG, tensors)

def get_init_state(self) -> State:
return self.init_state
def get_init_state(self):
""" Get init state of this ComputeDAG
Returns
-------
state : State
"""
return _ffi_api.ComputeDAGGetInitState(self)

def apply_steps_from_state(self, state, layout_rewrite_level):
"""
Parameters
----------
state : State
layout_rewrite_level : LayoutRewriteLevel(***)
Returns
-------
sch : Schedule
args : List[Tensor]
"""
sch, args = _ffi_api.ComputeDAGApplyStepsFromState(self, state)
return sch, args

def print_python_code_from_state(self, state):
"""
Parameters
----------
state : State
Returns
-------
str : Str
"""
return _ffi_api.ComputeDAGPrintPythonCodeFromState(self, state)
Loading

0 comments on commit 2032a64

Please sign in to comment.