(self, tmpdir, use_fd, file_partitions)
| 281 | |
| 282 | @pytest.mark.parametrize('use_fd', [False, True]) |
| 283 | def test_offset_write(self, tmpdir, use_fd, file_partitions): |
| 284 | ref_file = _get_file_path(tmpdir, '_py_random') |
| 285 | aio_file = _get_file_path(tmpdir, '_aio_random') |
| 286 | partition_unit_size = IO_SIZE |
| 287 | file_size = sum(file_partitions) * partition_unit_size |
| 288 | |
| 289 | h = GDSBuilder().load().gds_handle(BLOCK_SIZE, QUEUE_DEPTH, True, True, IO_PARALLEL) |
| 290 | |
| 291 | gds_buffer = torch.empty(file_size, dtype=torch.uint8, device=get_accelerator().device_name()) |
| 292 | h.pin_device_tensor(gds_buffer) |
| 293 | |
| 294 | file_offsets = [] |
| 295 | next_offset = 0 |
| 296 | for i in range(len(file_partitions)): |
| 297 | file_offsets.append(next_offset) |
| 298 | next_offset += file_partitions[i] * partition_unit_size |
| 299 | |
| 300 | ref_fd = open(ref_file, 'wb') |
| 301 | for i in range(len(file_partitions)): |
| 302 | src_buffer = torch.narrow(gds_buffer, 0, file_offsets[i], |
| 303 | file_partitions[i] * partition_unit_size).to(device='cpu') |
| 304 | |
| 305 | ref_fd.write(src_buffer.numpy().tobytes()) |
| 306 | ref_fd.flush() |
| 307 | |
| 308 | if use_fd: |
| 309 | aio_fd = os.open(aio_file, flags=os.O_DIRECT | os.O_CREAT | os.O_WRONLY) |
| 310 | write_status = h.async_pwrite(buffer=src_buffer, fd=aio_fd, file_offset=file_offsets[i]) |
| 311 | else: |
| 312 | write_status = h.async_pwrite(buffer=src_buffer, filename=aio_file, file_offset=file_offsets[i]) |
| 313 | |
| 314 | assert write_status == 0 |
| 315 | wait_status = h.wait() |
| 316 | assert wait_status == 1 |
| 317 | |
| 318 | if use_fd: |
| 319 | assert os.path.isfile(aio_fd) |
| 320 | os.close(aio_fd) |
| 321 | |
| 322 | filecmp.clear_cache() |
| 323 | assert filecmp.cmp(ref_file, aio_file, shallow=False) |
| 324 | |
| 325 | ref_fd.close() |
| 326 | |
| 327 | h.unpin_device_tensor(gds_buffer) |
| 328 | |
| 329 | def test_offset_read(self, tmpdir, file_partitions): |
| 330 | partition_unit_size = BLOCK_SIZE |
nothing calls this directly
no test coverage detected