In this chapter we will learn how to properly get profiling data and primitive_ids for networks built with optimized data. Comparing to chapter_5, this time topology will be built two times - with and without optimize_data build option. Intermediate primitives will not be set as outputs (user will not have access to intermediate layers data). This way all applicable optimizations such as in-place optimizations (crop, concatenation) or primitives fusing for relu, will be applied to the network built with optimize_data set to true. The difference in executed primitives will be shown for both cases.
Please take a look in the files: "convolution_kernel_tutorial.cpp" "convolution_kernel_tutorial.h" "convolution_tutorial.cl"
#include <../api/CPP/cldnn_defs.h>
#include <../api/CPP/engine.hpp>
#include <../api/CPP/input_layout.hpp>
#include <../api/CPP/memory.hpp>
#include <../api/CPP/data.hpp>
#include <../api/CPP/topology.hpp>
#include <../api/CPP/network.hpp>
#include <../api/CPP/activation.hpp>
#include <../api/CPP/crop.hpp>
#include <../api/CPP/upsampling.hpp>
#include <iostream>
#include <chrono>
#include "helper_functions.h"
void print_info(std::map<primitive_id, primitive_id>& all_primitives, std::map<primitive_id, event>& executed_primitives)
{
std::cout << std::endl << "Org_primitive_id, Primitive_id_after_optimization" << std::endl;
for (auto& p : all_primitives)
{
std::cout << p.first << ", " << p.second << std::endl;
}
std::vector<cldnn::instrumentation::profiling_info> profiling_table;
for (auto& p : executed_primitives)
{
profiling_table.push_back({ p.first, p.second.get_profiling_info() });
}
for (auto& p : profiling_table)
{
std::cout << p.name << ":" << std::endl;
for (auto& q : p.intervals)
{
std::cout << "\t" << q.name << ": " << std::chrono::duration_cast<std::chrono::duration<double, std::chrono::milliseconds::period>>(q.value->value()).count()
<< " milliseconds" << std::endl;
}
}
}
{
std::cout << std::endl << "-- Chapter 8 --" << std::endl;
set_values(input_prim, get_simple_data<float>(input_prim));
network_1.set_input_data("input", input_prim);
auto outputs_1 = network_1.execute();
auto executed_primitives_1 = network_1.get_executed_primitives();
auto all_primitives_1 = network_1.get_all_primitives();
std::cout << std::endl << "Primitives list and profiling info for network without optimize data build option." << std::endl;
print_info(all_primitives_1, executed_primitives_1);
network_2.set_input_data("input", input_prim);
auto outputs = network_2.execute();
auto executed_primitives_2 = network_2.get_executed_primitives();
auto all_primitives_2 = network_2.get_all_primitives();
std::cout << std::endl << "Primitives list and profiling info for network with optimize data build option." << std::endl;
print_info(all_primitives_2, executed_primitives_2);
}