]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - viewer/tidl_viewer.cpp
1d72f8acdd53cb11dc29cad2874e7d0a503ec571
[tidl/tidl-api.git] / viewer / tidl_viewer.cpp
1 /******************************************************************************
2  * Copyright (c) 2017-18, Texas Instruments Incorporated - http://www.ti.com/
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *      * Redistributions of source code must retain the above copyright
8  *        notice, this list of conditions and the following disclaimer.
9  *      * Redistributions in binary form must reproduce the above copyright
10  *        notice, this list of conditions and the following disclaimer in the
11  *        documentation and/or other materials provided with the distribution.
12  *      * Neither the name of Texas Instruments Incorporated nor the
13  *        names of its contributors may be used to endorse or promote products
14  *        derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  *  THE POSSIBILITY OF SUCH DAMAGE.
27  *****************************************************************************/
28 #include "util.h"
29 #include "tidl_viewer.h"
30 #include "dot_graph.h"
32 using namespace tidl::util;
34 bool tidl::util::PrintNetwork(const std::string& network_binary,
35                               std::ostream& os)
36 {
37     if (network_binary.empty())
38         return false;
40     sTIDL_Network_t net;
41     bool status = ReadBinary(network_binary,
42                              reinterpret_cast<char *>(&net),
43                              sizeof(sTIDL_Network_t));
44     if (!status)
45     {
46         std::cerr << "ERROR: Invalid network binary: "
47                   << network_binary << std::endl;
48         exit(EXIT_FAILURE);
49     }
51     printf("%3s  %-20s  %3s  %3s  %3s "
52            " %3s  %3s  %3s  %3s  %3s  %3s  %3s  %3s %3s "
53            " %5s  %5s  %5s  %5s  %5s  %5s  %5s  %5s\n",
54             "#", "Name", "gId", "#i", "#o",
55             "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", "o",
56             "#roi", "#ch", "h", "w", "#roi", "#ch", "h", "w");
58     for (int i = 0 ; i < net.numLayers; i++)
59     {
60         printf("%3d, %-20s,",i,
61                     TIDL_LayerString[net.TIDLLayers[i].layerType]);
62         printf("%3d, %3d ,%3d ,",net.TIDLLayers[i].layersGroupId,
63                                  net.TIDLLayers[i].numInBufs,
64                                  net.TIDLLayers[i].numOutBufs);
66         for (int j = 0; j < net.TIDLLayers[i].numInBufs; j++)
67         {
68           printf("%3d ,",net.TIDLLayers[i].inData[j].dataId);
69         }
70         for (int j = (net.TIDLLayers[i].numInBufs > 0 ?
71               net.TIDLLayers[i].numInBufs : 0); j < 8; j++)
72         {
73           printf("  x ,");
74         }
75         printf("%3d ,",net.TIDLLayers[i].outData[0].dataId);
76         for (int j = 0; j < 4; j++)
77         {
78           printf("%5d ,",net.TIDLLayers[i].inData[0].dimValues[j]);
79         }
80         for (int j = 0; j < 4; j++)
81         {
82           printf("%5d ,",net.TIDLLayers[i].outData[0].dimValues[j]);
83         }
84         printf("\n");
85     }
87     return true;
88 }
91 bool tidl::util::GenerateDotGraphForNetwork(const std::string& network_binary,
92                                             const std::string& dot_file)
93 {
94     if (network_binary.empty())
95         return false;
97     sTIDL_Network_t net;
98     bool status = ReadBinary(network_binary,
99                              reinterpret_cast<char *>(&net),
100                              sizeof(sTIDL_Network_t));
101     if (!status)
102     {
103         std::cerr << "ERROR: Invalid network binary: "
104                   << network_binary << std::endl;
105         exit(EXIT_FAILURE);
106     }
109     DotGraph g(net);
110     g.Write(dot_file);
112     return true;