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

Method exec

dnn/test/common/benchmarker.h:145–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143
144template <typename Opr, typename T, typename OprProxy>
145float BenchmarkerBase<Opr, T, OprProxy>::exec(TensorLayoutArray layouts) {
146 auto opr = this->opr();
147 opr->param() = m_param;
148 auto user_layouts = layouts;
149 m_proxy->deduce_layout(opr, layouts);
150 for (size_t i = 0; i < layouts.size(); ++i) {
151 if (user_layouts[i].ndim > 0) {
152 auto run = [&]() {
153 ASSERT_TRUE(layouts[i].eq_shape(user_layouts[i]))
154 << "User provided shape is "
155 << user_layouts[i].TensorShape::to_string()
156 << "\nExpected shape is "
157 << layouts[i].TensorShape::to_string();
158 };
159 run();
160 }
161 }
162 auto allocate = [&layouts](Handle* handle) {
163 TensorNDArray tensors(layouts.size());
164 auto trans_func = [handle](const TensorLayout& layout) {
165 auto span = layout.span();
166 TensorND res;
167 res.reset_ptr(
168 static_cast<uint8_t*>(megdnn_malloc(handle, span.dist_byte())) -
169 span.low_byte);
170 res.layout = layout;
171 return res;
172 };
173 std::transform(layouts.begin(), layouts.end(), tensors.begin(), trans_func);
174 return tensors;
175 };
176 auto tensors_cur = allocate(m_handle);
177 auto tensors_cur_host = allocate(m_handle_naive.get());
178 // init
179 for (size_t i = 0; i < tensors_cur_host.size(); ++i) {
180 TensorND& tensor = tensors_cur_host[i];
181 auto rng = m_rng[i];
182 if (!rng)
183 rng = m_default_rng.get();
184 rng->gen(tensor);
185 }
186 if (m_tensor_constraint) {
187 m_tensor_constraint(tensors_cur_host);
188 }
189 for (size_t i = 0; i < tensors_cur_host.size(); ++i) {
190 TensorND& tensor = tensors_cur_host[i];
191 if (tensor.layout.ndim == 0)
192 continue;
193 auto size = tensor.layout.span().high_byte;
194 megdnn_memcpy_H2D(m_handle, tensors_cur[i].raw_ptr(), tensor.raw_ptr(), size);
195 }
196 if (m_before_exec_callback) {
197 m_before_exec_callback(opr, tensors_cur);
198 }
199 //! init weights
200 m_proxy->init(opr, tensors_cur);
201 // run
202 // warm up

Callers 2

exectMethod · 0.45
algo_benchmarkFunction · 0.45

Calls 15

oprMethod · 0.95
allocateFunction · 0.85
megcoreSynchronizeFunction · 0.85
freeFunction · 0.85
spanMethod · 0.80
reset_ptrMethod · 0.80
dist_byteMethod · 0.80
runFunction · 0.50
minFunction · 0.50
paramMethod · 0.45
deduce_layoutMethod · 0.45

Tested by

no test coverage detected