-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
175 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/common/snippets/include/snippets/lowered/pass/brgemm_debug_params.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright (C) 2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#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" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
/** | ||
* @interface BrgemmDebugParamsBase | ||
* @brief Base class for Brgemm debug parameters dump pass | ||
* @ingroup snippets | ||
*/ | ||
class BrgemmDebugParamsBase { | ||
public: | ||
static snippets::lowered::SpecificIterationHandlers get_default_blocking_loop_handlers(size_t work_amount, size_t block_size); | ||
|
||
protected: | ||
/** | ||
* @interface get_brgemm_dimensions | ||
* @brief Extract current dimensions M,N,K of `brgemm_expr` | ||
* @param brgemm_expr Brgemm expression | ||
* @return tuple in format (M, N, K) | ||
*/ | ||
static std::tuple<size_t, size_t, size_t> get_brgemm_dimensions(const ov::snippets::lowered::ExpressionPtr& brgemm_expr); | ||
}; | ||
|
||
/** | ||
* @interface BrgemmDebugParams | ||
* @brief Base class for brgemm blocking passes | ||
* @ingroup snippets | ||
*/ | ||
template <typename BRGEMM_TYPE, | ||
typename std::enable_if<std::is_base_of<ov::snippets::op::Brgemm, BRGEMM_TYPE>::value, bool>::type = true> | ||
class BrgemmDebugParams : public snippets::lowered::pass::RangedPass, public BrgemmDebugParamsBase { | ||
public: | ||
OPENVINO_RTTI("BrgemmDebugParams", "", RangedPass); | ||
|
||
bool run(snippets::lowered::LinearIR& linear_ir, | ||
snippets::lowered::LinearIR::constExprIt begin, | ||
snippets::lowered::LinearIR::constExprIt end) override final { // NOLINT | ||
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::BrgemmDebugParams") | ||
#ifdef SNIPPETS_DEBUG_CAPS | ||
for (auto expr_it = begin; expr_it != end; expr_it++) { | ||
const auto& brgemm_expr = *expr_it; | ||
const auto brgemm = ov::as_type_ptr<BRGEMM_TYPE>(brgemm_expr->get_node()); | ||
if (brgemm) { | ||
dump_params_to_csv(brgemm_expr, linear_ir); | ||
} | ||
} | ||
#endif // SNIPPETS_DEBUG_CAPS | ||
return false; | ||
} | ||
|
||
#ifdef SNIPPETS_DEBUG_CAPS | ||
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 csv_path = linear_ir.get_config().debug_config.dumpParams.csv_path; | ||
std::stringstream ss; | ||
ss << brgemm_expr->get_node()->get_friendly_name() << ","; | ||
for (size_t i = 0; i < brgemm->get_input_size(); ++i) { | ||
ss << brgemm->get_input_element_type(i); | ||
if (i != brgemm->get_input_size() - 1) { | ||
ss << ";"; | ||
} | ||
} | ||
ss << ","; | ||
for (size_t i = 0; i < brgemm->get_output_size(); ++i) { | ||
ss << brgemm->get_output_element_type(i); | ||
if (i != brgemm->get_output_size() - 1) { | ||
ss << ";"; | ||
} | ||
} | ||
ss << ","; | ||
for (const auto& input : brgemm->inputs()) { | ||
const auto& shape = input.get_partial_shape(); | ||
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(); | ||
for (const auto& dim : shape) { | ||
ss << dim << " "; | ||
} | ||
ss.seekp(-1, ss.cur); | ||
ss << ";"; | ||
} | ||
ss.seekp(-1, ss.cur); | ||
ss << ","; | ||
int64_t M, N, K; | ||
std::tie(M, N, K) = get_brgemm_dimensions(brgemm_expr); | ||
ss << M << "," << N << "," << K << ","; | ||
int64_t m_block = brgemm_expr->get_input_port_descriptor(0)->get_subtensor().front(); | ||
int64_t n_block = brgemm_expr->get_input_port_descriptor(1)->get_subtensor().back(); | ||
int64_t k_block = brgemm_expr->get_input_port_descriptor(0)->get_subtensor().back(); | ||
ss << m_block << "," << n_block << "," << k_block; | ||
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 | ||
}; | ||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
42 changes: 42 additions & 0 deletions
42
src/common/snippets/src/lowered/pass/brgemm_debug_params.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "snippets/lowered/pass/brgemm_debug_params.hpp" | ||
|
||
#include "snippets/itt.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
#include "snippets/lowered/pass/pass.hpp" | ||
#include "snippets/lowered/pass/iter_handler.hpp" | ||
#include "snippets/snippets_isa.hpp" | ||
#include "snippets/utils/utils.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
using namespace ov::snippets::utils; | ||
|
||
std::tuple<size_t, size_t, size_t> BrgemmDebugParamsBase::get_brgemm_dimensions(const ExpressionPtr& brgemm_expr) { | ||
OPENVINO_ASSERT(brgemm_expr, "Brgemm expression is nullptr!"); | ||
const auto& in_0_desc = brgemm_expr->get_input_port_descriptor(0); | ||
const auto& in_1_desc = brgemm_expr->get_input_port_descriptor(1); | ||
const auto& out_desc = brgemm_expr->get_output_port_descriptor(0); | ||
|
||
const auto& in_0_planar_dims = get_planar_vdims(in_0_desc->get_shape(), in_0_desc->get_layout()); | ||
const auto& in_1_planar_dims = get_planar_vdims(in_1_desc->get_shape(), in_1_desc->get_layout()); | ||
const auto& out_preordered_dims = get_preordered_vdims(out_desc->get_shape(), out_desc->get_layout()); | ||
|
||
const auto& m = *++out_preordered_dims.rbegin(); | ||
const auto& n = *out_preordered_dims.rbegin(); | ||
const auto& k0 = *in_0_planar_dims.rbegin(); | ||
const auto& k1 = *++in_1_planar_dims.rbegin(); | ||
size_t k = 0; | ||
OPENVINO_ASSERT(utils::merge_dynamic_dim(k, k0, k1), "Brgemm input descriptors have incompatible K dimension value."); | ||
return std::make_tuple(m, n, k); | ||
} | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters