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

Method get_workspace_in_bytes

dnn/src/arm_common/pooling/opr_impl.cpp:110–159  ·  view source on GitHub ↗

namespace

Source from the content-addressed store, hash-verified

108
109} // namespace
110size_t PoolingImpl::get_workspace_in_bytes(
111 const TensorLayout& src, const TensorLayout& dst) {
112 auto param = make_pooling_kern_szie_param(this, src, dst);
113 bool fwd_reduce = is_global_pooling_reduce(param);
114 if (fwd_reduce) {
115 TensorND src_tensor{nullptr, src};
116 TensorND dst_tensor{nullptr, dst};
117 auto reduce_tensor = get_gloabl_pooling_reduce_tensor(src_tensor, dst_tensor);
118 auto&& opr = get_global_pooling_reduce_opr(nullptr, param);
119 auto reduce_need = opr->get_workspace_in_bytes(
120 reduce_tensor.first.layout, reduce_tensor.second.layout);
121 return reduce_need;
122 }
123
124 auto algo = get_algorithm(this, src, dst);
125 if (!is_fallback_algo(algo)) {
126 size_t arm_common_workspace = 0;
127
128 //! When multi-thread, every thread has its own workspace
129 size_t nr_threads = static_cast<naive::HandleImpl*>(handle())
130 ->megcore_dispatcher()
131 ->nr_threads();
132 if ((param.src_type.category() == DTypeCategory::FLOAT ||
133 param.src_type == dtype::Int8{} ||
134 param.src_type.enumv() == DTypeEnum::QuantizedS8 ||
135 param.src_type.enumv() == DTypeEnum::Quantized8Asymm) &&
136 param.filter[0] == param.filter[1] &&
137 (param.filter[0] == 3 || param.filter[0] == 5) &&
138 param.format == Param::Format::NCHW &&
139 (param.mode == Mode::MAX ||
140 (param.mode == Mode::AVERAGE && param.filter[0] == 3)) &&
141 param.stride[0] == 2 && param.stride[1] == 2 && param.isz[0] >= 2 &&
142 param.isz[1] >= 2) {
143 WorkspaceBundle ws = get_bundle(param);
144 arm_common_workspace = ws.total_size_in_bytes() * nr_threads;
145 }
146
147 if ((param.src_type.enumv() == DTypeEnum::QuantizedS8 ||
148 param.src_type.enumv() == DTypeEnum::Int8) &&
149 (param.format == param::Pooling::Format::NCHW44)) {
150 WorkspaceBundle ws = get_bundle_nchw44(param);
151 arm_common_workspace = ws.total_size_in_bytes() * nr_threads;
152 }
153 return arm_common_workspace;
154 } else {
155 auto fallback_worksapce =
156 fallback::PoolingImpl::get_workspace_in_bytes(src, dst);
157 return fallback_worksapce;
158 }
159}
160
161void PoolingImpl::exec(
162 _megdnn_tensor_in src, _megdnn_tensor_out dst, _megdnn_workspace workspace) {

Callers

nothing calls this directly

Calls 12

is_global_pooling_reduceFunction · 0.85
get_algorithmFunction · 0.85
get_bundle_nchw44Function · 0.85
megcore_dispatcherMethod · 0.80
categoryMethod · 0.80
total_size_in_bytesMethod · 0.80
get_bundleFunction · 0.70
get_workspace_in_bytesFunction · 0.50
nr_threadsMethod · 0.45
enumvMethod · 0.45

Tested by

no test coverage detected