| 16 | } |
| 17 | |
| 18 | void TileImpl::exec( |
| 19 | _megdnn_tensor_in src_, _megdnn_tensor_out dst_, _megdnn_workspace workspace) { |
| 20 | check_exec(src_.layout, dst_.layout, workspace.size); |
| 21 | TensorShape src, dst, times; |
| 22 | simplify_shape(src_.layout, dst_.layout, param().times, src, dst, times); |
| 23 | auto nr_reduces = count_not_ones_in_shape(times); |
| 24 | if (nr_reduces == 0) { |
| 25 | MEGDNN_DISPATCH_CPU_KERN_OPR(std::memcpy( |
| 26 | dst_.raw_ptr(), src_.raw_ptr(), sizeof(float) * dst.total_nr_elems())); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | auto kern = [=]() { |
| 31 | auto ndim = times.ndim; |
| 32 | WorkspaceBundle workspaces( |
| 33 | workspace.raw_ptr, {dst.total_nr_elems() * sizeof(float), |
| 34 | dst.total_nr_elems() * sizeof(float)}); |
| 35 | auto workspace0 = static_cast<float*>(workspaces.get(0)); |
| 36 | auto workspace1 = static_cast<float*>(workspaces.get(1)); |
| 37 | |
| 38 | float *current, *next; |
| 39 | size_t state; |
| 40 | |
| 41 | init_tile_repeat_state( |
| 42 | src_.ptr<dt_float32>(), dst_.ptr<dt_float32>(), workspace0, workspace1, |
| 43 | current, next, state, nr_reduces); |
| 44 | |
| 45 | for (size_t i = ndim; i > 0; --i) { |
| 46 | size_t j = i - 1; |
| 47 | if (times.shape[j] != 1) { |
| 48 | // m = sshape[0]*...*sshape[i-2] |
| 49 | auto m = std::accumulate( |
| 50 | src.shape, src.shape + j, 1_z, SafeMultiplies<size_t>()); |
| 51 | // n = sshape[i-1]*dshape[i]*... |
| 52 | auto n = std::accumulate( |
| 53 | dst.shape + i, dst.shape + ndim, 1_z, |
| 54 | SafeMultiplies<size_t>()) * |
| 55 | src.shape[j]; |
| 56 | // forward is repeat (m, n) to (m*times, n) |
| 57 | tile_or_repeat_single_axis(current, next, m, n, times[j]); |
| 58 | update_tile_repeat_state( |
| 59 | src_.ptr<dt_float32>(), dst_.ptr<dt_float32>(), workspace0, |
| 60 | workspace1, current, next, state, nr_reduces); |
| 61 | } |
| 62 | } |
| 63 | }; |
| 64 | MEGDNN_DISPATCH_CPU_KERN_OPR(kern()); |
| 65 | } |
| 66 | |
| 67 | } // namespace fallback |
| 68 | } // namespace megdnn |
nothing calls this directly
no test coverage detected