]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - tinn_api/src/configuration.cpp
74ec552a0894a37684963794c78a99b00726ecab
[tidl/tidl-api.git] / tinn_api / src / configuration.cpp
1 /******************************************************************************
2  * Copyright (c) 2017 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"
34 using namespace tinn;
36 void Configuration::Print(std::ostream &os) const
37 {
38     os << "Configuration"
39        << "\nFrame=      " << numFrames << " " << inWidth << "x"
40                            << inHeight << "x" << inNumChannels
41        << "\nPreProcType              " << preProcType
42        << "\nInputFile                " << inData
43        << "\nOutputFile               " << outData
44        << "\nNetwork                  " << netBinFile
45        << "\nParameters               " << paramsBinFile
46        << "\nEO Heap Size (MB)        " << (EXTMEM_HEAP_SIZE >> 20)
47        << "\nParameter heap size (MB) " << (PARAM_HEAP_SIZE >> 20)
48        << "\n";
49 }
51 #include <sys/stat.h>
52 bool Configuration::Validate() const
53 {
54     int errors = 0;
56     if (inHeight == 0 || inWidth == 0)
57     {
58         std::cerr << "inHeight, inWidth must be > 0" << std::endl;
59         errors++;
60     }
62     if (inNumChannels < 1)
63     {
64         std::cerr << "inNumChannels must be > 1" << std::endl;
65         errors++;
66     }
68     struct stat buffer;
69     if (stat(netBinFile.c_str(), &buffer) != 0)
70     {
71         std::cerr << "netBinFile not found: " << netBinFile << std::endl;
72         errors++;
73     }
75     size_t paramsBinFileSize = 0;
76     if (stat(paramsBinFile.c_str(), &buffer) != 0)
77     {
78         std::cerr << "paramsBinFile not found: " << paramsBinFile << std::endl;
79         errors++;
80     }
81     else
82         paramsBinFileSize = buffer.st_size;
84     if (!inData.empty() && stat(inData.c_str(), &buffer) != 0)
85     {
86         std::cerr << "inData not found: " << inData << std::endl;
87         errors++;
88     }
90     // Due to alignment, the parameter heap must be larger than the
91     // parameter binary. Using 1.1 as a conservative factor.
92     if (paramsBinFileSize > 0 &&
93             (paramsBinFileSize * 1.1) > PARAM_HEAP_SIZE)
94     {
95         std::cerr << "Parameter binary file larger than paramter heap. "
96                      "Increase Configuration::PARAM_HEAP_SIZE" << std::endl;
97         errors++;
98     }
100     if (errors > 0)
101         return false;
103     return true;