Skip to content

Commit

Permalink
[TMP] MatMul experiments via benchmark_app
Browse files Browse the repository at this point in the history
  • Loading branch information
v-Golubev committed Sep 30, 2024
1 parent fd8aeff commit 7a51f3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 30 additions & 1 deletion samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// clang-format off
#include "openvino/openvino.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/pass/serialize.hpp"

#ifndef IN_OV_COMPONENT
Expand Down Expand Up @@ -406,6 +408,7 @@ int main(int argc, char* argv[]) {
// set to default value
device_config[ov::enable_profiling.name()] = FLAGS_pc;
}
device_config[ov::enable_profiling.name()] = true;
perf_counts = (device_config.at(ov::enable_profiling.name()).as<bool>()) ? true : perf_counts;

auto supported_properties = core.get_property(device, ov::supported_properties);
Expand Down Expand Up @@ -596,7 +599,21 @@ int main(int argc, char* argv[]) {
slog::info << "Loading model files" << slog::endl;

auto startTime = Time::now();
auto model = core.read_model(FLAGS_m);
auto model = []() {
const size_t batch = std::atoi(std::getenv("B"));
const size_t M = std::atoi(std::getenv("M"));
const size_t K = std::atoi(std::getenv("K"));
const size_t N = std::atoi(std::getenv("N"));

ov::Shape data_shape{1, batch, M, K};
auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, data_shape);
std::vector<float> weights_vals(K * N);
std::iota(weights_vals.begin(), weights_vals.end(), -1000);
auto weights = ov::op::v0::Constant::create(ov::element::f32, {K, N}, weights_vals);
auto matmul = std::make_shared<ov::op::v0::MatMul>(data, weights, false, false);
matmul->set_friendly_name("MatMul");
return std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{data});
}();
auto duration_ms = get_duration_ms_till_now(startTime);
slog::info << "Read model took " << double_to_string(duration_ms) << " ms" << slog::endl;
slog::info << "Original model I/O parameters:" << slog::endl;
Expand Down Expand Up @@ -1218,6 +1235,18 @@ int main(int argc, char* argv[]) {
slog::info << "OpenVINO Runtime configuration settings were dumped to " << FLAGS_dump_config << slog::endl;
}

const auto runtime_model = compiledModel.get_runtime_model();
for (const auto& op : runtime_model->get_ordered_ops()) {
if (op->get_friendly_name() == "MatMul") {
const auto& rt_info = op->get_rt_info();
auto exec_time = rt_info.at("execTimeMcs");
auto layer_type = rt_info.at("layerType");
auto primitive_type = rt_info.at("primitiveType");
std::cout << "execTimeMcs: " << exec_time.as<std::string>() << std::endl;
std::cout << "layerType: " << layer_type.as<std::string>() << std::endl;
std::cout << "primitiveType: " << primitive_type.as<std::string>() << std::endl;
}
}
if (!FLAGS_exec_graph_path.empty()) {
try {
ov::serialize(compiledModel.get_runtime_model(), FLAGS_exec_graph_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ std::tuple<size_t, size_t, size_t> BrgemmCPUBlocking::get_blocking_params(const
n_blk = get_full_dim_value();
k_blk = get_full_dim_value();
}
return std::make_tuple(m_blk, n_blk, k_blk);
const size_t M = std::atoi(std::getenv("M_b"));
const size_t K = std::atoi(std::getenv("K_b"));
const size_t N = std::atoi(std::getenv("N_b"));
return std::make_tuple(M, N, K);
}

SpecificIterationHandlers BrgemmCPUBlocking::get_k_loop_handlers(size_t work_amount, size_t block_size) const {
Expand Down

0 comments on commit 7a51f3c

Please sign in to comment.