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_print_op.py 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 numpy as np
  16. import pytest
  17. from mindspore import Tensor
  18. import mindspore.nn as nn
  19. from mindspore.ops import operations as P
  20. import mindspore.context as context
  21. class PrintNetOneInput(nn.Cell):
  22. def __init__(self):
  23. super(PrintNetOneInput, self).__init__()
  24. self.op = P.Print()
  25. def construct(self, x):
  26. self.op(x)
  27. return x
  28. class PrintNetTwoInputs(nn.Cell):
  29. def __init__(self):
  30. super(PrintNetTwoInputs, self).__init__()
  31. self.op = P.Print()
  32. def construct(self, x, y):
  33. self.op(x, y)
  34. return x
  35. class PrintNetIndex(nn.Cell):
  36. def __init__(self):
  37. super(PrintNetIndex, self).__init__()
  38. self.op = P.Print()
  39. def construct(self, x):
  40. self.op(x[0][0][6][3])
  41. return x
  42. def print_testcase(nptype):
  43. # large shape
  44. x = np.arange(20808).reshape(6, 3, 34, 34).astype(nptype)
  45. # a value that can be stored as int8_t
  46. x[0][0][6][3] = 125
  47. # small shape
  48. y = np.arange(9).reshape(3, 3).astype(nptype)
  49. x = Tensor(x)
  50. y = Tensor(y)
  51. # graph mode
  52. context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
  53. net_1 = PrintNetOneInput()
  54. net_2 = PrintNetTwoInputs()
  55. net_3 = PrintNetIndex()
  56. net_1(x)
  57. net_2(x, y)
  58. net_3(x)
  59. @pytest.mark.level0
  60. @pytest.mark.platform_x86_gpu_training
  61. @pytest.mark.env_onecard
  62. def test_print_bool():
  63. print_testcase(np.bool)
  64. @pytest.mark.level0
  65. @pytest.mark.platform_x86_gpu_training
  66. @pytest.mark.env_onecard
  67. def test_print_int8():
  68. print_testcase(np.int8)
  69. @pytest.mark.level0
  70. @pytest.mark.platform_x86_gpu_training
  71. @pytest.mark.env_onecard
  72. def test_print_int16():
  73. print_testcase(np.int16)
  74. @pytest.mark.level0
  75. @pytest.mark.platform_x86_gpu_training
  76. @pytest.mark.env_onecard
  77. def test_print_int32():
  78. print_testcase(np.int32)
  79. @pytest.mark.level0
  80. @pytest.mark.platform_x86_gpu_training
  81. @pytest.mark.env_onecard
  82. def test_print_int64():
  83. print_testcase(np.int64)
  84. @pytest.mark.level0
  85. @pytest.mark.platform_x86_gpu_training
  86. @pytest.mark.env_onecard
  87. def test_print_uint8():
  88. print_testcase(np.uint8)
  89. @pytest.mark.level0
  90. @pytest.mark.platform_x86_gpu_training
  91. @pytest.mark.env_onecard
  92. def test_print_uint16():
  93. print_testcase(np.uint16)
  94. @pytest.mark.level0
  95. @pytest.mark.platform_x86_gpu_training
  96. @pytest.mark.env_onecard
  97. def test_print_uint32():
  98. print_testcase(np.uint32)
  99. @pytest.mark.level0
  100. @pytest.mark.platform_x86_gpu_training
  101. @pytest.mark.env_onecard
  102. def test_print_uint64():
  103. print_testcase(np.uint64)
  104. @pytest.mark.level0
  105. @pytest.mark.platform_x86_gpu_training
  106. @pytest.mark.env_onecard
  107. def test_print_float16():
  108. print_testcase(np.float16)
  109. @pytest.mark.level0
  110. @pytest.mark.platform_x86_gpu_training
  111. @pytest.mark.env_onecard
  112. def test_print_float32():
  113. print_testcase(np.float32)