Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aobolensk committed Jan 13, 2025
1 parent ac0ed82 commit 1962d8c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 98 deletions.
13 changes: 2 additions & 11 deletions src/common/snippets/docs/debug_capabilities/parameters_dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ Snippet parameters can be captured during the pass flow, which can be useful for

To turn on snippet parameters dump feature, the following environment variable should be used:
```sh
OV_SNIPPETS_DUMP_PARAMS=<space_separated_options> binary ...
OV_SNIPPETS_DUMP_BRGEMM_PARAMS=<path_to_csv_dump_file> binary ...
```

Examples:
```sh
OV_SNIPPETS_DUMP_PARAMS="snippets=brgemm dir=dump" binary ...
OV_SNIPPETS_DUMP_BRGEMM_PARAMS="brgemm.csv" binary ...
```

Option names are case insensitive, the following options are supported:
- `snippets` : Dump parameters for selected snippets.
Supported values: `brgemm`
It support multiple comma separated pass names. The names are case insensitive.
This option is a must have, should not be omitted.
- `dir` : Path to dumped LIR files.
If omitted, it defaults to `snippets_params_dump` directory.
If specified path doesn't exist, the directory will be created automatically.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#pragma once

#include <fstream>

#include "snippets/itt.hpp"
#include "snippets/lowered/loop_manager.hpp"
#include "snippets/lowered/specific_loop_iter_handlers.hpp"
#include "snippets/lowered/pass/iter_handler.hpp"
#include "snippets/op/brgemm.hpp"
#include "snippets/utils/params_dumper.hpp"

namespace ov {
namespace snippets {
Expand Down Expand Up @@ -113,15 +114,30 @@ class BrgemmBlocking : public snippets::lowered::pass::RangedPass, public Brgemm
size_t m_block, n_block, k_block;
std::tie(m_block, n_block, k_block) = get_blocking_params(brgemm_expr);
modified = mark_blocking_loops(linear_ir, expr_it, m_block, n_block, k_block);
SNIPPETS_DEBUG_PARAMS_DUMP(brgemm_expr, this);
#ifdef SNIPPETS_DEBUG_CAPS
dump_params_to_csv(brgemm_expr, linear_ir);
#endif // SNIPPETS_DEBUG_CAPS
}
return modified;
}

#ifdef SNIPPETS_DEBUG_CAPS
std::string params_to_csv(const ov::snippets::lowered::ExpressionPtr& brgemm_expr) {
void dump_params_to_csv(const ov::snippets::lowered::ExpressionPtr& brgemm_expr,
const snippets::lowered::LinearIR& linear_ir) {
auto debug_config = linear_ir.get_config().debug_config;
const auto brgemm = ov::as_type_ptr<BRGEMM_TYPE>(brgemm_expr->get_node());
OPENVINO_ASSERT(brgemm, "Brgemm is nullptr!");
auto readEnv = [](const char* envVar) {
const char* env = std::getenv(envVar);
if (env && *env)
return env;
return (const char*)nullptr;
};
const char* dumpParamPath = readEnv("OV_SNIPPETS_DUMP_BRGEMM_PARAMS");
if (!dumpParamPath) {
return;
}
std::string csv_path = dumpParamPath;
std::stringstream ss;
for (size_t i = 0; i < brgemm->get_input_size(); ++i) {
ss << brgemm->get_input_element_type(i);
Expand All @@ -139,28 +155,20 @@ class BrgemmBlocking : public snippets::lowered::pass::RangedPass, public Brgemm
ss << ",";
for (const auto& input : brgemm->inputs()) {
const auto& shape = input.get_partial_shape();
if (shape.is_dynamic()) {
ss << "?";
} else {
for (const auto& dim : shape) {
ss << static_cast<int64_t>(dim.get_length()) << " ";
}
ss.seekp(-1, ss.cur);
for (const auto& dim : shape) {
ss << dim << " ";
}
ss.seekp(-1, ss.cur);
ss << ";";
}
ss.seekp(-1, ss.cur);
ss << ",";
for (const auto& output : brgemm->outputs()) {
const auto& shape = output.get_partial_shape();
if (shape.is_dynamic()) {
ss << "?";
} else {
for (const auto& dim : shape) {
ss << static_cast<int64_t>(dim.get_length()) << " ";
}
ss.seekp(-1, ss.cur);
for (const auto& dim : shape) {
ss << dim << " ";
}
ss.seekp(-1, ss.cur);
ss << ";";
}
ss.seekp(-1, ss.cur);
Expand All @@ -171,8 +179,12 @@ class BrgemmBlocking : public snippets::lowered::pass::RangedPass, public Brgemm
int64_t m_block, n_block, k_block;
std::tie(m_block, n_block, k_block) = get_blocking_params(brgemm_expr);
ss << m_block << "," << n_block << "," << k_block;
std::string params = ss.str();
return params;
ss << '\n';
std::ofstream csv_file(csv_path, std::ios_base::app);
if (csv_file.seekp(0, std::ios_base::end).tellp() == 0) {
csv_file << "name,in_type,out_type,in_shapes,out_shapes,M,N,K,m_block,n_block,k_block\n";
}
csv_file << ss.str();
}
#endif // SNIPPETS_DEBUG_CAPS
};
Expand Down
65 changes: 0 additions & 65 deletions src/common/snippets/include/snippets/utils/params_dumper.hpp

This file was deleted.

3 changes: 0 additions & 3 deletions src/common/snippets/src/utils/debug_caps_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ void DebugCapsConfig::readProperties() {
dumpLIR.parseAndSet(envVarValue);
OPENVINO_ASSERT(!dumpLIR.passes.empty(), "Passes option in OV_SNIPPETS_DUMP_LIR must be provided.");
}
if ((envVarValue = readEnv("OV_SNIPPETS_DUMP_PARAMS"))) {
dumpParams.parseAndSet(envVarValue);
}
}

void DebugCapsConfig::PropertyGroup::parseAndSet(const std::string& str) {
Expand Down

0 comments on commit 1962d8c

Please sign in to comment.