@@ -32,6 +32,7 @@ std::vector<std::shared_ptr<BackendRuntime>> PipelineScheduler::PipelineInit(
3232 const std::vector<Module>& modules, const ConfigPipelineExecution& pipeline_config) {
3333 std::vector<std::shared_ptr<BackendRuntime>> runtimes;
3434 graph_modules_ = modules;
35+ global_runtime_ = std::make_shared<GlobalRuntime>(GLOBAL_MODULE_INDEX);
3536 // Creating a list of runtimes.
3637 for (size_t i = 0 ; i < graph_modules_.size (); i++) {
3738 auto run_item = std::make_shared<BackendRuntime>(graph_modules_[i], i);
@@ -49,71 +50,25 @@ std::vector<std::shared_ptr<BackendRuntime>> PipelineScheduler::PipelineInit(
4950 }
5051 // Initializing and then running the worker thread.
5152 for (auto runtime : runtimes) {
52- runtime->InitializePipeline (pipeline_config, &runtimes);
53+ runtime->InitializePipeline (pipeline_config, &runtimes, global_runtime_ );
5354 }
5455 return runtimes;
5556}
56- /* !
57- * \brief Running the pipeline logic in the sequential mode.
58- * \param runtimes A list of backend runtime modules.
59- * \param pipeline_config The dependent configuration of each runtime module.
60- */
61- void PipelineScheduler::PipelineRunSequential (
62- const std::vector<std::shared_ptr<BackendRuntime>>& runtimes,
63- ConfigPipelineExecution pipeline_config) {
64- for (size_t i = 0 ; i < runtimes.size (); i++) {
65- // The "runtimes" is a list of runtime sorted by the runtime index which should be
66- // contiguous ascend.
67- if (static_cast <int >(i) != runtimes[i]->GetModuleIndex ()) {
68- LOG (FATAL) << " Runtime index " << runtimes[i]->GetModuleIndex ()
69- << " is not as same as vector offset value " << i;
70- }
71-
72- if (!pipeline_config.FindModuleInConfig (i)) {
73- LOG (FATAL) << " Not find the configuration for the module " << i;
74- }
75-
76- runtimes[i]->Run ();
77- // Getting the output then forwarding into other module once it is configured as input of
78- // another module or storaging into the "output_array" when the output is a global one.
79- int outputs_num = runtimes[i]->NumOutputs ();
80- for (int j = 0 ; j < outputs_num; j++) {
81- ConfigBindings& out_binding = pipeline_config[i][j];
82- std::unordered_map<int , std::string>& input_connections = out_binding.Get ();
83- NDArray output = runtimes[i]->GetOutput (j);
84- for (auto bind : input_connections) {
85- // "bind.first < 0" means the bind is a global bind, by pass the forwarding for
86- // a global bind.
87- if (bind.first < 0 ) continue ;
88- // Setting the output as an input data into the runtime module.
89- runtimes[bind.first ]->SetInput (bind.second , const_cast <DLTensor*>(output.operator ->()));
90- }
91- // Store the output.
92- if (out_binding.IsGlobalOutput ()) {
93- int global_idx = out_binding.GetGlobalOutputIndex ();
94- TVMArrayCopyFromTo (const_cast <DLTensor*>(output.operator ->()),
95- const_cast <DLTensor*>(output_arrays_[global_idx].operator ->()), nullptr );
96- }
97- }
98- }
99- }
10057/* !
10158 * \brief Running pipeline logic.
10259 * \param runtimes A list of backend runtime modules.
10360 * \param pipeline_config The dependency configuration of each runtime module.
104- * \param sequential_mode Whether the execution is in a sequential mode.
10561 */
10662void PipelineScheduler::PipelineRun (const std::vector<std::shared_ptr<BackendRuntime>>& runtimes,
107- ConfigPipelineExecution pipeline_config, bool sequential_mode) {
108- if (!sequential_mode) {
109- runtimes.front ()->RunPipeline ();
110- } else {
111- PipelineRunSequential (runtimes, pipeline_config);
112- }
63+ ConfigPipelineExecution pipeline_config) {
64+ runtimes.front ()->RunPipeline ();
11365}
11466/* !
11567 * \brief Get a list of output.
11668 */
117- Array<NDArray> PipelineScheduler::PipelineGetOutput () { return output_arrays_; }
69+ Array<NDArray> PipelineScheduler::PipelineGetOutput () {
70+ bool ret = global_runtime_->GetOutput (&output_arrays_);
71+ return ret ? output_arrays_ : Array<NDArray>{};
72+ }
11873} // namespace runtime
11974} // namespace tvm
0 commit comments