| 27 | namespace dali { |
| 28 | |
| 29 | static void CopyHelper(SampleView<CPUBackend> output, ConstSampleView<CPUBackend> input, |
| 30 | ThreadPool &thread_pool, int min_blk_sz, int req_nblocks) { |
| 31 | auto *out_ptr = static_cast<uint8_t *>(output.raw_mutable_data()); |
| 32 | const auto *in_ptr = static_cast<const uint8_t *>(input.raw_data()); |
| 33 | auto nelements = input.shape().num_elements(); |
| 34 | auto nbytes = nelements * TypeTable::GetTypeInfo(input.type()).size(); |
| 35 | if (nelements <= min_blk_sz) { |
| 36 | thread_pool.AddWork([=](int tid) { |
| 37 | std::memcpy(out_ptr, in_ptr, nbytes); |
| 38 | }, nelements); |
| 39 | } else { |
| 40 | int64_t prev_b_start = 0; |
| 41 | for (int b = 0; b < req_nblocks; b++) { |
| 42 | int64_t b_start = prev_b_start; |
| 43 | int64_t b_end = prev_b_start = nbytes * (b + 1) / req_nblocks; |
| 44 | int64_t b_size = b_end - b_start; |
| 45 | thread_pool.AddWork([=](int tid) { |
| 46 | std::memcpy(out_ptr + b_start, in_ptr + b_start, b_size); |
| 47 | }, b_size); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static void SliceHelper(SampleView<CPUBackend> output, ConstSampleView<CPUBackend> input, |
| 53 | const CropWindow &roi, float fill_value, ThreadPool &thread_pool, |
no test coverage detected