• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 "thread/core_affinity.h"
18 #include "thread/threadpool.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 static mindspore::ThreadPool *g_pool = nullptr;
25 
CreateThreadPool(int thread_num)26 int CreateThreadPool(int thread_num) {
27   g_pool = mindspore::ThreadPool::CreateThreadPool(thread_num);
28   if (g_pool == nullptr) {
29     return mindspore::THREAD_ERROR;
30   }
31   return mindspore::THREAD_OK;
32 }
33 
SetCoreAffinity(int bind_mode)34 int SetCoreAffinity(int bind_mode) {
35   if (g_pool == nullptr) {
36     return mindspore::THREAD_ERROR;
37   }
38   return g_pool->SetCpuAffinity(static_cast<mindspore::BindMode>(bind_mode));
39 }
40 
GetCurrentThreadNum()41 int GetCurrentThreadNum() {
42   if (g_pool == nullptr) {
43     return 0;
44   }
45   return g_pool->thread_num();
46 }
47 
ParallelLaunch(int (* func)(void *,int,float,float),void * content,int task_num)48 int ParallelLaunch(int (*func)(void *, int, float, float), void *content, int task_num) {
49   if (g_pool == nullptr) {
50     return mindspore::THREAD_ERROR;
51   }
52   return g_pool->ParallelLaunch(func, content, task_num);
53 }
54 
ClearThreadPool()55 void ClearThreadPool() {
56   delete g_pool;
57   g_pool = nullptr;
58 }
59 
60 #ifdef __cplusplus
61 }
62 #endif
63