1 /******************************************************************************
2 * Copyright (c) 2017-2018, 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 = ReadNetworkBinary(network_binary,
42 reinterpret_cast<char *>(&net));
43 if (!status)
44 {
45 std::cerr << "ERROR: Invalid network binary: "
46 << network_binary << std::endl;
47 exit(EXIT_FAILURE);
48 }
50 printf("%3s %-20s %3s %3s %3s "
51 " %3s %3s %3s %3s %3s %3s %3s %3s %3s "
52 " %5s %5s %5s %5s %5s %5s %5s %5s\n",
53 "#", "Name", "gId", "#i", "#o",
54 "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", "o",
55 "#roi", "#ch", "h", "w", "#roi", "#ch", "h", "w");
57 for (int i = 0 ; i < net.numLayers; i++)
58 {
59 printf("%3d, %-20s,",i,
60 TIDL_LayerString[net.TIDLLayers[i].layerType]);
61 printf("%3d, %3d ,%3d ,",net.TIDLLayers[i].layersGroupId,
62 net.TIDLLayers[i].numInBufs,
63 net.TIDLLayers[i].numOutBufs);
65 for (int j = 0; j < net.TIDLLayers[i].numInBufs; j++)
66 {
67 printf("%3d ,",net.TIDLLayers[i].inData[j].dataId);
68 }
69 for (int j = (net.TIDLLayers[i].numInBufs > 0 ?
70 net.TIDLLayers[i].numInBufs : 0); j < 8; j++)
71 {
72 printf(" x ,");
73 }
74 printf("%3d ,",net.TIDLLayers[i].outData[0].dataId);
75 for (int j = 0; j < 4; j++)
76 {
77 printf("%5d ,",net.TIDLLayers[i].inData[0].dimValues[j]);
78 }
79 for (int j = 0; j < 4; j++)
80 {
81 printf("%5d ,",net.TIDLLayers[i].outData[0].dimValues[j]);
82 }
83 printf("\n");
84 }
86 return true;
87 }
90 bool tidl::util::GenerateDotGraphForNetwork(const std::string& network_binary,
91 const std::string& dot_file)
92 {
93 if (network_binary.empty())
94 return false;
96 sTIDL_Network_t net;
97 bool status = ReadNetworkBinary(network_binary,
98 reinterpret_cast<char *>(&net));
99 if (!status)
100 {
101 std::cerr << "ERROR: Invalid network binary: "
102 << network_binary << std::endl;
103 exit(EXIT_FAILURE);
104 }
107 DotGraph g(net);
108 g.Write(dot_file);
110 return true;
111 }