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_profiling.py 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. """
  16. Testing profiling support in DE
  17. """
  18. import os
  19. import numpy as np
  20. import mindspore.dataset as ds
  21. FILES = ["../data/dataset/testTFTestAllTypes/test.data"]
  22. DATASET_ROOT = "../data/dataset/testTFTestAllTypes/"
  23. SCHEMA_FILE = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  24. PIPELINE_FILE_SIZE = "./pipeline_profiling_1.json"
  25. PIPELINE_FILE_THR = "./pipeline_profiling_Connector_Throughput_Sampling_1.json"
  26. DATASET_ITERATOR_FILE = "./dataset_iterator_profiling_1.txt"
  27. def test_profiling_simple_pipeline():
  28. """
  29. Generator -> Shuffle -> Batch
  30. """
  31. os.environ['PROFILING_MODE'] = 'true'
  32. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  33. os.environ['DEVICE_ID'] = '1'
  34. source = [(np.array([x]),) for x in range(1024)]
  35. data1 = ds.GeneratorDataset(source, ["data"])
  36. data1 = data1.shuffle(64)
  37. data1 = data1.batch(32)
  38. for _ in data1:
  39. pass
  40. assert os.path.exists(PIPELINE_FILE_SIZE) is True
  41. os.remove(PIPELINE_FILE_SIZE)
  42. assert os.path.exists(PIPELINE_FILE_THR) is True
  43. os.remove(PIPELINE_FILE_THR)
  44. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  45. os.remove(DATASET_ITERATOR_FILE)
  46. del os.environ['PROFILING_MODE']
  47. del os.environ['MINDDATA_PROFILING_DIR']
  48. def test_profiling_complex_pipeline():
  49. """
  50. Generator -> Map ->
  51. -> Zip -> Batch
  52. TFReader -> Shuffle ->
  53. """
  54. os.environ['PROFILING_MODE'] = 'true'
  55. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  56. os.environ['DEVICE_ID'] = '1'
  57. source = [(np.array([x]),) for x in range(1024)]
  58. data1 = ds.GeneratorDataset(source, ["gen"])
  59. data1 = data1.map("gen", operations=[(lambda x: x + 1)])
  60. pattern = DATASET_ROOT + "/test.data"
  61. data2 = ds.TFRecordDataset(pattern, SCHEMA_FILE, shuffle=ds.Shuffle.FILES)
  62. data2 = data2.shuffle(4)
  63. data3 = ds.zip((data1, data2))
  64. for _ in data3:
  65. pass
  66. assert os.path.exists(PIPELINE_FILE_SIZE) is True
  67. os.remove(PIPELINE_FILE_SIZE)
  68. assert os.path.exists(PIPELINE_FILE_THR) is True
  69. os.remove(PIPELINE_FILE_THR)
  70. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  71. os.remove(DATASET_ITERATOR_FILE)
  72. del os.environ['PROFILING_MODE']
  73. del os.environ['MINDDATA_PROFILING_DIR']
  74. def test_profiling_sampling_iterval():
  75. """
  76. Test non-default monitor sampling interval
  77. """
  78. os.environ['PROFILING_MODE'] = 'true'
  79. os.environ['MINDDATA_PROFILING_DIR'] = '.'
  80. os.environ['DEVICE_ID'] = '1'
  81. interval_origin = ds.config.get_monitor_sampling_interval()
  82. ds.config.set_monitor_sampling_interval(30)
  83. interval = ds.config.get_monitor_sampling_interval()
  84. assert interval == 30
  85. source = [(np.array([x]),) for x in range(1024)]
  86. data1 = ds.GeneratorDataset(source, ["data"])
  87. data1 = data1.shuffle(64)
  88. data1 = data1.batch(32)
  89. for _ in data1:
  90. pass
  91. assert os.path.exists(PIPELINE_FILE_SIZE) is True
  92. os.remove(PIPELINE_FILE_SIZE)
  93. assert os.path.exists(PIPELINE_FILE_THR) is True
  94. os.remove(PIPELINE_FILE_THR)
  95. assert os.path.exists(DATASET_ITERATOR_FILE) is True
  96. os.remove(DATASET_ITERATOR_FILE)
  97. ds.config.set_monitor_sampling_interval(interval_origin)
  98. del os.environ['PROFILING_MODE']
  99. del os.environ['MINDDATA_PROFILING_DIR']
  100. if __name__ == "__main__":
  101. test_profiling_simple_pipeline()
  102. test_profiling_complex_pipeline()
  103. test_profiling_sampling_iterval()