(device, batch_description, dont_use_mmap, use_o_direct)
| 982 | |
| 983 | @cartesian_params(("cpu", "gpu"), ((1, 2, 1), (3, 1, 2)), (True, False), (True, False)) |
| 984 | def test_pad_last_sample(device, batch_description, dont_use_mmap, use_o_direct): |
| 985 | if not is_gds_supported() and device == "gpu": |
| 986 | raise SkipTest("GDS is not supported in this platform") |
| 987 | if not dont_use_mmap and use_o_direct: |
| 988 | raise SkipTest("Cannot use O_DIRECT with mmap") |
| 989 | with tempfile.TemporaryDirectory(prefix=gds_data_root) as test_data_root: |
| 990 | # create files |
| 991 | num_samples, batch_size, num_shards = batch_description |
| 992 | filenames = [] |
| 993 | ref_filenames = [] |
| 994 | arr_np_list = [] |
| 995 | last_file_name = None |
| 996 | for index in range(0, num_samples): |
| 997 | filename = os.path.join(test_data_root, "test_{:02d}.npy".format(index)) |
| 998 | last_file_name = filename |
| 999 | filenames.append(filename) |
| 1000 | create_numpy_file(filename, (5, 2, 8), np.float32, False) |
| 1001 | arr_np_list.append(np.load(filename)) |
| 1002 | ref_filenames.append(filename) |
| 1003 | while len(arr_np_list) < batch_size: |
| 1004 | arr_np_list.append(np.load(last_file_name)) |
| 1005 | ref_filenames.append(last_file_name) |
| 1006 | pipe = NumpyReaderPipeline( |
| 1007 | path=test_data_root, |
| 1008 | files=filenames, |
| 1009 | file_list=None, |
| 1010 | file_filter=None, |
| 1011 | device=device, |
| 1012 | batch_size=batch_size, |
| 1013 | num_threads=4, |
| 1014 | device_id=0, |
| 1015 | pad_last_batch=True, |
| 1016 | num_shards=num_shards, |
| 1017 | dont_use_mmap=dont_use_mmap, |
| 1018 | enable_o_direct=use_o_direct, |
| 1019 | ) |
| 1020 | |
| 1021 | try: |
| 1022 | for _ in range(2): |
| 1023 | pipe_out = pipe.run() |
| 1024 | for i in range(batch_size): |
| 1025 | out_arr = to_array(pipe_out[0][i]) |
| 1026 | out_prop = pipe_out[0][i].source_info() |
| 1027 | ref_arr = arr_np_list[i] |
| 1028 | assert out_prop == ref_filenames[i] |
| 1029 | assert_array_equal(out_arr, ref_arr) |
| 1030 | finally: |
| 1031 | del pipe |
| 1032 | |
| 1033 | |
| 1034 | @cartesian_params(("global", "local", "none"), (True, False)) |
nothing calls this directly
no test coverage detected