Skip to content

Commit

Permalink
debug caps
Browse files Browse the repository at this point in the history
  • Loading branch information
aobolensk committed Jan 20, 2025
1 parent 98b8e04 commit 7eef6d6
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 93 deletions.
3 changes: 2 additions & 1 deletion src/common/snippets/src/utils/debug_caps_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace snippets {
void DebugCapsConfig::readProperties() {
auto readEnv = [](const char* envVar) {
const char* env = std::getenv(envVar);
if (env && *env)
if (env && *env) {
return env;
}

return static_cast<const char*>(nullptr);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ template void RegPrinter::print<unsigned char, Reg8>(jit_generator& h, Reg8 reg,
template <typename T>
void RegPrinter::print_reg_prc(const char* name, const char* ori_name, T* ptr) {
std::stringstream ss;
if (name)
if (name) {
ss << name << " | ";
}
ss << ori_name << ": ";
if (std::is_floating_point<T>::value) {
ss << *ptr;
Expand All @@ -52,8 +53,9 @@ void RegPrinter::print_reg_prc(const char* name, const char* ori_name, T* ptr) {
template <typename PRC_T, size_t vlen>
void RegPrinter::print_vmm_prc(const char* name, const char* ori_name, PRC_T* ptr) {
std::stringstream ss;
if (name)
if (name) {
ss << name << " | ";
}
ss << ori_name << ": {" << ptr[0];
for (size_t i = 1; i < vlen / sizeof(float); i++) {
ss << ", " << ptr[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ std::string CPURuntimeConfig::to_string() const {
const auto& loop = loop_args[i];
out << "\t[" << i << "] WA: " << loop.m_work_amount << "\n";
out << "\tPointer Increments: ";
for (int64_t j = 0; j < loop.m_num_data_ptrs; ++j)
for (int64_t j = 0; j < loop.m_num_data_ptrs; ++j) {
out << loop.m_ptr_increments[j] << " ";
}
out << "\n";
out << "\tFinalization offsets: ";
for (int64_t j = 0; j < loop.m_num_data_ptrs; ++j)
for (int64_t j = 0; j < loop.m_num_data_ptrs; ++j) {
out << loop.m_finalization_offsets[j] << " ";
}
out << "\n";
}
return out.str();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace intel_cpu {
void SnippetsDebugCapsConfig::readProperties() {
auto readEnv = [](const char* envVar) {
const char* env = std::getenv(envVar);
if (env && *env)
if (env && *env) {
return env;
}

return static_cast<const char*>(nullptr);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ void jit_debug_emitter::emit_code(const std::vector<size_t>& in_idxs,
const std::vector<size_t>& out_idxs,
const std::vector<size_t>& pool_vec_idxs,
const std::vector<size_t>& pool_gpr_idxs) const {
if (m_decorator_emit_loc == EmissionLocation::preamble || m_decorator_emit_loc == EmissionLocation::both)
if (m_decorator_emit_loc == EmissionLocation::preamble || m_decorator_emit_loc == EmissionLocation::both) {
m_decorator_emitter->emit_code(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs);
}

m_target_emitter->emit_code(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs);

if (m_decorator_emit_loc == EmissionLocation::postamble || m_decorator_emit_loc == EmissionLocation::both)
if (m_decorator_emit_loc == EmissionLocation::postamble || m_decorator_emit_loc == EmissionLocation::both) {
m_decorator_emitter->emit_code(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs);
}
}

} // namespace intel_cpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ void brgemm_ref_kernel::operator()(dnnl::impl::cpu::x64::brgemm_kernel_params_t*
for (dnnl_dim_t m = 0; m < m_config.get_M(); m++) {
for (dnnl_dim_t n = 0; n < m_config.get_N(); n++, B++) {
C[n] = 0;
for (dnnl_dim_t k = 0; k < m_config.get_K(); k++)
for (dnnl_dim_t k = 0; k < m_config.get_K(); k++) {
C[n] += A[k] * B[k * m_config.get_LDB()];
}
}
B -= m_config.get_N();
A += m_config.get_LDA();
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/intel_cpu/src/emitters/snippets/x64/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ static std::string init_info_jit_store_memory_emitter(const jit_store_memory_emi
std::string init_info_jit_brgemm_emitter(const jit_brgemm_emitter* emitter) {
std::stringstream ss;
ss << "Emitter_type_name:jit_brgemm_emitter";
if (const auto& common = std::dynamic_pointer_cast<BrgemmKernelExecutor>(emitter->m_kernel_executor))
if (const auto& common = std::dynamic_pointer_cast<BrgemmKernelExecutor>(emitter->m_kernel_executor)) {
ss << common->to_string();
if (const auto& amx = std::dynamic_pointer_cast<BrgemmAMXKernelExecutor>(emitter->m_kernel_executor))
}
if (const auto& amx = std::dynamic_pointer_cast<BrgemmAMXKernelExecutor>(emitter->m_kernel_executor)) {
ss << amx->to_string();
}
ss << " m_memory_offset:" << vector_to_string(emitter->m_memory_offsets)
<< " m_buffer_ids:" << vector_to_string(emitter->m_buffer_ids);

Expand All @@ -110,8 +112,9 @@ std::string init_info_jit_kernel_static_emitter(const jit_kernel_static_emitter*
<< " master_shape:" << vector_to_string(emitter->master_shape) << " num_inputs:" << emitter->num_inputs
<< " num_outputs:" << emitter->num_outputs << " num_unique_buffers:" << emitter->num_unique_buffers
<< " data_ptr_regs_idx:" << vector_to_string(emitter->data_ptr_regs_idx);
for (size_t i = 0; i < emitter->data_offsets.size(); ++i)
for (size_t i = 0; i < emitter->data_offsets.size(); ++i) {
ss << " data_offsets for " << i << " is:" << vector_to_string(emitter->data_offsets[i]);
}
return ss.str();
}

Expand Down Expand Up @@ -146,8 +149,9 @@ static std::string init_info_jit_emitter_general(const jit_emitter* emitter) {
}

void jit_emitter_info_t::init(const jit_emitter* emitter) {
if (is_initialized_)
if (is_initialized_) {
return;
}
if (auto e_type = dynamic_cast<const jit_load_memory_emitter*>(emitter)) {
str_ = init_info_jit_load_memory_emitter(e_type);
} else if (auto e_type = dynamic_cast<const jit_load_broadcast_emitter*>(emitter)) {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/intel_cpu/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,8 +1904,9 @@ void Graph::EnforceInferencePrecision() {
continue;
}
#ifdef CPU_DEBUG_CAPS
if (!inferPrecDebug.enabled(NameFromType(node->getType()), node->getName(), node->getOriginalLayers()))
if (!inferPrecDebug.enabled(NameFromType(node->getType()), node->getName(), node->getOriginalLayers())) {
continue;
}
#endif

for (size_t i = 0; i < node->getOriginalInputsNumber(); i++) {
Expand Down
43 changes: 28 additions & 15 deletions src/plugins/intel_cpu/src/graph_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ std::shared_ptr<ov::Model> dump_graph_as_ie_ngraph_net(const Graph& graph) {
void serialize(const Graph& graph) {
const std::string& path = graph.getConfig().debugCaps.execGraphPath;

if (path.empty())
if (path.empty()) {
return;
}

if (path == "cout") {
serializeToCout(graph);
Expand All @@ -240,8 +241,9 @@ void serialize(const Graph& graph) {
}

void serializeToXML(const Graph& graph, const std::string& path) {
if (path.empty())
if (path.empty()) {
return;
}

std::string binPath;
ov::pass::Manager manager;
Expand Down Expand Up @@ -275,8 +277,9 @@ void summary_perf(const Graph& graph) {
}
const std::string& summaryPerf = graph.getConfig().debugCaps.summaryPerf;

if (summaryPerf.empty() || !std::stoi(summaryPerf))
if (summaryPerf.empty() || !std::stoi(summaryPerf)) {
return;
}

std::map<std::string, double> perf_by_type;
std::map<NodePtr, double> perf_by_node;
Expand All @@ -290,19 +293,22 @@ void summary_perf(const Graph& graph) {
total += node->PerfCounter().count() * avg;
total_avg += avg;

if (perf_by_type.count(type))
if (perf_by_type.count(type)) {
perf_by_type[type] += avg;
else
} else {
perf_by_type[type] = avg;
}

if (perf_by_node.count(node))
if (perf_by_node.count(node)) {
perf_by_node[node] += avg;
else
} else {
perf_by_node[node] = avg;
}
}

if (total_avg < 1)
if (total_avg < 1) {
return;
}

std::cout << "======= ENABLE_DEBUG_CAPS:OV_CPU_SUMMARY_PERF ======" << std::endl;
std::cout << "Summary of " << graph.GetName() << " @" << std::hash<uint64_t>{}(reinterpret_cast<uint64_t>(&graph))
Expand All @@ -313,17 +319,19 @@ void summary_perf(const Graph& graph) {
std::cout << " perf_by_type:" << std::endl;
std::vector<std::pair<std::string, double>> A;
A.reserve(perf_by_type.size());
for (auto& it : perf_by_type)
for (auto& it : perf_by_type) {
A.push_back(it);
}
sort(A.begin(), A.end(), [](std::pair<std::string, double>& a, std::pair<std::string, double>& b) {
return a.second > b.second;
});

for (auto& it : A) {
std::stringstream ss;
int percentage = static_cast<int>(it.second * 100 / total_avg);
if (percentage == 0)
if (percentage == 0) {
break;
}
ss << std::setw(10) << std::right << percentage << " % : " << std::setw(8) << std::right << it.second
<< "(us) " << it.first << std::endl;
std::cout << ss.str();
Expand All @@ -333,8 +341,9 @@ void summary_perf(const Graph& graph) {
std::cout << " perf_by_node:" << std::endl;
std::vector<std::pair<NodePtr, double>> A;
A.reserve(perf_by_node.size());
for (auto& it : perf_by_node)
for (auto& it : perf_by_node) {
A.push_back(it);
}
sort(A.begin(), A.end(), [](std::pair<NodePtr, double>& a, std::pair<NodePtr, double>& b) {
return a.second > b.second;
});
Expand All @@ -343,10 +352,12 @@ void summary_perf(const Graph& graph) {
std::stringstream ss;
auto percentage = it.second * 100 / total_avg;
auto node = it.first;
if (node->PerfCounter().count() == 0)
if (node->PerfCounter().count() == 0) {
continue;
if (node->PerfCounter().avg() < 1)
}
if (node->PerfCounter().avg() < 1) {
continue;
}
ss << std::setw(10) << std::right << std::fixed << std::setprecision(2) << percentage << " % "
<< std::setw(8) << std::right << node->PerfCounter().avg() << "(us)x" << node->PerfCounter().count()
<< " #" << node->getExecIndex() << " " << node->getName() << " "
Expand All @@ -371,8 +382,9 @@ void average_counters(const Graph& graph) {

const std::string& path = graph.getConfig().debugCaps.averageCountersPath;

if (path.empty())
if (path.empty()) {
return;
}

static int graphIndex = 0;
std::string fileName = path + "_" + std::to_string(graphIndex++) + ".csv";
Expand Down Expand Up @@ -404,8 +416,9 @@ void average_counters(const Graph& graph) {
};

for (auto& node : graph.GetNodes()) {
if (node->isConstant())
if (node->isConstant()) {
continue;
}

total += printAverageCounter(node);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/intel_cpu/src/nodes/executors/x64/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ void SubgraphExecutor::segfault_detector() {
if (enabled_segfault_detector) {
__sighandler_t signal_handler = [](int signal) {
std::lock_guard<std::mutex> guard(err_print_lock);
if (auto segfault_detector_emitter = ov::intel_cpu::g_custom_segfault_handler->local())
if (auto segfault_detector_emitter = ov::intel_cpu::g_custom_segfault_handler->local()) {
std::cout << segfault_detector_emitter->info() << std::endl;
}
auto tid = parallel_get_thread_num();
OPENVINO_THROW("Segfault was caught by the signal handler in subgraph node execution on thread " +
std::to_string(tid));
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/intel_cpu/src/onednn/iml_type_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ impl_desc_type parse_impl_name(std::string impl_desc_name) {
SEARCH_WORD(jit);
SEARCH_WORD(brgconv);
SEARCH_WORD(brgemm);
if ((res & impl_desc_type::brgemm) != impl_desc_type::brgemm)
if ((res & impl_desc_type::brgemm) != impl_desc_type::brgemm) {
SEARCH_WORD(gemm);
}
SEARCH_WORD(blas);
SEARCH_WORD(mlas);
SEARCH_WORD(sse42);
Expand All @@ -60,12 +61,14 @@ impl_desc_type parse_impl_name(std::string impl_desc_name) {
SEARCH_WORD(shl);
SEARCH_WORD(asimd);
if ((res & impl_desc_type::avx2) != impl_desc_type::avx2 &&
(res & impl_desc_type::avx512) != impl_desc_type::avx512)
(res & impl_desc_type::avx512) != impl_desc_type::avx512) {
SEARCH_WORD(avx);
}
if ((res & impl_desc_type::sse42) != impl_desc_type::sse42 && (res & impl_desc_type::avx) != impl_desc_type::avx &&
(res & impl_desc_type::avx2) != impl_desc_type::avx2 &&
(res & impl_desc_type::avx512) != impl_desc_type::avx512)
(res & impl_desc_type::avx512) != impl_desc_type::avx512) {
SEARCH_WORD(uni);
}

SEARCH_WORD_2(nchw, ref);
SEARCH_WORD_2(ncdhw, ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecis

ov::pass::Manager manager("Plugin:CPU");
manager.set_per_pass_validation(false);
if (useLpt)
if (useLpt) {
CPU_REGISTER_PASS_COMMON(manager, ov::pass::MarkDequantization, defaultPrecisions);
}

auto get_convert_precisions = [&]() {
precisions_map map = {{ov::element::i64, ov::element::i32},
Expand Down
Loading

0 comments on commit 7eef6d6

Please sign in to comment.