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.

test_ms_log.py 1.9 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2020-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. import numpy as np
  15. from tests.common.gen_random import random_gaussian
  16. from akg.utils import kernel_exec as utils
  17. from akg.utils.result_analysis import gpu_profiling
  18. from akg.utils.format_transform import to_tvm_nd_array
  19. from akg.ops.math_gpu.log import log
  20. def gen_data(in_shape, in_dtype):
  21. support_list = {"float16": np.float16, "float32": np.float32}
  22. data = random_gaussian(in_shape, miu=1, sigma=0.1).astype(support_list[in_dtype])
  23. expect = np.log(data)
  24. output = np.full(expect.shape, np.nan, in_dtype)
  25. return data, output, expect
  26. def test_ms_log(in_shape, in_dtype, poly_sch=False):
  27. if poly_sch:
  28. mod = utils.op_build_test(log, (in_shape, ), (in_dtype, ), kernel_name="log", attrs={"target":"cuda"})
  29. data, output, expect = gen_data(in_shape, in_dtype)
  30. args = (data, output)
  31. output = utils.mod_launch(mod, args, expect=expect)
  32. res = np.allclose(output, expect, rtol=5e-03, atol=1.e-7) # from 1e-8 changing to 1e-7
  33. print("Test {}".format("Pass" if res else "Fail"))
  34. if not res:
  35. print("Error cuda:========================")
  36. print(mod.imported_modules[0].get_source())
  37. raise AssertionError("Test fail")
  38. data, expect = to_tvm_nd_array([data, expect])
  39. gpu_profiling(mod, data, expect, 400)

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