Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / program_dump_graph.cpp
index 7e4c739..b82dd0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-// Copyright (c) 2016 Intel Corporation
+// Copyright (c) 2016-2018 Intel Corporation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 
 #include "program_dump_graph.h"
 #include "to_string_utils.h"
-#include "xml_object.h"
+#include "data_inst.h"
+#include "condition_inst.h"
+
+#include "gpu/ocl_toolkit.h"
+
+#include "to_string_utils.h"
+
 #include <algorithm>
 #include <vector>
 
@@ -152,12 +158,12 @@ namespace cldnn
         graph.close();
     }
 
-    std::string get_node_id(program_node* ptr)
+    std::string get_node_id(const program_node* ptr)
     {
         return "node_" + std::to_string(reinterpret_cast<uintptr_t>(ptr));
     }
 
-    void dump_full_node(std::ofstream& out, program_node* node)
+    void dump_full_node(std::ofstream& out, const program_node* node)
     {
         out << node->type()->to_string(*node);
     }
@@ -193,31 +199,7 @@ namespace cldnn
     {
         const auto extr_oformat = [](program_node* ptr)
         {
-            std::string out = "";
-            switch (ptr->get_output_layout().format)
-            {
-            case format::yxfb: out = "yxfb"; break;
-            case format::byxf: out = "byxf"; break;
-            case format::bfyx: out = "bfyx"; break;
-            case format::fyxb: out = "fyxb"; break;
-            case format::os_iyx_osv16: out = "os_iyx_osv16"; break;
-            case format::bs_xs_xsv8_bsv8: out = "bs_xs_xsv8_bsv8"; break;
-            case format::bs_xs_xsv8_bsv16: out = "bs_xs_xsv8_bsv16"; break;
-            case format::bs_x_bsv16: out = "bs_x_bsv16"; break;
-            case format::bf8_xy16: out = "bf8_xy16"; break;
-            case format::image_2d_weights_c1_b_fyx: out = "image_2d_weights_c1_b_fyx"; break;
-            case format::image_2d_weights_c4_fyx_b: out = "image_2d_weights_c4_fyx_b"; break;
-            case format::image_2d_weights_winograd_6x3_s1_fbxyb: out = "image_2d_weights_winograd_6x3_s1_fbxyb"; break;
-            case format::image_2d_weights_winograd_6x3_s1_xfbyb: out = "image_2d_weights_winograd_6x3_s1_xfbyb"; break;
-            case format::os_is_yx_isa8_osv8_isv4: out = "os_is_yx_isa8_osv8_isv4"; break;
-            case format::is_o_yx_isv32: out = "is_o_yx_isv32"; break;
-            case format::byxf_af32: out = "byxf_af32"; break;
-            case format::fs_bs_yx_bsv4_fsv32: out = "fs_bs_yx_bsv4_fsv32"; break;
-            case format::any: out = "any"; break;
-            default:
-                out = "unk format";
-                break;
-            }
+            std::string out = fmt_to_str(ptr->get_output_layout().format);
 
             if (!ptr->is_valid_output_layout())
                 out += " (invalid)";
@@ -225,22 +207,6 @@ namespace cldnn
             return out;
         };
 
-        const auto extr_data_type = [](program_node* ptr)
-        {
-            std::string out = "";
-            switch (ptr->get_output_layout().data_type)
-            {
-            case data_types::i8: out = "i8"; break;
-            case data_types::u8: out = "u8"; break;
-            case data_types::f16: out = "f16"; break;
-            case data_types::f32: out = "f32"; break;
-            default:
-                out = "unknown data_type";
-                break;
-            }
-            return out;
-        };
-
         const auto dump_mem_info = [](program_node* ptr)
         {
             std::string out = "size_info: ";
@@ -262,7 +228,7 @@ namespace cldnn
         };
 
         graph << "digraph cldnn_program {\n";
-        for (auto& node : program.get_nodes())
+        for (auto& node : program.get_processing_order())
         {
             if (filter && !filter(*node))
             {
@@ -272,23 +238,36 @@ namespace cldnn
                 #pragma clang diagnostic push
                 #pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
             #endif
-            std::string node_type = get_extr_type(typeid(*node).name());
-            graph << "    " << get_node_id(node.get()) << "[label=\"" << node->id() << ":\n" << node_type << "\n out format: " + extr_oformat(node.get())
-                << "\n out data_type: " + extr_data_type(node.get())
-                << "\\nprocessing number: " << node->get_processing_num() << "\\n color:" << (node->is_reusing_memory() ? std::to_string(node->get_reused_memory_color()) : "none")
+            auto& node_type = typeid(*node);
+            std::string node_type_name = get_extr_type(node_type.name());
+            graph << "    " << get_node_id(node) << "[label=\"" << node->id() << ":\n" << node_type_name << "\n out format: " + extr_oformat(node)
+                << "\n out data_type: " + dt_to_str(node->get_output_layout().data_type)
+                << "\\nprocessing number: " << program.get_processing_order().get_processing_number(node) << "\\n color:" << (node->is_reusing_memory() ? std::to_string(node->get_reused_memory_color()) : "none")
                 << (node->can_be_optimized() ? "\\n optimized out" : "");
-            if (node_type != "struct cldnn::data" && node_type != "struct cldnn::input_layout" && !node->can_be_optimized())
+
+            if (node_type_name != "struct cldnn::data" && node_type_name != "struct cldnn::input_layout" && !node->can_be_optimized())
+            {
                 graph << "\\n Selected kernel: " << (node->get_selected_impl() == nullptr ? "none" : node->get_selected_impl().get()->get_kernel_name()
-                    + "\n" + dump_mem_info(node.get()));
+                    + "\n" + dump_mem_info(node));
+            }
             graph << "\"";
             #ifdef __clang__
                 #pragma clang diagnostic pop
             #endif
 
+            if (node->is_type<condition>())
+            {
+                graph << ", shape=diamond";
+            }
             if (node->is_type<data>() || node->is_constant())
+            {
                 graph << ", shape=box";
+            }
             if (node->is_type<internal_primitive>())
+            {
                 graph << ", color=blue";
+            }
+
             if (node->is_reusing_memory())
             {
                 graph << ", fillcolor=\"" << colors[node->get_reused_memory_color() % colors.size()] << "\" ";
@@ -303,9 +282,9 @@ namespace cldnn
                     continue;
                 }
                 bool doubled = true;
-                if (std::find(user->get_dependencies().begin(), user->get_dependencies().end(), node.get()) == user->get_dependencies().end())
+                if (std::find(user->get_dependencies().begin(), user->get_dependencies().end(), node) == user->get_dependencies().end())
                     doubled = false;
-                graph << "    " << get_node_id(node.get()) << " -> " << get_node_id(user);
+                graph << "    " << get_node_id(node) << " -> " << get_node_id(user);
 
                 bool data_flow = node->is_in_data_flow() && user->is_in_data_flow();
                 if (data_flow)
@@ -330,12 +309,12 @@ namespace cldnn
                     continue;
                 }
 
-                if (std::find(dep->get_users().begin(), dep->get_users().end(), node.get()) != dep->get_users().end())
+                if (std::find(dep->get_users().begin(), dep->get_users().end(), node) != dep->get_users().end())
                 {
                     continue;
                 }
 
-                graph << "   " << get_node_id(node.get()) << " -> " << get_node_id(dep) << " [style=dashed, label=\"dep\", constraint=false];\n";
+                graph << "   " << get_node_id(node) << " -> " << get_node_id(dep) << " [style=dashed, label=\"dep\", constraint=false];\n";
             }
         }
         graph << "}\n";
