Skip to content

Commit

Permalink
dedicate load store emitters runtime info for segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhu-wang committed Oct 11, 2023
1 parent 1e8e6ff commit abc6c81
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
38 changes: 38 additions & 0 deletions src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ size_t jit_load_emitter::aux_gprs_count() const {
}

void jit_load_emitter::emit_impl(const std::vector<size_t> &in_idxs, const std::vector<size_t> &out_idxs) const {
// save runtime debug info
h->push(h->r15);
Xbyak::Label label_set_current;
h->mov(h->r15, reinterpret_cast<size_t>(&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<size_t>(&current_address));
h->mov(h->qword[h->r15], Xbyak::Reg64(in_idxs[0]));

// iteration++
h->mov(h->r15, reinterpret_cast<size_t>(&iteration));
h->add(h->qword[h->r15], 0x01);
}
h->pop(h->r15);

const int offset = in_idxs.size() == 2 ? in_idxs[1] : 0;
if (host_isa_ == cpu::x64::sse41) {
emit_isa<cpu::x64::sse41>(Reg64(in_idxs[0]), static_cast<int>(out_idxs[0]), offset);
Expand Down Expand Up @@ -601,6 +619,7 @@ void jit_load_emitter::register_table_entries() {

void jit_load_emitter::print_debug_info() const {
std::cerr << "ERROR is from jit_load_emitter." << "\n";
std::cerr << "where start_address:" << start_address << " current_address:" << current_address << " iteration:" << iteration << "\n";
std::cerr << "Emitter name:" << name_ << "\n";
std::cerr << "load_num_:" << load_num_ << "\n";
std::cerr << "src_prc_:" << src_prc_ << "\n";
Expand Down Expand Up @@ -667,6 +686,24 @@ void jit_store_emitter::emit_data() const {
}

void jit_store_emitter::emit_impl(const std::vector<size_t> &in_idxs, const std::vector<size_t> &out_idxs) const {
// save runtime debug info
h->push(h->r15);
Xbyak::Label label_set_current;
h->mov(h->r15, reinterpret_cast<size_t>(&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<size_t>(&current_address));
h->mov(h->qword[h->r15], Xbyak::Reg64(out_idxs[0]));

// iteration++
h->mov(h->r15, reinterpret_cast<size_t>(&iteration));
h->add(h->qword[h->r15], 0x01);
}
h->pop(h->r15);

const int offset = in_idxs.size() == 2 ? in_idxs[1] : 0;
if (host_isa_ == cpu::x64::sse41) {
emit_isa<cpu::x64::sse41>(static_cast<int>(in_idxs[0]), Reg64(out_idxs[0]), offset);
Expand Down Expand Up @@ -1273,6 +1310,7 @@ void jit_store_emitter::register_table_entries() {

void jit_store_emitter::print_debug_info() const {
std::cerr << "Segfault happens in jit_store_emitter." << "\n";
std::cerr << "where start_address:" << start_address << " current_address:" << current_address << " iteration:" << iteration << "\n";
std::cerr << "Emitter name:" << name_ << "\n";
std::cerr << "store_num_:" << store_num_ << "\n";
std::cerr << "src_prc_:" << src_prc_ << "\n";
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/intel_cpu/src/emitters/x64/jit_load_store_emitters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class jit_load_emitter : public jit_emitter {
InferenceEngine::Precision dst_prc_;
bool is_fill_;
std::string fill_value_;

size_t start_address = 0;
size_t current_address = 0;
size_t iteration = 0;
std::shared_ptr<snippets::op::Store> m_load_node;
};

class jit_store_emitter : public jit_emitter {
Expand Down Expand Up @@ -174,6 +179,11 @@ class jit_store_emitter : public jit_emitter {
mutable bool data_reg_updated = false;
mutable int data_idx = 0;
mutable int aux_src_idx = 0;

size_t start_address = 0;
size_t current_address = 0;
size_t iteration = 0;
std::shared_ptr<snippets::op::Store> m_store_node;
};

} // namespace intel_cpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ class ScalarEmitter : public jit_emitter {
/// Memory emitters:
///
/// *Note*: post increment is embedded into Load/Store operation which means that
/// it's illigal to load/store to the same address multiple times
/// it's illegal to load/store to the same address multiple times
/// Typical application can be if Load and BroadcastLoad are performed from the same pointer.
/// If Load goes before BroadcastLoad topologicaly the resilt will be incorrect
/// If Load goes before BroadcastLoad topologicaly the result will be incorrect
/// For scalar loads we can use different loops. Tiling indeed can be arbitrary and post increment should be somehow coded into ISA.
/// Blocked parameter to tell if input is actually blocked. Broadcast means broadcast by W in other cases no need to substitute load.
class MemoryEmitter : public jit_emitter {
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/intel_cpu/src/nodes/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,15 @@ void Snippet::SnippetJitExecutor::update_ptrs(jit_snippets_call_args& call_args,
void Snippet::SnippetJitExecutor::schedule_6d(const std::vector<MemoryPtr>& inMemPtrs, const std::vector<MemoryPtr>& outMemPtrs) {
const auto& dom = parallel_exec_domain;
// < N, C, H, W > < 1, 1, N, C*H*W>
// parallel_for5d(dom[0], dom[1], dom[2], dom[3], dom[4],
parallel_for5d(1, 1, 1, 1, 1,
parallel_for5d(dom[0], dom[1], dom[2], dom[3], dom[4],
[&](int64_t d0, int64_t d1, int64_t d2, int64_t d3, int64_t d4) {
int64_t indexes[] = {d0, d1, d2, d3, d4};
jit_snippets_call_args call_args;
update_ptrs(call_args, inMemPtrs, outMemPtrs);
#ifndef _WIN32
#ifdef __linux__
__sighandler_t signal_handler = [](int signal) {
std::cerr << "Segfault was caught by the signal handler.\n";
ov::intel_cpu::g_debug_err_handler->print_debug_info();
OPENVINO_THROW("Segfault was caught by the signal handler");
};
struct sigaction new_handler{};
new_handler.sa_handler = signal_handler;
Expand All @@ -501,10 +500,10 @@ void Snippet::SnippetJitExecutor::schedule_nt(const std::vector<MemoryPtr>& inMe
indexes[j] = tmp % work_size[j];
tmp /= work_size[j];
}
#ifndef _WIN32
#ifdef __linux__
__sighandler_t signal_handler = [](int signal) {
std::cerr << "Segfault was caught by the signal handler.\n";
ov::intel_cpu::g_debug_err_handler->print_debug_info();
OPENVINO_THROW("Segfault was caught by the signal handler");
};
struct sigaction new_handler{};
new_handler.sa_handler = signal_handler;
Expand Down

0 comments on commit abc6c81

Please sign in to comment.