[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-04 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551179115



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -624,12 +652,10 @@ def local_build_worker(args):
 The build result of this Builder thread.
 """
 inp, build_func, timeout, verbose = args
-if build_func == "default":
-build_func = tar.tar
-elif build_func == "ndk":
-build_func = ndk.create_shared
-else:
-raise ValueError("Invalid build_func" + build_func)
+assert build_func == BuildFunc.name, (
+"BuildFunc.name: " + BuildFunc.name + ", but args is: " + build_func
+)
+build_func = BuildFunc.build_func

Review comment:
   Ok, then I dont have other better opinions, I'm going to do some test on 
arm cpus these days, maybe I'll encounter similar problem like you.
   
   Is it possible to:
   ```python
   use_ndk = True
   
   @tvm._ffi.register_func("special_wrapper")
   def _wrapper():
   return cc.cross_compiler(ndk.create_shared, options=ndk_options)
   
   build_func = "special_wrapper"
   
   tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
   tune_option = auto_scheduler.TuningOptions(
   num_measure_trials=200, # change this to 2 to achieve the best 
performance
   builder=auto_scheduler.LocalBuilder(build_func=build_func if use_ndk 
else "default"),
   runner=auto_scheduler.RPCRunner(
   device_key, host=tracker_ip, port=tracker_port, repeat=3, timeout=50
   ),
   measure_callbacks=[auto_scheduler.RecordToFile(log_file)],
   )
   ```
   ?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-04 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551179115



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -624,12 +652,10 @@ def local_build_worker(args):
 The build result of this Builder thread.
 """
 inp, build_func, timeout, verbose = args
-if build_func == "default":
-build_func = tar.tar
-elif build_func == "ndk":
-build_func = ndk.create_shared
-else:
-raise ValueError("Invalid build_func" + build_func)
+assert build_func == BuildFunc.name, (
+"BuildFunc.name: " + BuildFunc.name + ", but args is: " + build_func
+)
+build_func = BuildFunc.build_func

Review comment:
   Ok, then I dont have other better opinions, I'm going to do some test on 
arm cpus these days, maybe I'll encounter similar problem like you.
   
   Is it possible to:
   ```python
   use_ndk = True
   
   @tvm._ffi.register_func("special_wrapper")
   def _wrapper():
   return cc.cross_compiler(ndk.create_shared, options=ndk_options)
   
   build_func = "special_wrapper"
   
   tuner = auto_scheduler.TaskScheduler(tasks, task_weights)
   tune_option = auto_scheduler.TuningOptions(
   num_measure_trials=200, # change this to 2 to achieve the best 
performance
   builder=auto_scheduler.LocalBuilder(build_func=build_func if use_ndk 
else "default"),
   runner=auto_scheduler.RPCRunner(
   device_key, host=tracker_ip, port=tracker_port, repeat=3, timeout=50
   ),
   measure_callbacks=[auto_scheduler.RecordToFile(log_file)],
   )
   ```
   





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-04 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551163552



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -624,12 +652,10 @@ def local_build_worker(args):
 The build result of this Builder thread.
 """
 inp, build_func, timeout, verbose = args
-if build_func == "default":
-build_func = tar.tar
-elif build_func == "ndk":
-build_func = ndk.create_shared
-else:
-raise ValueError("Invalid build_func" + build_func)
+assert build_func == BuildFunc.name, (
+"BuildFunc.name: " + BuildFunc.name + ", but args is: " + build_func
+)
+build_func = BuildFunc.build_func

Review comment:
   @FrozenGene @leowang1225 
   I remember that we have used the global variable here at first. But it was 
modified to use serialized args later because of some special reason(which I 
have forgetten)
   So this way may cause some other problem. I'm thinking that just pass the 
registered function name here as a string and this can be serialized easily.
   
   Also cc @merrymercy @comaniac if you can figure out the reason of not using 
global variable here.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-04 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551163552



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -624,12 +652,10 @@ def local_build_worker(args):
 The build result of this Builder thread.
 """
 inp, build_func, timeout, verbose = args
-if build_func == "default":
-build_func = tar.tar
-elif build_func == "ndk":
-build_func = ndk.create_shared
-else:
-raise ValueError("Invalid build_func" + build_func)
+assert build_func == BuildFunc.name, (
+"BuildFunc.name: " + BuildFunc.name + ", but args is: " + build_func
+)
+build_func = BuildFunc.build_func

Review comment:
   @FrozenGene @leowang1225 
   I remember that we have used the global variable at first. But it was 
modified to use serialized args later because of some special reason(which I 
have forgetten)
   So this way may cause some other problem. I'm thinking that just pass the 
registered function name here as a string and this can be serialized easily.
   
   Also cc @merrymercy @comaniac if you can figure out the reason of not using 
global variable here.

##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -303,12 +312,26 @@ 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 = "default"
+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"):
-self.__init_handle_by_constructor__(_ffi_api.LocalBuilder, timeout, 
n_parallel, build_func)
+if build_func == "default":

Review comment:
   @FrozenGene @leowang1225 
   Since we pass the `BuildFunc.name` to the constructor, how about just 
register the custom build function by `@tvm._ffi.register_func` and pass the 
fuction name to it?
   In this way, it can be serialized in args in the `local_build_worker` below.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-03 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551138247



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -624,12 +647,7 @@ def local_build_worker(args):
 The build result of this Builder thread.
 """
 inp, build_func, timeout, verbose = args
-if build_func == "default":
-build_func = tar.tar
-elif build_func == "ndk":
-build_func = ndk.create_shared
-else:
-raise ValueError("Invalid build_func" + build_func)
+build_func = BuildFunc.build_func

Review comment:
   Get `build_func` from the `args`, rather than get from the global 
`BuildFunc`.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [tvm] jcf94 commented on a change in pull request #7185: [AutoScheduler] Add custom build function

2021-01-03 Thread GitBox


jcf94 commented on a change in pull request #7185:
URL: https://github.com/apache/tvm/pull/7185#discussion_r551137236



##
File path: python/tvm/auto_scheduler/measure.py
##
@@ -303,12 +312,26 @@ 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 = "default"
+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"):
-self.__init_handle_by_constructor__(_ffi_api.LocalBuilder, timeout, 
n_parallel, build_func)
+if build_func == "default":

Review comment:
   So this is designed to use the class static member?
   Why not just use a `self.build_func`.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org