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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. def print_testcase(nptype):
  36. # large shape
  37. x = np.arange(20808).reshape(6, 3, 34, 34).astype(nptype)
  38. # small shape
  39. y = np.arange(9).reshape(3, 3).astype(nptype)
  40. x = Tensor(x)
  41. y = Tensor(y)
  42. # graph mode
  43. context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
  44. net_1 = PrintNetOneInput()
  45. net_2 = PrintNetTwoInputs()
  46. net_1(x)
  47. net_2(x, y)
  48. @pytest.mark.level0
  49. @pytest.mark.platform_x86_gpu_training
  50. @pytest.mark.env_onecard
  51. def test_print_bool():
  52. print_testcase(np.bool)
  53. @pytest.mark.level0
  54. @pytest.mark.platform_x86_gpu_training
  55. @pytest.mark.env_onecard
  56. def test_print_int8():
  57. print_testcase(np.int8)
  58. @pytest.mark.level0
  59. @pytest.mark.platform_x86_gpu_training
  60. @pytest.mark.env_onecard
  61. def test_print_int16():
  62. print_testcase(np.int16)
  63. @pytest.mark.level0
  64. @pytest.mark.platform_x86_gpu_training
  65. @pytest.mark.env_onecard
  66. def test_print_int32():
  67. print_testcase(np.int32)
  68. @pytest.mark.level0
  69. @pytest.mark.platform_x86_gpu_training
  70. @pytest.mark.env_onecard
  71. def test_print_int64():
  72. print_testcase(np.int64)
  73. @pytest.mark.level0
  74. @pytest.mark.platform_x86_gpu_training
  75. @pytest.mark.env_onecard
  76. def test_print_uint8():
  77. print_testcase(np.uint8)
  78. @pytest.mark.level0
  79. @pytest.mark.platform_x86_gpu_training
  80. @pytest.mark.env_onecard
  81. def test_print_uint16():
  82. print_testcase(np.uint16)
  83. @pytest.mark.level0
  84. @pytest.mark.platform_x86_gpu_training
  85. @pytest.mark.env_onecard
  86. def test_print_uint32():
  87. print_testcase(np.uint32)
  88. @pytest.mark.level0
  89. @pytest.mark.platform_x86_gpu_training
  90. @pytest.mark.env_onecard
  91. def test_print_uint64():
  92. print_testcase(np.uint64)
  93. @pytest.mark.level0
  94. @pytest.mark.platform_x86_gpu_training
  95. @pytest.mark.env_onecard
  96. def test_print_float16():
  97. print_testcase(np.float16)
  98. @pytest.mark.level0
  99. @pytest.mark.platform_x86_gpu_training
  100. @pytest.mark.env_onecard
  101. def test_print_float32():
  102. print_testcase(np.float32)