You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

composite_tuner.py 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. # coding: utf-8
  3. # Copyright 2021 Huawei Technologies Co., Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """
  17. auto tuner function
  18. """
  19. from akg.auto_tune.job import launch_json
  20. def tune_composite(json_str, tune_level=0, repo_path="repo.json", skip_exist=False):
  21. """
  22. tune composite
  23. Args:
  24. json_str : str of compute description
  25. tune_level : interger value to specify the tuning level: higher level expects better performance while lower level tunes much faster
  26. repo_path : the path of repo file to save tuning result
  27. skip_exist : whether skip tuning when there is already previous tuning result found in repo file
  28. Returns:
  29. attrs : the best config
  30. """
  31. iter_times = [80, 160, 320] if tune_level == 0 else [15, 15, 15]
  32. debug_mode = False
  33. save_res = True
  34. all_space = False
  35. skip_file = False
  36. extra_tune = False
  37. self_attrs = None
  38. tuning_attrs = ['enable_pre_poly_loop_partition',
  39. 'enable_post_poly_loop_partition']
  40. best_results = launch_json(debug_mode=debug_mode, save_res=save_res, input_str=json_str, repo_path=repo_path, all_space=all_space,
  41. skip_exist=skip_exist, skip_file=skip_file, extra_tune=extra_tune, self_attrs=self_attrs, tuning_attrs=tuning_attrs, iter_times=iter_times)
  42. attrs = {}
  43. if best_results is not None and len(best_results) == 1:
  44. bst = best_results[0]
  45. if bst is not None:
  46. if isinstance(bst, dict):
  47. attrs = bst.get("metadata", {}).get("attrs", {})
  48. elif bst.best_config is not None:
  49. best_config = best_results[0].best_config.input
  50. index_table = best_results[0].index_table
  51. from akg.auto_tune.runner import get_attr_from_config
  52. attrs = get_attr_from_config(best_config, index_table)
  53. return attrs