• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 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 pytest
17import mindspore.context as context
18from mindspore import Tensor, nn
19from mindspore.common import dtype as mstype
20from mindspore import Parameter
21
22
23class GraphNet(nn.Cell):
24    def __init__(self):
25        super().__init__()
26        self.param_a = Parameter(Tensor(10, mstype.float32), name="a")
27        self.zero = Parameter(Tensor(0, mstype.float32), name="zero")
28
29    def construct(self, x):
30        out = self.zero
31        out1 = self.param_a
32        if x > 0:
33            out = out + self.param_a
34        if x > 2:
35            out1 += self.param_a
36            out += self.param_a
37        out1 += self.param_a
38        return out, out1
39
40def aoe_online():
41    context.set_context(mode=context.GRAPH_MODE, aoe_tune_mode="online", aoe_config={"job_type": "2"})
42    context.set_context(jit_config={"jit_level": "O2"})
43    net = GraphNet()
44    x = Tensor(3, mstype.int32)
45    out0, out1 = net(x)
46    assert out0 == Tensor(20, mstype.float32)
47    assert out1 == Tensor(30, mstype.float32)
48
49@pytest.mark.level0
50@pytest.mark.platform_x86_ascend_training
51@pytest.mark.platform_arm_ascend_training
52@pytest.mark.platform_arm_ascend910b_training
53@pytest.mark.env_onecard
54def test_aoe():
55    """
56    Feature: aoe
57    Description: aoe with ge backend.
58    Expectation: success.
59    """
60    aoe_online()
61    ret = os.system(f"ls aoe_result_opat_*.json")
62    assert ret == 0
63