diff --git a/src/common/snippets/include/snippets/lowered/linear_ir.hpp b/src/common/snippets/include/snippets/lowered/linear_ir.hpp index c0aa3dc00224f0..8ebc56c5d78eb6 100644 --- a/src/common/snippets/include/snippets/lowered/linear_ir.hpp +++ b/src/common/snippets/include/snippets/lowered/linear_ir.hpp @@ -29,7 +29,7 @@ class Config { // Minimal advised work amount that should be processed during one call of the executable produced by Subgraph::generate // Set by a backend, should be large enough to compensate for the kernel call overheads size_t m_min_kernel_work_amount = 256; - bool m_enable_segfault_detector = true; + bool m_enable_segfault_detector = false; }; /* The control flow of Snippets is built on Linear Intermediate Representation (Linear IR). diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index f1dc0beaf0b475..b4344c4876f925 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -12,6 +12,8 @@ #include "snippets/itt.hpp" +bool g_enable_snippets_err_detector = false; + namespace ov { namespace snippets { @@ -44,13 +46,15 @@ void Generator::generate(lowered::LinearIR& linear_ir, LoweringResult& result, c } OV_ITT_TASK_NEXT(GENERATE, "::GetSnippet") - // Note: some emitters use precompiled kernels. They need to be saved, so the kernels are accessible at runtime. if (linear_ir.get_config().m_enable_segfault_detector) { + // Need save emitters to print usefull info in runtime if segfault happens. for (const auto& expr : linear_ir) { const auto& emitter = expr->get_emitter(); result.m_saved_emitters.emplace_back(emitter); } + g_enable_snippets_err_detector = true; } else if (linear_ir.get_config().m_save_expressions) { + // Note: some emitters use precompiled kernels. They need to be saved, so the kernels are accessible at runtime. for (const auto& expr : linear_ir) { const auto& emitter = expr->get_emitter(); if (uses_precompiled_kernel(emitter)) diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_dnnl_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_dnnl_emitters.cpp index e8ad90a115451d..88579b63c0ae93 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_dnnl_emitters.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_dnnl_emitters.cpp @@ -54,6 +54,8 @@ size_t jit_dnnl_emitter::get_inputs_num() const { return 1; } void jit_dnnl_emitter::emit_code(const std::vector &in_vec_idxs, const std::vector &out_vec_idxs, const std::vector &pool_vec_idxs, const std::vector &pool_gpr_idxs) const { + if (g_enable_snippets_err_detector) + build_debug_info(); if (host_isa_ == cpu::x64::sse41) { if (out_vec_idxs[0] != in_vec_idxs[0]) h->uni_vmovups(Xmm(out_vec_idxs[0]), Xmm(in_vec_idxs[0])); diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp index 4b898c00a51d63..d5279e0cc81c0e 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp @@ -14,7 +14,7 @@ using namespace Xbyak; namespace ov { namespace intel_cpu { -std::shared_ptr> g_debug_err_handler = std::make_shared>(); +std::shared_ptr> g_snippets_err_handler = std::make_shared>(); size_t jit_emitter::get_max_vecs_count() const { return one_of(host_isa_, cpu::x64::avx512_core, cpu::x64::avx512_core) ? 32 : 16; @@ -211,7 +211,8 @@ void jit_emitter::emit_code(const std::vector &in_idxs, const std::vecto const std::vector &pool_vec_idxs, const std::vector &pool_gpr_idxs) const { emitter_preamble(in_idxs, out_idxs, pool_vec_idxs, pool_gpr_idxs); - build_debug_info(); + if (g_enable_snippets_err_detector) + build_debug_info(); emit_impl(in_idxs, out_idxs); @@ -232,7 +233,7 @@ void jit_emitter::build_debug_info() const { } void jit_emitter::set_local_handler(jit_emitter* emitter_address) { - g_debug_err_handler->local() = emitter_address; + g_snippets_err_handler->local() = emitter_address; } } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp index 23102cf2fd8ca8..d92af5542b7303 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp @@ -3,7 +3,6 @@ // #pragma once -#include #include #include @@ -15,13 +14,19 @@ #include +#ifndef _WIN32 +#include +#endif + using namespace ov::threading; +extern bool g_enable_snippets_err_detector; + namespace ov { namespace intel_cpu { class jit_emitter; -extern std::shared_ptr> g_debug_err_handler; +extern std::shared_ptr> g_snippets_err_handler; enum emitter_in_out_map { vec_to_vec, diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.cpp index 540f8c4a372278..7b5352cbd810d1 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.cpp @@ -97,23 +97,25 @@ size_t jit_load_emitter::aux_gprs_count() const { } void jit_load_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { - // save runtime debug info - h->push(h->r15); - Xbyak::Label label_set_current; - h->mov(h->r15, reinterpret_cast(&start_address)); - h->cmp(h->qword[h->r15], 0); - h->jne(label_set_current); - h->mov(h->qword[h->r15], Xbyak::Reg64(in_idxs[0])); - h->L(label_set_current); - { - h->mov(h->r15, reinterpret_cast(¤t_address)); + if (g_enable_snippets_err_detector) { + // save runtime debug info + h->push(h->r15); + Xbyak::Label label_set_current; + h->mov(h->r15, reinterpret_cast(&start_address)); + h->cmp(h->qword[h->r15], 0); + h->jne(label_set_current); h->mov(h->qword[h->r15], Xbyak::Reg64(in_idxs[0])); - - // iteration++ - h->mov(h->r15, reinterpret_cast(&iteration)); - h->add(h->qword[h->r15], 0x01); + h->L(label_set_current); + { + h->mov(h->r15, reinterpret_cast(¤t_address)); + h->mov(h->qword[h->r15], Xbyak::Reg64(in_idxs[0])); + + // iteration++ + h->mov(h->r15, reinterpret_cast(&iteration)); + h->add(h->qword[h->r15], 0x01); + } + h->pop(h->r15); } - h->pop(h->r15); const int offset = in_idxs.size() == 2 ? in_idxs[1] : 0; if (host_isa_ == cpu::x64::sse41) { @@ -686,23 +688,25 @@ void jit_store_emitter::emit_data() const { } void jit_store_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { - // save runtime debug info - h->push(h->r15); - Xbyak::Label label_set_current; - h->mov(h->r15, reinterpret_cast(&start_address)); - h->cmp(h->qword[h->r15], 0); - h->jne(label_set_current); - h->mov(h->qword[h->r15], Xbyak::Reg64(out_idxs[0])); - h->L(label_set_current); - { - h->mov(h->r15, reinterpret_cast(¤t_address)); + if (g_enable_snippets_err_detector) { + // save runtime debug info + h->push(h->r15); + Xbyak::Label label_set_current; + h->mov(h->r15, reinterpret_cast(&start_address)); + h->cmp(h->qword[h->r15], 0); + h->jne(label_set_current); h->mov(h->qword[h->r15], Xbyak::Reg64(out_idxs[0])); - - // iteration++ - h->mov(h->r15, reinterpret_cast(&iteration)); - h->add(h->qword[h->r15], 0x01); + h->L(label_set_current); + { + h->mov(h->r15, reinterpret_cast(¤t_address)); + h->mov(h->qword[h->r15], Xbyak::Reg64(out_idxs[0])); + + // iteration++ + h->mov(h->r15, reinterpret_cast(&iteration)); + h->add(h->qword[h->r15], 0x01); + } + h->pop(h->r15); } - h->pop(h->r15); const int offset = in_idxs.size() == 2 ? in_idxs[1] : 0; if (host_isa_ == cpu::x64::sse41) { diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.hpp index 86e27601ba1515..7ec4be58aca9ac 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.hpp @@ -105,7 +105,6 @@ class jit_load_emitter : public jit_emitter { size_t start_address = 0; size_t current_address = 0; size_t iteration = 0; - std::shared_ptr m_load_node; }; class jit_store_emitter : public jit_emitter { diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp index be2f4440a12f41..318be017d16444 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp @@ -12,7 +12,6 @@ #include "transformations/snippets/x64/op/brgemm_copy_b.hpp" #include "transformations/snippets/x64/op//brgemm_cpu.hpp" #include "snippets/op/rank_normalization.hpp" -// #include using namespace InferenceEngine; using namespace Xbyak; @@ -28,19 +27,6 @@ using ExpressionPtr = ov::snippets::lowered::ExpressionPtr; namespace { constexpr size_t gpr_size = 8; - -// std::string get_type_name(const jit_emitter* emitter) { -// std::string name = typeid(*emitter).name(); -// #ifndef _WIN32 -// int status; -// std::unique_ptr demangled_name( -// abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), -// std::free); -// name = demangled_name.get(); -// #endif -// return name; -// } - } // namespace inline static void transform_idxs_to_regs(const std::vector& idxs, std::vector& regs) { @@ -115,10 +101,7 @@ KernelEmitter::KernelEmitter(jit_generator* h, cpu_isa_t isa, const ExpressionPt : jit_container_emitter(h, isa, expr), reg_indexes_idx(abi_param1.getIdx()), reg_const_params_idx(abi_param2.getIdx()) { - // const auto kernel = ov::as_type_ptr(expr->get_node()); - m_kernel_node = ov::as_type_ptr(expr->get_node()); -// const auto kernel = ov::as_type_ptr(n); - const auto kernel = m_kernel_node; + const auto kernel = ov::as_type_ptr(expr->get_node()); if (!kernel) IE_THROW() << "KernelEmitter invoked with invalid op argument"; if (kernel->region.empty()) @@ -224,7 +207,8 @@ KernelEmitter::KernelEmitter(jit_generator* h, cpu_isa_t isa, const ExpressionPt void KernelEmitter::emit_code(const std::vector &in, const std::vector &out) const { validate_arguments(in, out); - build_debug_info(); + if (g_enable_snippets_err_detector) + build_debug_info(); emit_impl(in, out); } @@ -375,6 +359,8 @@ void LoopBeginEmitter::print_debug_info() const { void LoopBeginEmitter::emit_code(const std::vector &in, const std::vector &out) const { validate_arguments(in, out); + if (g_enable_snippets_err_detector) + build_debug_info(); emit_impl(in, out); } @@ -430,6 +416,8 @@ void LoopEndEmitter::print_debug_info() const { void LoopEndEmitter::emit_code(const std::vector &in, const std::vector &out) const { validate_arguments(in, out); + if (g_enable_snippets_err_detector) + build_debug_info(); emit_impl(in, out); } diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp index 721db5006a5df9..b12fa88a87273c 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.hpp @@ -111,7 +111,6 @@ class KernelEmitter : public jit_container_emitter { const size_t reg_indexes_idx; const size_t reg_const_params_idx; - std::shared_ptr m_kernel_node; }; class LoopBeginEmitter : public jit_emitter { diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp index 6f809be4f12ccb..e8bccb894f3573 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp +++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp @@ -501,14 +501,16 @@ void Snippet::SnippetJitExecutor::schedule_6d(const std::vector& inMe int64_t indexes[] = {d0, d1, d2, d3, d4}; jit_snippets_call_args call_args; update_ptrs(call_args, inMemPtrs, outMemPtrs); -#ifdef __linux__ - __sighandler_t signal_handler = [](int signal) { - ov::intel_cpu::g_debug_err_handler->local()->print_debug_info(); - OPENVINO_THROW("Segfault was caught by the signal handler"); - }; - struct sigaction new_handler{}; - new_handler.sa_handler = signal_handler; - sigaction(SIGSEGV, &new_handler, nullptr); +#ifndef _WIN32 + if (g_enable_snippets_err_detector) { + __sighandler_t signal_handler = [](int signal) { + ov::intel_cpu::g_snippets_err_handler->local()->print_debug_info(); + OPENVINO_THROW("Segfault was caught by the signal handler"); + }; + struct sigaction new_handler{}; + new_handler.sa_handler = signal_handler; + sigaction(SIGSEGV, &new_handler, nullptr); + } #endif callable(indexes, &call_args); }); @@ -530,14 +532,16 @@ void Snippet::SnippetJitExecutor::schedule_nt(const std::vector& inMe indexes[j] = static_cast(tmp % work_size[j]); tmp /= work_size[j]; } -#ifdef __linux__ - __sighandler_t signal_handler = [](int signal) { - ov::intel_cpu::g_debug_err_handler->local()->print_debug_info(); - OPENVINO_THROW("Segfault was caught by the signal handler"); - }; - struct sigaction new_handler{}; - new_handler.sa_handler = signal_handler; - sigaction(SIGSEGV, &new_handler, nullptr); +#ifndef _WIN32 + if (g_enable_snippets_err_detector) { + __sighandler_t signal_handler = [](int signal) { + ov::intel_cpu::g_snippets_err_handler->local()->print_debug_info(); + OPENVINO_THROW("Segfault was caught by the signal handler"); + }; + struct sigaction new_handler{}; + new_handler.sa_handler = signal_handler; + sigaction(SIGSEGV, &new_handler, nullptr); + } #endif schedule.get_callable()(indexes.data(), &call_args); }