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.

parallel_estimate.py 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """estimate parallel case"""
  16. import json
  17. import json.decoder as jd
  18. import traceback
  19. from mindspore import log as logger
  20. from . import model
  21. def estimate_ops(json_str: str):
  22. """Call costmodel to estimate ops."""
  23. try:
  24. json_obj = json.loads(json_str)
  25. graph_descs = json_obj["graph_desc"]
  26. graphs = []
  27. for gd in graph_descs:
  28. graphs.append(model.load_composite(gd).graph)
  29. estimation = model.parallel_estimate(graphs)
  30. res = (estimation.block_assign, estimation.gain,
  31. estimation.fusion_type, estimation.type_info)
  32. return res
  33. except jd.JSONDecodeError:
  34. logger.error(traceback.format_exc())
  35. return None
  36. def estimate_calulation_amount(json_str: str):
  37. """Call costmodel to estimate calculation amount of op."""
  38. try:
  39. graph_desc = json.loads(json_str)
  40. comp = model.load_composite(graph_desc)
  41. estimation = model.parallel_estimate([comp.graph])
  42. return estimation.bottleneck
  43. except jd.JSONDecodeError:
  44. logger.error(traceback.format_exc())
  45. return None