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.

realdiv.py 2.0 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. # coding: utf-8
  3. # Copyright 2019 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. """operator dsl function:realdiv"""
  17. import akg.topi
  18. from akg.utils import validation_check as vc_util
  19. from akg.utils.dsl_create import produce_shapes
  20. @vc_util.check_input_type(akg.tvm.tensor.Tensor, akg.tvm.tensor.Tensor)
  21. def realdiv(input1, input2):
  22. """
  23. Returns input1 / input2 element-wise for real types.
  24. Note:
  25. Realdiv supports broadcasting.
  26. Args:
  27. input1 (tvm.tensor.Tensor): Tensor of type float16, float32.
  28. input2 (tvm.tensor.Tensor): Tensor of type float16, float32.
  29. Returns:
  30. tvm.tensor.Tensor, has the same type of input1 and shaped by broadcasting.
  31. """
  32. vc_util.ops_dtype_check([input1.dtype, input2.dtype], vc_util.DtypeForDavinci.ALL_FLOAT)
  33. vc_util.elemwise_dtype_check(input1.dtype, input2.dtype)
  34. shape1 = [x.value for x in input1.shape]
  35. shape2 = [x.value for x in input2.shape]
  36. vc_util.check_shape(shape1)
  37. vc_util.check_shape(shape2)
  38. vc_util.auto_broadcast_check(shape1, shape2)
  39. n_shape1, n_shape2, out_shape = produce_shapes(shape1, shape2)
  40. if n_shape1 != out_shape:
  41. input1_cast = akg.topi.broadcast_to(input1, out_shape)
  42. else:
  43. input1_cast = input1
  44. if n_shape2 != out_shape:
  45. input2_cast = akg.topi.broadcast_to(input2, out_shape)
  46. else:
  47. input2_cast = input2
  48. res = akg.topi.divide(input1_cast, input2_cast)
  49. return res

AKG(Auto Kernel Generator)对深度神经网络中的算子进行优化,并提供特定模式下的算子自动融合功能。AKG与MindSpore的图算融合功能协同工作,可提升在不同硬件后端上运行网络的性能。