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

Method exec_internal

dnn/src/cuda/split/opr_impl.cpp:26–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25template <typename T>
26void SplitForwardImpl::exec_internal(
27 _megdnn_tensor_in src, const TensorNDArray& dsts, _megdnn_workspace workspace) {
28 // Please refer to ConcatForwardImpl. Implementations are similar.
29 auto dsts_layout = apply_vector<TensorLayout>(m_get_layout, dsts);
30 auto dsts_shape = apply_vector<TensorShape>(m_get_shape, dsts_layout);
31 check_exec(src.layout, dsts_layout, workspace.size);
32 size_t A, B, C;
33 auto stream = cuda_stream(this->handle());
34
35 // Pre-calculate B to determine cpu-side workspace size.
36 B = src.layout.shape[param().axis];
37
38 // workspace_cpu will be freed by cuda callback.
39 SmallVector<size_t> workspace_sizes{
40 sizeof(const T*) * dsts.size(),
41 sizeof(size_t) * dsts.size(),
42 sizeof(size_t) * B,
43 sizeof(size_t) * B,
44 };
45
46 WorkspaceBundle workspace_cpu(nullptr, workspace_sizes),
47 workspace_gpu(nullptr, workspace_sizes);
48
49 auto total_workspace_size = workspace_cpu.total_size_in_bytes();
50 void* workspace_cpu_raw = malloc(total_workspace_size);
51 megdnn_assert_internal(workspace_cpu_raw);
52 void* workspace_gpu_raw = static_cast<void*>(workspace.raw_ptr);
53 workspace_cpu = WorkspaceBundle(workspace_cpu_raw, workspace_sizes);
54 workspace_gpu = WorkspaceBundle(workspace_gpu_raw, workspace_sizes);
55
56 auto dsts_cpu = static_cast<T**>(workspace_cpu.get(0));
57 auto dsts_gpu = static_cast<T**>(workspace_gpu.get(0));
58 for (size_t i = 0; i < dsts.size(); ++i) {
59 dsts_cpu[i] = dsts[i].ptr<T>();
60 }
61
62 auto Bv_cpu = static_cast<size_t*>(workspace_cpu.get(1));
63 auto Bv_gpu = static_cast<size_t*>(workspace_gpu.get(1));
64 get_ABC(dsts_shape, A, Bv_cpu, C);
65
66 auto table_outer_cpu = static_cast<size_t*>(workspace_cpu.get(2));
67 auto table_outer_gpu = static_cast<size_t*>(workspace_gpu.get(2));
68 auto table_inner_cpu = static_cast<size_t*>(workspace_cpu.get(3));
69 auto table_inner_gpu = static_cast<size_t*>(workspace_gpu.get(3));
70 {
71 size_t outer_idx = 0, inner_idx = 0;
72
73 for (size_t i = 0; i < B; ++i) {
74 table_outer_cpu[i] = outer_idx;
75 table_inner_cpu[i] = inner_idx;
76 ++inner_idx;
77 if (inner_idx == Bv_cpu[outer_idx]) {
78 ++outer_idx;
79 inner_idx = 0;
80 }
81 }
82 }
83 for (size_t i = 0; i < workspace_cpu.nr_workspace(); ++i) {

Callers

nothing calls this directly

Calls 10

cuda_streamFunction · 0.85
WorkspaceBundleClass · 0.85
get_ABCFunction · 0.85
total_size_in_bytesMethod · 0.80
nr_workspaceMethod · 0.80
paramFunction · 0.50
handleMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
get_sizeMethod · 0.45

Tested by

no test coverage detected