1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "src/executor.h"
18 #include <queue>
19 #include "include/errorcode.h"
20 #include "src/common/tensor_util.h"
21
22 namespace mindspore::lite {
Run(const std::vector<Tensor * > & in_tensors,const std::vector<Tensor * > & out_tensors,const std::vector<kernel::LiteKernel * > & kernels,const KernelCallBack & before,const KernelCallBack & after)23 int Executor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
24 const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before,
25 const KernelCallBack &after) {
26 // init the max spin count.
27 CHECK_NULL_RETURN(ctx_);
28 auto thread_pool = ctx_->thread_pool();
29 CHECK_NULL_RETURN(thread_pool);
30 thread_pool->SetSpinCountMaxValue();
31
32 // clear ref_count
33 for (auto *kernel : kernels) {
34 for (auto *tensor : kernel->in_tensors()) {
35 tensor->set_ref_count(0);
36 }
37 }
38
39 for (auto kernel : kernels) {
40 int ret = kernel->Execute(before, after);
41 if (ret != RET_OK) {
42 MS_LOG(ERROR) << "run kernel failed, name: " << kernel->name();
43 return ret;
44 }
45 }
46
47 thread_pool->SetSpinCountMinValue();
48 return RET_OK;
49 }
50 } // namespace mindspore::lite
51