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

Method get

src/gopt/impl/global_layout_transform/reformat_manager.cpp:333–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333ReformatManager::ReformatImpl ReformatManager::get(const ReformatKey& key) const {
334 using Attribute = ReformatKey::Attribute;
335 MGB_TRY {
336 {
337 auto find = m_cache.find(key);
338 if (find != m_cache.end()) {
339 auto rst = find->second;
340 return rst;
341 }
342 }
343 if (key.attribute == Attribute::AUTO_PADDING_NHWC) {
344 auto key_ = key;
345 key_.attribute = Attribute::DEFAULT;
346 auto find = m_cache.find(key_);
347 if (find != m_cache.end()) {
348 auto rst = find->second;
349 return rst;
350 }
351 }
352 if (key.attribute == Attribute::IMAGE2D) {
353 auto key_ = key;
354 key_.input_dtype = DTypeEnum::Float32;
355 key_.output_dtype = DTypeEnum::Float32;
356 auto find = m_cache.find(key_);
357 if (find != m_cache.end()) {
358 return find->second;
359 }
360 }
361 mgb_assert(
362 !(key.attribute & Attribute::IMAGE2D) &&
363 !(key.attribute & Attribute::IC_SMALL));
364 auto&& i = key.input_format;
365 auto&& o = key.output_format;
366 auto ishp = tensor_formats_to_named_tensor_shape(i);
367 auto oshp = tensor_formats_to_named_tensor_shape(o);
368 auto builder = std::get<0>(ReformatEmitter{ishp, oshp}.emit());
369 return builder;
370 }
371 MGB_CATCH(std::exception & exc, {
372 mgb_log_error(
373 "cannot find ReformatImpl for ReformatKey(%s), extra "

Calls 5

ifFunction · 0.50
findMethod · 0.45
endMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected