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_tile.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 tests.common.tensorio import compare_tensor
  20. from akg.ops.array_gpu.tile import tile
  21. def gen_data(shape, multiples, dtype):
  22. support_list = {"float16": np.float16, "float32": np.float32}
  23. data = random_gaussian(shape, miu=1, sigma=0.1).astype(support_list[dtype])
  24. expect = np.tile(data, multiples)
  25. output = np.full(expect.shape, np.nan, dtype)
  26. return data, output, expect
  27. def test_ms_tile(shape, multiples, dtype, poly_sch=False):
  28. if poly_sch:
  29. mod = utils.op_build_test(tile, [shape], [dtype], op_attrs=[multiples], kernel_name="tile", attrs={"target": "cuda"})
  30. data, output, expect = gen_data(shape, multiples, dtype)
  31. output = utils.mod_launch(mod, (data, output), expect = expect)
  32. ret = compare_tensor(output, expect, rtol=5e-03, atol=1.e-8, equal_nan=True)
  33. print("Test {}".format("Pass" if ret else "Failed"))
  34. if not ret:
  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)