MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / check_tensor_for_transpose

Function check_tensor_for_transpose

dnn/src/cambricon/relayout/opr_impl.cpp:48–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48bool check_tensor_for_transpose(
49 const TensorLayout& src_layout, const TensorLayout& dst_layout,
50 std::vector<size_t>& permute) {
51 if (!src_layout.eq_shape(dst_layout)) {
52 return false;
53 }
54 if (!dst_layout.is_contiguous()) {
55 return false;
56 }
57 size_t ndim = src_layout.ndim;
58
59 permute.resize(ndim);
60 rep(i, ndim) { permute[i] = i; }
61 std::sort(permute.begin(), permute.end(), [&src_layout](int i, int j) {
62 return src_layout.stride[i] >= src_layout.stride[j];
63 });
64 TensorLayout ori_src_layout = src_layout.dimshuffle(permute);
65 if (!ori_src_layout.is_contiguous()) {
66 return false;
67 }
68 return true;
69}
70
71bool try_transpose(
72 _megdnn_tensor_in src, _megdnn_tensor_out dst, RelayoutForwardImpl* opr,

Callers 1

try_transposeFunction · 0.85

Calls 7

sortFunction · 0.85
resizeMethod · 0.80
dimshuffleMethod · 0.80
eq_shapeMethod · 0.45
is_contiguousMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected