| 123 | } |
| 124 | |
| 125 | void NumpyReaderGPU::ScheduleChunkedRead(SampleView<GPUBackend> &out_sample, |
| 126 | NumpyFileWrapperGPU &load_target) { |
| 127 | // TODO(michalz): add nbytes and num_elements to SampleView. |
| 128 | size_t data_bytes = out_sample.shape().num_elements() * |
| 129 | TypeTable::GetTypeInfo(out_sample.type()).size(); |
| 130 | if (!data_bytes) |
| 131 | return; // empty array - short-circuit |
| 132 | |
| 133 | uint8_t *base_ptr = static_cast<uint8_t*>(out_sample.raw_mutable_data()); |
| 134 | uint8_t *dst_ptr = base_ptr; |
| 135 | ssize_t read_start = load_target.data_offset & -gds::kGDSAlignment; // align _down_ |
| 136 | ssize_t file_offset = read_start; |
| 137 | ssize_t read_bytes = data_bytes + load_target.data_offset - read_start; |
| 138 | while (read_bytes > 0) { |
| 139 | ssize_t chunk_read_length = std::min<ssize_t>(read_bytes, chunk_size_); |
| 140 | ssize_t copy_start = std::max(file_offset, load_target.data_offset); |
| 141 | ssize_t copy_skip = copy_start - file_offset; |
| 142 | ssize_t copy_end = file_offset + chunk_read_length; |
| 143 | ssize_t chunk_copy_length = copy_end - copy_start; |
| 144 | thread_pool_.AddWork([=, &load_target, this](int tid) { |
| 145 | assert(chunk_read_length <= static_cast<ssize_t>(staging_.chunk_size())); |
| 146 | auto buffer = staging_.get_staging_buffer(); |
| 147 | load_target.ReadRawChunk(buffer.at(0), chunk_read_length, 0, file_offset); |
| 148 | assert(dst_ptr >= base_ptr && dst_ptr + chunk_copy_length <= base_ptr + data_bytes); |
| 149 | staging_.copy_to_client(dst_ptr, chunk_copy_length, std::move(buffer), copy_skip); |
| 150 | }); |
| 151 | |
| 152 | // update addresses |
| 153 | dst_ptr += chunk_copy_length; |
| 154 | file_offset += chunk_read_length; |
| 155 | read_bytes -= chunk_read_length; |
| 156 | } |
| 157 | assert(dst_ptr == base_ptr + data_bytes); |
| 158 | } |
| 159 | |
| 160 | DALI_REGISTER_OPERATOR(readers__Numpy, NumpyReaderGPU, GPU); |
| 161 |
nothing calls this directly
no test coverage detected