From 60cdef6eb0e829003959e027b205b846e35dcec8 Mon Sep 17 00:00:00 2001 From: "River.Li" Date: Sat, 15 Jul 2023 19:20:05 +0800 Subject: [PATCH] Remove tets code --- src/plugins/intel_cpu/src/compiled_model.cpp | 52 +------- src/plugins/intel_cpu/src/graph.cpp | 128 +++++++------------ 2 files changed, 46 insertions(+), 134 deletions(-) diff --git a/src/plugins/intel_cpu/src/compiled_model.cpp b/src/plugins/intel_cpu/src/compiled_model.cpp index 2024ae3c26698b..08140322381055 100644 --- a/src/plugins/intel_cpu/src/compiled_model.cpp +++ b/src/plugins/intel_cpu/src/compiled_model.cpp @@ -68,7 +68,6 @@ CompiledModel::CompiledModel(const std::shared_ptr& model, m_cfg.isLegacyApi = !core->is_new_api(); bool support_all_precision = true; -#if 0 auto get_graph_supported_precisions = [&]() -> std::set { std::set supported_precisions = {ov::element::Type_t::u8, ov::element::Type_t::i8, @@ -93,7 +92,6 @@ CompiledModel::CompiledModel(const std::shared_ptr& model, support_all_precision = false; } - if (!support_all_precision) { m_graph_model = m_model->clone(); Transformations graph_transformations(m_graph_model, @@ -106,55 +104,7 @@ CompiledModel::CompiledModel(const std::shared_ptr& model, } else { m_graph_model = m_model; } -#else - auto get_convert_precisions = []() { - precisions_map map = {{ov::element::i64, ov::element::i32}, - {ov::element::u64, ov::element::i32}, - {ov::element::i16, ov::element::i32}, - {ov::element::u16, ov::element::i32}, - {ov::element::u32, ov::element::i32}, - {ov::element::f64, ov::element::f32}, - {ov::element::f16, ov::element::f32}, - {ov::element::boolean, ov::element::u8}, - {ov::element::i4, ov::element::i8}, - {ov::element::u4, ov::element::u8}}; - - if (!dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core)) - map.insert({ov::element::bf16, ov::element::f32}); - - return map; - }; - static const auto convert_precisions = get_convert_precisions(); - - m_graph_model = m_model->clone(); - ov::preprocess::PrePostProcessor preproc(m_graph_model); - for (size_t i = 0; i < m_graph_model->inputs().size(); i++) { - auto port = m_graph_model->input(i); - auto prec = port.get_element_type(); - std::cout << "input " << i << ", prec = " << prec << std::endl; - auto it = convert_precisions.find(prec); - if (it != convert_precisions.end()) { - preproc.input(i).tensor().set_element_type(it->second); - support_all_precision = false; - std::cout << "preproc: input precision convert " << it->first << " to " << it->second << std::endl; - } - } - for (size_t i = 0; i < m_graph_model->outputs().size(); i++) { - auto port = m_graph_model->output(i); - auto prec = port.get_element_type(); - std::cout << "input " << i << ", prec = " << prec << std::endl; - auto it = convert_precisions.find(prec); - if (it != convert_precisions.end()) { - preproc.output(i).tensor().set_element_type(it->second); - support_all_precision = false; - std::cout << "preproc: output precision covert " << it->first << " to " << it->second << std::endl; - } - } - if (!support_all_precision) - preproc.build(); - else - m_graph_model = m_model; -#endif + std::cout << std::endl << "support_all_precision = " << support_all_precision << std::endl; for (const auto& in : m_graph_model->inputs()) { auto port_name = get_port_name(in, false); diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp index 88788259a22a70..80ae626f5e4c98 100644 --- a/src/plugins/intel_cpu/src/graph.cpp +++ b/src/plugins/intel_cpu/src/graph.cpp @@ -867,99 +867,61 @@ void Graph::PushInputData(const std::string& name, const ov::SoPtr &in) auto input = inputNodesMap.find(name); if (input != inputNodesMap.end()) { -#if 0 - auto create_mem_desc = [&](const ov::SoPtr& tensor, - InferenceEngine::Precision& precision) -> CpuBlockedMemoryDesc { + auto create_mem_desc = [&](const ov::SoPtr& tensor) -> CpuBlockedMemoryDesc { InferenceEngine::TensorDesc tensorDesc( - precision, + ie::details::convertPrecision(tensor->get_element_type()), tensor->get_shape(), InferenceEngine::TensorDesc::getLayoutByRank(tensor->get_shape().size())); return MemoryDescUtils::convertToCpuBlockedMemoryDesc(tensorDesc); }; -#else - auto create_mem_desc = [&](const ov::SoPtr& tensor) -> CpuBlockedMemoryDesc { - auto element_type = tensor->get_element_type(); - auto shape = tensor->get_shape(); - std::vector blk_order(shape.size()); - std::iota(blk_order.begin(), blk_order.end(), 0); - std::vector dim_offset(shape.size(), 0); - std::vector blk_strides; - auto byte_strides = element_type.bitwidth() >= 8 ? tensor->get_strides() : Strides{}; - Shape mem_shape(shape); - if (mem_shape.hasZeroDims()) { - blk_strides = std::vector(shape.size(), 0); - } else if (byte_strides.empty()) { - blk_strides = ov::row_major_strides(shape); - } else { - blk_strides.resize(byte_strides.size()); - std::transform(byte_strides.begin(), - byte_strides.end(), - blk_strides.begin(), - [&element_type](size_t byte_stride) { - OPENVINO_ASSERT(byte_stride % element_type.size() == 0, - "Limitation: Stride in bytes ", - byte_stride, - " should be divisible by size of element ", - element_type.size()); - return byte_stride / element_type.size(); - }); + + auto node = input->second; + auto childEdge = node->getChildEdgeAt(0); + const auto& outDims = node->getOutputShapeAtPort(0); + + const void* ext_data_ptr = in->data(); + void* inter_data_ptr = childEdge->getMemory().getData(); + + // Convert data if precision mismatch + auto& inter_mem_desc = childEdge->getMemory().getDesc(); + auto inter_precision = inter_mem_desc.getPrecision(); + auto ext_precision = ie::details::convertPrecision(in->get_element_type()); + auto ext_tensor_desc = create_mem_desc(in); + if (ext_precision != inter_precision) { + if ((inter_data_ptr == nullptr) || (ext_data_ptr == nullptr)) { + OPENVINO_THROW("Get tensor has no allocated memory"); } - return CpuBlockedMemoryDesc(ie::details::convertPrecision(element_type), - mem_shape, - shape, - blk_order, - 0, - dim_offset, - blk_strides); - }; -#endif - auto node = input->second; - auto childEdge = node->getChildEdgeAt(0); - const auto& outDims = node->getOutputShapeAtPort(0); - - const void* ext_data_ptr = in->data(); - void* inter_data_ptr = childEdge->getMemory().getData(); - - // Convert data if precision mismatch - auto& inter_mem_desc = childEdge->getMemory().getDesc(); - auto inter_precision = inter_mem_desc.getPrecision(); - auto ext_precision = ie::details::convertPrecision(in->get_element_type()); - auto ext_tensor_desc = create_mem_desc(in); - if (ext_precision != inter_precision) { - if ((inter_data_ptr == nullptr) || (ext_data_ptr == nullptr)) { - OPENVINO_THROW("Get tensor has no allocated memory"); - } - cpu_convert(ext_data_ptr, inter_data_ptr, ext_precision, inter_precision, in->get_size()); - std::cout << "push_input: convert data " << ext_precision << " to " << inter_precision << std::endl; + cpu_convert(ext_data_ptr, inter_data_ptr, ext_precision, inter_precision, in->get_size()); + std::cout << "push_input: convert data " << ext_precision << " to " << inter_precision << std::endl; - std::cout << "input data: " << std::endl; - float* p = static_cast(inter_data_ptr); - for (size_t i = 0; i < in->get_size(); i++) { - std::cout << " " << p[i]; - } - std::cout << std::endl; - - Memory mem(getEngine(), inter_mem_desc, inter_data_ptr, false); - childEdge->getMemory().load(mem, false); - } else if (ext_data_ptr != inter_data_ptr) { - Memory ext_mem(getEngine(), inter_mem_desc, ext_data_ptr, false); - childEdge->getMemory().load(ext_mem, false); - std::cout << "push_input: update data " << ext_precision << " to " << inter_precision << std::endl; + std::cout << "input data: " << std::endl; + float* p = static_cast(inter_data_ptr); + for (size_t i = 0; i < in->get_size() && i < 10; i++) { + std::cout << " " << p[i]; } + std::cout << std::endl; + + Memory mem(getEngine(), inter_mem_desc, inter_data_ptr, false); + childEdge->getMemory().load(mem, false); + } else if (ext_data_ptr != inter_data_ptr) { + Memory ext_mem(getEngine(), inter_mem_desc, ext_data_ptr, false); + childEdge->getMemory().load(ext_mem, false); + std::cout << "push_input: update data " << ext_precision << " to " << inter_precision << std::endl; + } - // todo: make sure 'name' exists in this map... - if (_normalizePreprocMap.find(name) != _normalizePreprocMap.end()) { - if (ext_tensor_desc.getPrecision() == InferenceEngine::Precision::FP32) { - _normalizePreprocMap[name].NormalizeImage(outDims, - reinterpret_cast(inter_data_ptr), - TensorDesc::getLayoutByDims(in->get_shape())); - } else { - OPENVINO_THROW("Mean image of type ", ext_tensor_desc.getPrecision().name(), " is unsupported"); - } + // todo: make sure 'name' exists in this map... + if (_normalizePreprocMap.find(name) != _normalizePreprocMap.end()) { + if (ext_tensor_desc.getPrecision() == InferenceEngine::Precision::FP32) { + _normalizePreprocMap[name].NormalizeImage(outDims, + reinterpret_cast(inter_data_ptr), + TensorDesc::getLayoutByDims(in->get_shape())); + } else { + OPENVINO_THROW("Mean image of type ", ext_tensor_desc.getPrecision().name(), " is unsupported"); } - } else { - OPENVINO_THROW("Input blob for infer '", name, "' doesn't correspond to input in network"); } + } else { + OPENVINO_THROW("Input blob for infer '", name, "' doesn't correspond to input in network"); + } } void Graph::PullOutputData(std::unordered_map>& out) { @@ -1029,7 +991,7 @@ void Graph::PullOutputData(std::unordered_map>& std::cout << "pull_output: " << srcPrec << " to " << dstPrec << ", same_ptr "<< (ext_blob_ptr == intr_blob_ptr) << std::endl; std::cout << "output data: " << std::endl; float* p = static_cast(intr_blob_ptr); - for (size_t i = 0; i < ext_blob->get_size(); i++) { + for (size_t i = 0; i < ext_blob->get_size() && i < 10; i++) { std::cout << " " << p[i]; } std::cout << std::endl;