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.

addn.py 1.3 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright 2020 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. """operator dsl function: addn"""
  15. import akg.topi
  16. from akg.utils import validation_check as vc_util
  17. @vc_util.check_input_type(((list, tuple), akg.tvm.tensor.Tensor))
  18. def addn(data):
  19. """
  20. Compute sum of all elements in tensor.
  21. Args:
  22. data (tvm.tensor.Tensor): Tensor of of type float16, float32.
  23. Returns:
  24. tvm.tensor.Tensor, compute result, get all elements' sum.
  25. """
  26. # check types
  27. dtype = data[0].dtype
  28. vc_util.ops_dtype_check(dtype, vc_util.DtypeForDavinci.ALL_FLOAT)
  29. res = data[0]
  30. for i in range(1, len(data)):
  31. vc_util.elemwise_dtype_check(res.dtype, data[i].dtype)
  32. vc_util.elemwise_shape_check(res.shape, data[i].shape)
  33. res = akg.topi.elemwise_sum(data)
  34. return res

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