@@ -361,101 +340,16 @@ namespace cldnn
 
     void dump_graph_info(std::ofstream& graph, const program_impl& program, std::function<bool(program_node const&)> const& filter)
     {
-        for (auto& node : program.get_nodes())
+        for (auto& node : program.get_processing_order())
         {
             if (filter && !filter(*node))
                 continue;
 
-            dump_full_node(graph, node.get());
+            dump_full_node(graph, node);
             graph << std::endl << std::endl;
         }
         close_stream(graph);
     }
-
-    //Function used by serialization. Not working yet, in progress.
-    void dump_to_xml(std::ofstream& graph, const program_impl& program, std::function<bool(program_node const&)> const& filter, std::vector<unsigned long long>& offsets, std::vector<std::string>& data_names)
-    {
-        xml_composite data_container, node_container;
-        auto node_number = 1;
-        auto kernels_number = 1;
-        auto postion = 0u;
-        auto offset = 0ull;
-        auto size = offsets.at(0);
-        for (auto& node : program.get_nodes())
-        {
-            if (filter && !filter(*node))
-                continue;
-
-            std::string package_name = "node_" + std::to_string(node_number);
-            auto node_info = node.get()->desc_to_xml();
-            auto id = node->id();
-            for (auto p = postion; p < (unsigned int)data_names.size(); p++)
-            {
-                    if (p != 0)
-                    {
-                        offset = offsets.at(p - 1);
-                        size = offsets.at(p) - offsets.at(p - 1);
-                    }
-                    if (data_names.at(p).find("kernels") != std::string::npos)
-                    {
-                        node_info.reset(new xml_composite());
-                        node_info->add("id", data_names.at(p));
-                        id = "kernels";
-                        package_name = "kernels_" + std::to_string(kernels_number);
-
-                        postion++;
-                        kernels_number++;
-                        node_number--;
-                    }
-                    if (data_names.at(p).find(id) != std::string::npos)
-                    {
-                        node_info->add("data_offset", std::to_string(offset));
-                        node_info->add("data_size", std::to_string(size));
-                        node_number++;
-                        break;
-                    }
-            }
-            node_container.add(package_name, node_info.get()); 
-        }
-        data_container.add("data", node_container);
-        data_container.dump(graph);
-        close_stream(graph);
-    }
-
-    //Function used by serialization. Not working yet, in progress.
-    void dump_kernels(kernels_binaries_container program_binaries, std::vector<unsigned long long>& offsets, std::vector<std::string>& data_names, std::ofstream& file_stream)
-    {
-        auto offset_temp = 0ull;
-        for (unsigned int i = 0; i < (unsigned int)program_binaries.size(); i++)
-        {
-            for (unsigned int j = 0; j < (unsigned int)program_binaries.at(i).size(); j++)
-            {
-                for (unsigned int k = 0; k < (unsigned int)program_binaries.at(i).at(j).size(); k++)
-                {
-                    char* p = (char*)&program_binaries.at(i).at(j).at(k);
-                    file_stream.write(p, sizeof(char));
-                    offset_temp += sizeof(char);
-                }
-            }
-            offsets.push_back(offset_temp);
-            std::string offset_name = "kernels_part_" + std::to_string(i+1);
-            data_names.push_back(offset_name);
-        }
-    }
-
-    //Function used by serialization. Not working yet, in progress.
-    void dump_data(memory_impl& mem, std::ofstream& stream, unsigned long long& total_offset, unsigned long long type)
-    {
-        auto offset = 0ull;
-        char * ptr = (char*)mem.lock();
-        for (unsigned int x = 0; x < (unsigned int)mem.get_layout().count(); x++)
-        {
-            stream.write(ptr + offset, type);
-            offset += type;
-        }
-        mem.unlock();
-        total_offset += offset;
-    }
 }
 
  
\ No newline at end of file