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_abs.py 1.8 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.abs import abs_data
  20. def gen_data(shape, dtype):
  21. support_list = {"float16": np.float16, "float32": np.float32}
  22. data = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype])
  23. expect = np.abs(data)
  24. output = np.full(expect.shape, np.nan, dtype)
  25. return data, output, expect
  26. def test_ms_abs(shape, dtype, poly_sch=False):
  27. if poly_sch:
  28. mod = utils.op_build_test(abs_data, [shape], [dtype], attrs={"target": "cuda"}, kernel_name="abs")
  29. data, output, expect = gen_data(shape, dtype)
  30. output = utils.mod_launch(mod, (data, output), expect = expect)
  31. res = np.allclose(output, expect, rtol=5e-03, atol=1.e-8)
  32. print("Test {}".format("Pass" if res else "Fail"))
  33. if not res:
  34. print("Error cuda:========================")
  35. print(mod.imported_modules[0].get_source())
  36. raise AssertionError("Test fail")
  37. data, expect = to_tvm_nd_array([data, expect])
  38. gpu_profiling(mod, data, expect, 400)