Skip to content

Commit

Permalink
Add XGBModel & RPCRunnerWarpper (apache#15)
Browse files Browse the repository at this point in the history
* Add XGBModel & RPCRunnerWarpper

* Revert "Add Parallel Granularity Mutation"
  • Loading branch information
jcf94 authored and merrymercy committed Jun 20, 2020
1 parent f60d1a6 commit b839c0f
Show file tree
Hide file tree
Showing 8 changed files with 607 additions and 64 deletions.
3 changes: 2 additions & 1 deletion python/tvm/ansor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .compute_dag import ComputeDAG
from .task import SearchTask, MetaTileRewritePolicy, TuneOption
from .task import auto_schedule
from .measure import MeasureInput, LocalBuilder, LocalRunner, RPCRunner
from .measure import MeasureInput, LocalBuilder, LocalRunner, RPCRunner, RPCRunnerWarpper
from .cost_model import RandomModel
from .cost_model.xgb_model import XGBModel
from .serialization import LogToFile, LogReader, best_measure_pair_in_file
29 changes: 29 additions & 0 deletions python/tvm/ansor/cost_model/cost_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,32 @@ def random_number(n, return_ptr):
return_ptr = ctypes.cast(return_ptr, ctypes.POINTER(ctypes.c_float))
array_wrapper = np.ctypeslib.as_array(return_ptr, shape=(n,))
array_wrapper[:] = np.random.uniform(0, 1, (n,))

@tvm._ffi.register_object("ansor.PythonBasedModel")
class PythonBasedModel(CostModel):
def __init__(self):
def update_func(inputs, results):
self.update(inputs, results)

def predict_func(task, states, return_ptr):
return_ptr = ctypes.cast(return_ptr, ctypes.POINTER(ctypes.c_float))
array_wrapper = np.ctypeslib.as_array(return_ptr, shape=(len(states),))
array_wrapper[:] = self.predict(task, states)

def predict_stage_func(task, states, return_ptr):
ret = self.predict_stages(task, states)
return_ptr = ctypes.cast(return_ptr, ctypes.POINTER(ctypes.c_float))
array_wrapper = np.ctypeslib.as_array(return_ptr, shape=ret.shape)
array_wrapper[:] = ret

self.__init_handle_by_constructor__(_ffi_api.PythonBasedModel, update_func,
predict_func, predict_stage_func)

def update(self, inputs, results):
raise NotImplementedError

def predict(self, task, states):
raise NotImplementedError

def predict_stages(self, task, states):
raise NotImplementedError
Loading

0 comments on commit b839c0f

Please sign in to comment.