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