]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - tidl_api/src/subgraph_runtime_impl.h
9738dbbac7cbf65671d263880043050582c4926b
[tidl/tidl-api.git] / tidl_api / src / subgraph_runtime_impl.h
1 /******************************************************************************
2  * Copyright (c) 2019 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 //! @file subgraph_runtime_impl.h
31 #pragma once
32 #include <vector>
33 #include <mutex>
34 #include <condition_variable>
35 #include "execution_object_pipeline.h"
36 #include "subgraph_data_conv.h"
39 namespace tidl {
41 // Singleton ResM   .h file
42 // Resource manager for available EVE and DSP devices,
43 //   - Allocates EVEs and DSPs
44 //   - Constructs Executors (tidl_setup) and ExecutionObjects (tid_init)
45 //   - Creates set of ExecutionPipelines (with or without DSP)
46 //   - Allocating EOP on demand (acquire and free semantics)
47 //   - Allocates input/output buffers
48 class ResM {
49   public:
50     ResM();
51     ~ResM();
52     static ResM& Instance(uint32_t total_num_subgraphs = 1);
54     // how to get resources for subgraph_id
55     void                     InitSubgraph(uint32_t subgraph_id);
56     uint32_t                 GetNumEOPs(uint32_t subgraph_id);
57     ExecutionObjectPipeline* GetEOP(uint32_t subgraph_id);
58     void                     FreeEOP(uint32_t subgraph_id,
59                                      ExecutionObjectPipeline* eop);
60     Configuration&           GetConfiguration(uint32_t subgraph_id);
61     const SubgraphDataConv&  GetInConv(uint32_t subgraph_id);
62     const SubgraphDataConv&  GetOutConv(uint32_t subgraph_id);
63     uint32_t                 GetNumEs() { return num_es_per_subgraph_m; }
66   private:
67     void Init(uint32_t num_subgraphs);
69     bool     enable_trace_m;
70     uint32_t num_subgraphs_m;
71     uint32_t num_es_per_subgraph_m;
72     uint32_t num_eves_m;
73     uint32_t num_dsps_m;
74     uint32_t num_lg2_dsps_used_m;  // in partitioned execution case
75     std::mutex mutex_init_m;
77     // indexed by subgraph_id for resources
78     struct ResEOP {
79       ResEOP() : free_eop_index(0), is_used(), eops(nullptr) {}
81       uint32_t free_eop_index;
82       std::mutex mutex_eops;
83       std::condition_variable cv_eops;
84       std::vector<bool> is_used;
85       std::vector<ExecutionObjectPipeline*>* eops;
86     };
87     std::vector<Configuration> cs_m;
88     std::vector<Executor*> es_m;
89     std::vector<Executor*> e2s_m;
90     std::vector<ResEOP> *eops_m;
91     std::vector<SubgraphDataConv*> in_conv_m;
92     std::vector<SubgraphDataConv*> out_conv_m;
93 };
95 } // namespace tidl