| 42 | } |
| 43 | |
| 44 | bool RelayoutForwardImpl::Param::try_copy_2d() { |
| 45 | TensorLayout lsrc = m_src.layout, ldst = m_dst.layout; |
| 46 | |
| 47 | if (lsrc.ndim > 2 || ldst.ndim > 2) |
| 48 | return false; |
| 49 | |
| 50 | if (ldst.ndim == 1 && lsrc.ndim == 1) { |
| 51 | megdnn_assert(ldst.stride[0] != 1 || lsrc.stride[0] != 1); |
| 52 | if (lsrc.stride[0] < 1 || ldst.stride[0] < 1) |
| 53 | return false; |
| 54 | // extend to ndim == 2 |
| 55 | megdnn_assert(ldst.shape[0] == lsrc.shape[0]); |
| 56 | ldst.ndim = lsrc.ndim = 2; |
| 57 | ldst.shape[1] = lsrc.shape[1] = 1; |
| 58 | ldst.stride[1] = lsrc.stride[1] = 1; |
| 59 | } else if (ldst.ndim < 2) { |
| 60 | if (!expand_dim2(ldst, lsrc)) |
| 61 | return false; |
| 62 | } else if (lsrc.ndim < 2) { |
| 63 | if (!expand_dim2(lsrc, ldst)) |
| 64 | return false; |
| 65 | } |
| 66 | if (ldst.stride[1] != 1 || lsrc.stride[1] != 1 || ldst.shape[0] != lsrc.shape[0] || |
| 67 | ldst.shape[1] != lsrc.shape[1] || |
| 68 | ldst.stride[0] < static_cast<ptrdiff_t>(ldst.shape[1]) || |
| 69 | lsrc.stride[0] < static_cast<ptrdiff_t>(ldst.shape[1])) |
| 70 | return false; |
| 71 | |
| 72 | //! TODO: need refactor, hipMemcpy2DAsync has bug |
| 73 | auto dsize = dtype_size(); |
| 74 | hip_check(hipMemcpy2DAsync( |
| 75 | m_dst.raw_ptr(), ldst.stride[0] * dsize, m_src.raw_ptr(), |
| 76 | lsrc.stride[0] * dsize, ldst.shape[1] * dsize, ldst.shape[0], |
| 77 | hipMemcpyDeviceToDevice, m_opr->stream())); |
| 78 | |
| 79 | return true; |
| 80 | }; |
| 81 | |
| 82 | bool RelayoutForwardImpl::Param::try_copy_last_contig() { |
| 83 | //! check if the last stride is contiguous |