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 *****************************************************************************/
29 #include <string>
30 #include <fstream>
32 #include "configuration.h"
33 #include "parameters.h"
35 using namespace tidl;
37 Configuration::Configuration(): numFrames(0), inHeight(0), inWidth(0),
38 inNumChannels(0),
39 noZeroCoeffsPercentage(100),
40 preProcType(0),
41 runFullNet(0),
42 enableInternalInput(0),
43 EXTMEM_HEAP_SIZE(64 << 20), // 64MB for inceptionNetv1
44 PARAM_HEAP_SIZE(9 << 20) // 9MB for mobileNet1
45 {
46 }
48 void Configuration::Print(std::ostream &os) const
49 {
50 os << "Configuration"
51 << "\nFrame= " << numFrames << " " << inWidth << "x"
52 << inHeight << "x" << inNumChannels
53 << "\nPreProcType " << preProcType
54 << "\nRunFullNet " << runFullNet
55 << "\nEnableInternalInput " << enableInternalInput
56 << "\nInputFile " << inData
57 << "\nOutputFile " << outData
58 << "\nNetwork " << netBinFile
59 << "\nParameters " << paramsBinFile
60 << "\nEO Heap Size (MB) " << (EXTMEM_HEAP_SIZE >> 20)
61 << "\nParameter heap size (MB) " << (PARAM_HEAP_SIZE >> 20)
62 << "\n";
63 }
65 #include <sys/stat.h>
66 bool Configuration::Validate() const
67 {
68 int errors = 0;
70 if (inHeight == 0 || inWidth == 0)
71 {
72 std::cerr << "inHeight, inWidth must be > 0" << std::endl;
73 errors++;
74 }
76 if (inNumChannels < 1)
77 {
78 std::cerr << "inNumChannels must be > 1" << std::endl;
79 errors++;
80 }
82 struct stat buffer;
83 if (stat(netBinFile.c_str(), &buffer) != 0)
84 {
85 std::cerr << "netBinFile not found: " << netBinFile << std::endl;
86 errors++;
87 }
89 size_t paramsBinFileSize = 0;
90 if (stat(paramsBinFile.c_str(), &buffer) != 0)
91 {
92 std::cerr << "paramsBinFile not found: " << paramsBinFile << std::endl;
93 errors++;
94 }
95 else
96 paramsBinFileSize = buffer.st_size;
98 if (!inData.empty() && stat(inData.c_str(), &buffer) != 0)
99 {
100 std::cerr << "inData not found: " << inData << std::endl;
101 errors++;
102 }
104 // Due to alignment, the parameter heap must be larger than the
105 // parameter binary. Using 1.1 as a conservative factor.
106 if (paramsBinFileSize > 0 &&
107 (paramsBinFileSize * 1.1) > PARAM_HEAP_SIZE)
108 {
109 std::cerr << "Parameter binary file larger than paramter heap. "
110 "Increase Configuration::PARAM_HEAP_SIZE" << std::endl;
111 errors++;
112 }
114 if (errors > 0)
115 return false;
117 return true;
118 }