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

Method exec_internal

dnn/src/rocm/convolution/backward_data/matmul.cpp:36–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35template <typename T>
36void ConvolutionBackwardDataImpl::AlgoMatmul::exec_internal(const ExecArgs& args) {
37 auto&& fm = args.filter_meta;
38 size_t N = args.grad_layout->shape[0], IC = fm.icpg,
39 IH = args.grad_layout->shape[2], IW = args.grad_layout->shape[3],
40 OC = fm.ocpg, OH = args.diff_layout->shape[2],
41 OW = args.diff_layout->shape[3], FH = fm.spatial[0], FW = fm.spatial[1],
42 PH = fm.padding[0], PW = fm.padding[1], SH = fm.stride[0], SW = fm.stride[1],
43 DH = fm.dilation[0], DW = fm.dilation[1];
44 auto stream = hip_stream(args.handle);
45 auto wbundle = matmul_get_workspace_bundle(args.as_fwd_args());
46 wbundle.set(args.workspace.raw_ptr);
47 T* diff_t = static_cast<T*>(wbundle.get(0));
48 T* col = static_cast<T*>(wbundle.get(1));
49 {
50 // transpose diff
51 TensorLayout froml({N, OC * OH * OW}, typename DTypeTrait<T>::dtype()),
52 tol(froml);
53 froml.stride[0] = args.diff_layout->stride[0];
54 tol.stride[0] = 1;
55 tol.stride[1] = N;
56 TensorND from(args.diff_tensor->ptr<T>(), froml), to(diff_t, tol);
57 args.handle->relayout_opr()->exec(from, to);
58 }
59 {
60 // take gemm grad
61 TensorLayout Al({OC, IC * FH * FW}, typename DTypeTrait<T>::dtype()),
62 Bl({IC * FH * FW, OH * OW * N}, typename DTypeTrait<T>::dtype()),
63 Cl({OC, OH * OW * N}, typename DTypeTrait<T>::dtype());
64 TensorND A(args.filter_tensor->ptr<T>(), Al), B(col, Bl), C(diff_t, Cl);
65 if (fm.should_flip) {
66 convolution::flip_filter(
67 args.as_fwd_args(), wbundle.get_workspace(2), A.get_ref_ptr());
68 }
69 args.handle->matmul_aT_opr()->exec(A, C, B, Workspace());
70 }
71 {
72 convolution::col2im<T>(
73 col, args.grad_tensor->ptr<T>(), N, args.grad_layout->stride[0], IC, IH,
74 IW, FH, FW, OH, OW, PH, PW, SH, SW, DH, DW, stream);
75 }
76}
77
78// vim: syntax=cpp.doxygen

Callers

nothing calls this directly

Calls 12

hip_streamFunction · 0.85
flip_filterFunction · 0.85
WorkspaceClass · 0.85
as_fwd_argsMethod · 0.45
setMethod · 0.45
getMethod · 0.45
execMethod · 0.45
relayout_oprMethod · 0.45
get_workspaceMethod · 0.45
get_ref_ptrMethod · 0.45
matmul_aT_oprMethod · 0.45

Tested by

no test coverage detected