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_debug_info.py 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright 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. # ============================================================================
  15. """ test_parse_numpy """
  16. import os
  17. import shutil
  18. import subprocess
  19. import numpy as np
  20. import mindspore as ms
  21. from mindspore import nn
  22. from mindspore import context
  23. from mindspore import ms_function
  24. from mindspore import Tensor
  25. from tests.security_utils import security_off_wrap
  26. def find_files(file, para):
  27. output = subprocess.check_output(
  28. ["grep '%s' %s | wc -l" % (para, file)],
  29. shell=True)
  30. out = str(output, 'utf-8').strip()
  31. return out
  32. def remove_path(path):
  33. if os.path.exists(path):
  34. shutil.rmtree(path)
  35. @security_off_wrap
  36. def test_ms_function():
  37. @ms_function
  38. def add(x):
  39. return x + 1
  40. context.set_context(mode=context.GRAPH_MODE)
  41. context.set_context(save_graphs=True, save_graphs_path="ir_dump_path")
  42. input1 = np.random.randn(5, 5)
  43. add(Tensor(input1, ms.float32))
  44. result = find_files("./ir_dump_path/*validate*.ir", "test_debug_info.py(45)/ return x + 1/")
  45. assert result == '2'
  46. remove_path("./ir_dump_path/")
  47. @security_off_wrap
  48. def test_cell_ms_function():
  49. class Net(nn.Cell):
  50. @ms_function
  51. def construct(self, x):
  52. return x
  53. context.set_context(mode=context.GRAPH_MODE)
  54. context.set_context(save_graphs=True, save_graphs_path="ir_dump_path")
  55. input1 = np.random.randn(5, 5)
  56. net = Net()
  57. net(Tensor(input1, ms.float32))
  58. result = find_files("./ir_dump_path/*validate*.ir", "test_debug_info.py(62)/ return x/")
  59. assert result == '1'
  60. remove_path("./ir_dump_path/")