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_multigraph_sink.py 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright 2020 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_multigraph_sink """
  16. import pytest
  17. import numpy as np
  18. import mindspore.nn as nn
  19. import mindspore.context as context
  20. from mindspore.common.tensor import Tensor
  21. from mindspore.common import dtype as mstype
  22. from mindspore.common import ms_function
  23. from mindspore.ops import operations as P
  24. def setup_module(module):
  25. context.set_context(mode = context.PYNATIVE_MODE, save_graphs = True, device_target = "Ascend")
  26. context.set_context(enable_task_sink = True, device_id = 0)
  27. c1 = Tensor([2], mstype.int32)
  28. c2 = Tensor([14], mstype.int32)
  29. c3 = Tensor([1], mstype.int32)
  30. c4 = Tensor([0], mstype.int32)
  31. c5 = Tensor([14], mstype.int32)
  32. @ms_function
  33. def simple_if(x, y, z):
  34. if x < y:
  35. x = x + 1
  36. else:
  37. x = x + 2
  38. x = x + 3
  39. return x
  40. @ms_function
  41. def if_by_if(x, y, z):
  42. if x < y:
  43. x = x + 1
  44. if y > x:
  45. x = x + 2
  46. x = x + 3
  47. return x
  48. @ms_function
  49. def if_in_if(x, y, z):
  50. out = c4
  51. if x < y:
  52. z = c4 + c4
  53. if z < y:
  54. z = z + 2
  55. out = out + z
  56. x = x + 3
  57. out = out + x
  58. return out
  59. @ms_function
  60. def simple_while(x, y, z):
  61. y = y + 4
  62. while x < y:
  63. x = x + 1
  64. x = x + 3
  65. return x
  66. @ms_function
  67. def while_by_while(x, y, z):
  68. while x < y:
  69. x = x + 1
  70. while z < c5:
  71. z = z + 1
  72. x = x + 1
  73. x = x + 1
  74. return x
  75. def test_simple_if():
  76. output = simple_if(c1, c2, c3)
  77. expect = Tensor([6], mstype.int32)
  78. assert output == expect
  79. def test_if_by_if():
  80. output = if_by_if(c1, c2, c3)
  81. expect = Tensor([8], mstype.int32)
  82. assert output == expect
  83. def test_if_in_if():
  84. output = if_in_if(c1, c2, c3)
  85. expect = Tensor([7], mstype.int32)
  86. assert output == expect
  87. def test_simple_while():
  88. output = simple_while(c1, c2, c3)
  89. expect = Tensor([21], mstype.int32)
  90. assert output == expect
  91. def test_while_by_while():
  92. output = while_by_while(c1, c2, c3)
  93. expect = Tensor([28], mstype.int32)
  94. assert output == expect