(args)
| 30 | |
| 31 | |
| 32 | def iteration_test(args): |
| 33 | test_pipe_factories = get_pipe_factories( |
| 34 | args.test_pipes, |
| 35 | external_source_parallel_pipeline, |
| 36 | file_reader_pipeline, |
| 37 | external_source_pipeline, |
| 38 | ) |
| 39 | for pipe_factory in test_pipe_factories: |
| 40 | # TODO(klecki): We don't handle sharding in this test yet, would need to do it manually |
| 41 | # for External Source pipelines |
| 42 | pipes = [ |
| 43 | pipe_factory( |
| 44 | batch_size=args.batch_size, |
| 45 | num_threads=args.workers, |
| 46 | device_id=gpu, |
| 47 | data_path=args.data_path, |
| 48 | prefetch_queue_depth=args.prefetch, |
| 49 | reader_queue_depth=args.reader_queue_depth, |
| 50 | py_start_method=args.worker_init, |
| 51 | py_num_workers=args.py_workers, |
| 52 | source_mode=args.source_mode, |
| 53 | read_encoded=args.dali_decode, |
| 54 | ) |
| 55 | for gpu in range(args.gpus) |
| 56 | ] |
| 57 | # First start the Python workers, so we fork without CUDA context. |
| 58 | for pipe in pipes: |
| 59 | pipe.start_py_workers() |
| 60 | for pipe in pipes: |
| 61 | pipe.build() |
| 62 | |
| 63 | samples_no = pipes[0].epoch_size("Reader") |
| 64 | if args.benchmark_iters is None: |
| 65 | expected_iters = samples_no // args.batch_size + (samples_no % args.batch_size != 0) |
| 66 | else: |
| 67 | expected_iters = args.benchmark_iters |
| 68 | |
| 69 | print("RUN {}".format(pipe_factory.__name__)) |
| 70 | for i in range(args.epochs): |
| 71 | if i == 0: |
| 72 | print("Warm up") |
| 73 | else: |
| 74 | print("Test run " + str(i)) |
| 75 | data_time = AverageMeter() |
| 76 | end = time.time() |
| 77 | frequency = 50 |
| 78 | for j in range(expected_iters): |
| 79 | stop_iter = False |
| 80 | for pipe in pipes: |
| 81 | try: |
| 82 | pipe.run() |
| 83 | except StopIteration: |
| 84 | assert j == expected_iters - 1 |
| 85 | stop_iter = True |
| 86 | if stop_iter: |
| 87 | break |
| 88 | if j % frequency == 0 and j != 0: |
| 89 | data_time.update((time.time() - end) / frequency) |
no test coverage detected