Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoScheduler] Add custom build function #7185

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions python/tvm/auto_scheduler/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
# We use 1e10 instead of sys.float_info.max for better readability in log
MAX_FLOAT = 1e10

class CustomBuildFunc:
FrozenGene marked this conversation as resolved.
Show resolved Hide resolved
""" store custom build_func to class variable. """
build_func = None

@tvm._ffi.register_object("auto_scheduler.MeasureCallback")
class MeasureCallback(Object):
Expand Down Expand Up @@ -303,11 +306,16 @@ class LocalBuilder(ProgramBuilder):
This is used in a wrapper of the multiprocessing.Process.join().
n_parallel : int = multiprocessing.cpu_count()
Number of threads used to build in parallel.
build_func : str = 'default'
The name of registered build function.
build_func: callable or str
FrozenGene marked this conversation as resolved.
Show resolved Hide resolved
If is 'default', use default build function
If is 'ndk', use function for android ndk
If is callable, use it as custom build function, expect lib_format field.
"""

def __init__(self, timeout=15, n_parallel=multiprocessing.cpu_count(), build_func="default"):
if not isinstance(build_func, str):
CustomBuildFunc.build_func = build_func
build_func = "custom"
self.__init_handle_by_constructor__(_ffi_api.LocalBuilder, timeout, n_parallel, build_func)


Expand Down Expand Up @@ -628,6 +636,8 @@ def local_build_worker(args):
build_func = tar.tar
elif build_func == "ndk":
build_func = ndk.create_shared
elif build_func == "custom":
FrozenGene marked this conversation as resolved.
Show resolved Hide resolved
build_func = CustomBuildFunc.build_func
else:
raise ValueError("Invalid build_func" + build_func)
FrozenGene marked this conversation as resolved.
Show resolved Hide resolved

Expand Down