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 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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, device_target = "Ascend")
  26. c1 = Tensor([2], mstype.int32)
  27. c2 = Tensor([14], mstype.int32)
  28. c3 = Tensor([1], mstype.int32)
  29. c4 = Tensor([0], mstype.int32)
  30. c5 = Tensor([14], mstype.int32)
  31. @ms_function
  32. def simple_if(x, y, z):
  33. if x < y:
  34. x = x + 1
  35. else:
  36. x = x + 2
  37. x = x + 3
  38. return x
  39. @ms_function
  40. def if_by_if(x, y, z):
  41. if x < y:
  42. x = x + 1
  43. if y > x:
  44. x = x + 2
  45. x = x + 3
  46. return x
  47. @ms_function
  48. def if_in_if(x, y, z):
  49. out = c4
  50. if x < y:
  51. z = c4 + c4
  52. if z < y:
  53. z = z + 2
  54. out = out + z
  55. x = x + 3
  56. out = out + x
  57. return out
  58. @ms_function
  59. def simple_while(x, y, z):
  60. y = y + 4
  61. while x < y:
  62. x = x + 1
  63. x = x + 3
  64. return x
  65. @ms_function
  66. def while_by_while(x, y, z):
  67. while x < y:
  68. x = x + 1
  69. while z < c5:
  70. z = z + 1
  71. x = x + 1
  72. x = x + 1
  73. return x
  74. @ms_function
  75. def while_in_while(x, y, z):
  76. out = c4
  77. while x < y:
  78. z = c4 + c4
  79. while z < y:
  80. z = z + 1
  81. out = out + z
  82. x = x + 1
  83. out = out + x
  84. return out
  85. @ms_function
  86. def while_by_while_in_while(x, y, z):
  87. out = c4
  88. while x < c2:
  89. y = c4 + c4
  90. while y < c2:
  91. y = y + 1
  92. out = out + y
  93. z = c4 + c4
  94. while z < c2:
  95. z = z + 1
  96. out = out + z
  97. x = x + 1
  98. out = out + x
  99. return out
  100. @ms_function
  101. def while_in_while_in_while(x, y, z):
  102. out = c4
  103. while x < c2:
  104. y = c4 + c4
  105. while y < c2:
  106. y = y + 1
  107. z = c4 + c4
  108. while z < c2:
  109. z = z + 1
  110. out = out + z
  111. out = out + y
  112. x = x + 1
  113. out = out + x
  114. return out
  115. @pytest.mark.level0
  116. @pytest.mark.platform_x86_ascend_training
  117. @pytest.mark.platform_arm_ascend_training
  118. @pytest.mark.env_onecard
  119. def test_simple_if():
  120. output = simple_if(c1, c2, c3)
  121. expect = Tensor([6], mstype.int32)
  122. assert output == expect
  123. def test_if_by_if():
  124. output = if_by_if(c1, c2, c3)
  125. expect = Tensor([8], mstype.int32)
  126. assert output == expect
  127. def test_if_in_if():
  128. output = if_in_if(c1, c2, c3)
  129. expect = Tensor([7], mstype.int32)
  130. assert output == expect
  131. @pytest.mark.level0
  132. @pytest.mark.platform_x86_ascend_training
  133. @pytest.mark.platform_arm_ascend_training
  134. @pytest.mark.env_onecard
  135. def test_simple_while():
  136. output = simple_while(c1, c2, c3)
  137. expect = Tensor([21], mstype.int32)
  138. assert output == expect
  139. @pytest.mark.level0
  140. @pytest.mark.platform_x86_ascend_training
  141. @pytest.mark.platform_arm_ascend_training
  142. @pytest.mark.env_onecard
  143. def test_while_by_while():
  144. output = while_by_while(c1, c2, c3)
  145. expect = Tensor([28], mstype.int32)
  146. assert output == expect
  147. @pytest.mark.level0
  148. @pytest.mark.platform_x86_ascend_training
  149. @pytest.mark.platform_arm_ascend_training
  150. @pytest.mark.env_onecard
  151. def test_while_in_while():
  152. output = while_in_while(c1, c2, c3)
  153. expect = Tensor([1274], mstype.int32)
  154. assert output == expect
  155. @pytest.mark.level0
  156. @pytest.mark.platform_x86_ascend_training
  157. @pytest.mark.platform_arm_ascend_training
  158. @pytest.mark.env_onecard
  159. def test_while_by_while_in_while():
  160. output = while_by_while_in_while(c1, c2, c3)
  161. expect = Tensor([350], mstype.int32)
  162. assert output == expect
  163. @pytest.mark.level0
  164. @pytest.mark.platform_x86_ascend_training
  165. @pytest.mark.platform_arm_ascend_training
  166. @pytest.mark.env_onecard
  167. def test_while_in_while_in_while():
  168. output = while_in_while_in_while(c1, c2, c3)
  169. expect = Tensor([2534], mstype.int32)
  170. assert output == expect