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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. import os
  16. import shutil
  17. import glob
  18. import numpy as np
  19. import pytest
  20. import mindspore.context as context
  21. import mindspore.nn as nn
  22. from mindspore import Tensor
  23. from mindspore.ops import operations as P
  24. from mindspore.profiler import Profiler
  25. class Net(nn.Cell):
  26. def __init__(self):
  27. super(Net, self).__init__()
  28. self.add = P.Add()
  29. def construct(self, x_, y_):
  30. return self.add(x_, y_)
  31. x = np.random.randn(1, 3, 3, 4).astype(np.float32)
  32. y = np.random.randn(1, 3, 3, 4).astype(np.float32)
  33. @pytest.mark.level0
  34. @pytest.mark.platform_arm_ascend_training
  35. @pytest.mark.platform_x86_ascend_training
  36. @pytest.mark.env_onecard
  37. def test_ascend_profiling():
  38. if os.path.isdir("./data_ascend_profiler"):
  39. shutil.rmtree("./data_ascend_profiler")
  40. context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
  41. profiler = Profiler(output_path="./data_ascend_profiler", is_detail=True, is_show_op_path=False, subgraph="all")
  42. add = Net()
  43. add(Tensor(x), Tensor(y))
  44. profiler.analyse()
  45. assert len(glob.glob("./data_ascend_profiler/profiler*/JOB*/data/Framework*")) == 6