1fc033ceb32e7faa40d4ea8d5073c3b4b688aed5
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 #pragma once
31 //! @file configuration.h
33 #include <string>
34 #include <map>
35 #include <iostream>
37 namespace tidl {
39 /*! @class Configuration
40 @brief Specifies the configuration required for a network
42 The Configuration object is used to specify various parameters required
43 for network execution. Applications can directly initialize fields in an
44 instance of Configuration or use the ReadFromFile method to read the
45 configuration from a file.
46 */
48 class Configuration
49 {
50 public:
52 //! Number of frames of input data (can be 0 if data is not read from file)
53 int numFrames;
55 //! Height of the input image. Used by the API, must be specified.
56 int inHeight;
58 //! Width of the input image. Used by the API, must be specified.
59 int inWidth;
61 //! Number of channels in the input frame (e.g. 3 for BGR)
62 //! Used by the API, must be specified.
63 int inNumChannels;
65 //! @private
66 int noZeroCoeffsPercentage;
68 //! Pre-processing type applied to the input frame
69 //! Specific to each network, can take values from 0 to 4, default is 0
70 int preProcType;
72 //! Force to run all layers, regardless of layersGroupId partitioning
73 bool runFullNet;
75 //! Deprecated, do not use.
76 //! When set, inputs are taken from TIDL internal buffers that contain
77 //! outputs of previous layersGroupId, instead of from user application
78 bool enableInternalInput;
80 //! @brief Size of the device side network heap
81 //! This heap is used for allocating memory required to
82 //! run the network on the device. One per Execution Object.
83 size_t NETWORK_HEAP_SIZE;
85 //! @brief Size of the device side heap used for parameter data.
86 //! The size depends on the size of the parameter binary file. The
87 //! constructor for ``Configuration`` sets PARAM_HEAP_SIZE to 9MB.
88 //! There is one parameter heap for each instance of ``Executor`` .
89 size_t PARAM_HEAP_SIZE;
91 //! @brief Path to the input image file.
92 //! This field is not used by the TIDL API itself. It can be used by
93 //! applications to load an input image into a buffer. Can be empty if
94 //! the application uses frameworks such as OpenCV to read images. Refer
95 //! examples/test/main.cpp for usage.
96 std::string inData;
98 //! @brief Path to the output image file.
99 //! This field is not used by the TIDL API itself. It can be used by
100 //! applications to specify a name for the output file. Can be empty
101 //! if the application uses frameworks such as OpenCV to read images.
102 //! Refer examples/test/main.cpp for usage.
103 std::string outData;
105 //! Path to the TIDL network binary file.
106 //! Used by the API, must be specified.
107 std::string netBinFile;
109 //! Path to the TIDL parameter binary file
110 //! Used by the API, must be specified.
111 std::string paramsBinFile;
113 //! Map of layer index to layer group id. Used to override layer group
114 //! assigment for layers. Any layer not specified in this map will
115 //! retain its existing mapping.
116 std::map<int, int> layerIndex2LayerGroupId;
118 //! Enable tracing of output buffers associated with each layer
119 bool enableOutputTrace;
121 //! Debug - Generates a trace of host and device function calls
122 bool enableApiTrace;
124 //! Debug - Shows total size of PARAM and NETWORK heaps. Also shows bytes
125 //! available after all allocations. Can be used to adjust the heap
126 //! size.
127 bool showHeapStats;
129 //! Default constructor.
130 Configuration();
132 //! Validate the fields in the configuration object
133 bool Validate() const;
135 //! Debug - Print the configuration.
136 void Print(std::ostream& os = std::cout) const;
138 //! Read a configuration from the specified file and validate
139 bool ReadFromFile(const std::string& file_name);
141 };
143 }