test_ds_aio.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright (c) Microsoft Corporation.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # DeepSpeed Team
  4. """
  5. Functionality of swapping optimizer tensors to/from (NVMe) storage devices.
  6. """
  7. import os
  8. import argparse
  9. import multiprocessing as mp
  10. from ds_aio_basic import aio_basic_multiprocessing
  11. from ds_aio_handle import aio_handle_multiprocessing
  12. from test_ds_aio_utils import refine_args
  13. def parse_arguments():
  14. parser = argparse.ArgumentParser()
  15. parser.add_argument('--read_file', type=str, default=None, help='Read file.')
  16. parser.add_argument('--write_file', type=str, default=None, help='Write file.')
  17. parser.add_argument('--write_size', type=str, default=None, help='Number of bytes to write.')
  18. parser.add_argument('--block_size', type=str, default='1M', help='I/O block size.')
  19. parser.add_argument('--queue_depth', type=int, default=32, help='I/O queue depth.')
  20. parser.add_argument('--threads', type=int, default=1, help='Thread parallelism count.')
  21. parser.add_argument('--single_submit',
  22. action='store_true',
  23. help='Submit I/O requests in singles (default is submit queue_depth amount at once.).')
  24. parser.add_argument('--overlap_events',
  25. action='store_true',
  26. help='Overlap I/O submission and completion requests.')
  27. parser.add_argument('--validate', action='store_true', help='Perform validation in library.')
  28. parser.add_argument('--handle', action='store_true', help='Use AIO handle.')
  29. parser.add_argument('--loops', type=int, default=1, help='Count of operation repetitions')
  30. parser.add_argument('--io_parallel', type=int, default=None, help='Per iop parallelism')
  31. parser.add_argument('--gpu', action='store_true', help='Use GPU memory')
  32. parser.add_argument('--use_accelerator_pin_memory',
  33. action='store_true',
  34. help='Obtain pinned (CPU page-locked) tensors from accelerator')
  35. args = parser.parse_args()
  36. print(f'args = {args}')
  37. return args
  38. def validate_args(args):
  39. if args.read_file and not os.path.isfile(args.read_file):
  40. print(f'args validation error: {args.read_file} not found')
  41. return False
  42. return True
  43. def main():
  44. print(f'Testing deepspeed_aio python frontend')
  45. args = parse_arguments()
  46. refine_args(args)
  47. if not validate_args(args):
  48. quit()
  49. mp.set_start_method('spawn')
  50. multiprocess_function = aio_handle_multiprocessing if args.handle else aio_basic_multiprocessing
  51. if args.read_file:
  52. multiprocess_function(args, True)
  53. if args.write_file:
  54. multiprocess_function(args, False)
  55. if __name__ == "__main__":
  56. main()